<commit_before># Keyset

Tool for representation of BEM i18n keyset.

[![NPM Status][npm-img]][npm]

[npm]:            https://www.npmjs.org/package/@bem/sdk.keyset
[npm-img]:        https://img.shields.io/npm/v/@bem/sdk.keyset.svg

* [Introduction](#introduction)
* [Try keyset](#try-keyset)
* [Quick start](#quick-start)
* [Formats](#formats)
* [API reference](#api-reference)
* [Parameter tuning](#parameter-tuning)
* [Usage examples](#usage-examples)

## Introduction

Keyset representations BEM project's keysets and returns a JavaScript object with information about it.

## Try keyset

An example is available in the [RunKit editor](https://runkit.com/godfreyd/5c3339d802ce8e00124ead3f).

## Quick start

> **Attention.** To use `@bem/sdk.keyset`, you must install [Node.js 8.0+](https://nodejs.org/en/download/).

To run the `@bem/sdk.keyset` package:

1. [Install keyset](#installing-the-bemsdkkeyset-package).
2. [Declarating keyset](#declarating-keyset).

### Installing the `@bem/sdk.keyset` package

To install the `@bem/sdk.keyset` package, run the following command:

```bash
$ npm install --save @bem/sdk.keyset
```

### Declarating keyset

Specify the keyset name, path and format for keyset. The `Keyset` class is a constructor for classes that enable format-sensitive keyset formatting.

**Example:**

```js
const { Keyset } = require('@bem/sdk.keyset');
const keyset = new Keyset('Time', 'src/features/Time/Time.i18n');
keyset.name; // => 'Time'
keyset.path; // => 'src/features/Time/Time.i18n'
keyset.format; // => 'taburet' — default format, see Formats
```

[RunKit live editor](https://runkit.com/godfreyd/5c3339d802ce8e00124ead3f).

### Formats

Keyset has two default formats:

| Format | Default extantion |
|-----------|-------------|
| `enb` | `.js` |
| `taburet` | `.ts` |

If you want change default extantion, override a variable `keyset.langsKeysExt` before saving keyset.

**Example:**

```js
const mockfs = require('mock-fs');
const { Keyset, Key, ParamedKey, PluralKey, LangKeys } = require("@bem/sdk.keyset");

mockfs({
    'src/features/Time/Time.i18n': {}
});

const langKeys = new LangKeys('ru', [
    new Key('Time difference', 'Разница "во" времени'),
    new PluralKey('{count} minute', {
        one: new ParamedKey('{count} minute', '{count} минута', ['count']),
        some: new ParamedKey('{count} minute', '{count} минуты', ['count']),
        many: new ParamedKey('{count} minute', '{count} минут', ['count']),
        none: new Key('{count} minute', 'нет минут')
    })
]);
<commit_msg>Fix topic<commit_after># Keyset

Tool for representation of BEM i18n keyset.

[![NPM Status][npm-img]][npm]

[npm]:            https://www.npmjs.org/package/@bem/sdk.keyset
[npm-img]:        https://img.shields.io/npm/v/@bem/sdk.keyset.svg

* [Introduction](#introduction)
* [Try keyset](#try-keyset)
* [Quick start](#quick-start)
* [Formats](#formats)
* [API reference](#api-reference)

## Introduction

Keyset representations BEM project's keysets and returns a JavaScript object with information about it.

## Try keyset

An example is available in the [RunKit editor](https://runkit.com/godfreyd/5c3339d802ce8e00124ead3f).

## Quick start

> **Attention.** To use `@bem/sdk.keyset`, you must install [Node.js 8.0+](https://nodejs.org/en/download/).

To run the `@bem/sdk.keyset` package:

1. [Install keyset](#installing-the-bemsdkkeyset-package).
2. [Declarating keyset](#declarating-keyset).

### Installing the `@bem/sdk.keyset` package

To install the `@bem/sdk.keyset` package, run the following command:

```bash
$ npm install --save @bem/sdk.keyset
```

### Declarating keyset

Specify the keyset name, path and format for keyset. The `Keyset` class is a constructor for classes that enable format-sensitive keyset formatting.

**Example:**

```js
const { Keyset } = require('@bem/sdk.keyset');
const keyset = new Keyset('Time', 'src/features/Time/Time.i18n');
keyset.name; // => 'Time'
keyset.path; // => 'src/features/Time/Time.i18n'
keyset.format; // => 'taburet' — default format, see Formats
```

[RunKit live editor](https://runkit.com/godfreyd/5c3339d802ce8e00124ead3f).

### Formats

Keyset has two default formats:

| Format | Extantion |
|-----------|-------------|
| `enb` | `.js` |
| `taburet` | `.ts` |

If you want change default extantion, override a variable `keyset.langsKeysExt` before saving keyset.

**Example:**

```js
const mockfs = require('mock-fs');
const { Keyset, Key, ParamedKey, PluralKey, LangKeys } = require("@bem/sdk.keyset");

mockfs({
    'src/features/Time/Time.i18n': {}
});

const langKeys = new LangKeys('ru', [
    new Key('Time difference', 'Разница "во" времени'),
    new PluralKey('{count} minute', {
        one: new ParamedKey('{count} minute', '{count} минута', ['count']),
        some: new ParamedKey('{count} minute', '{count} минуты', ['count']),
        many: new ParamedKey('{count} minute', '{count} минут', ['count']),
        none: new Key('{count} minute', 'нет минут')
    })
]);

{'fraction_non_alphanumeric': 0.18331327717609305, 'fraction_numerical': 0.01684717208182912, 'mean_word_length': 4.146542827657378, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 10, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5292668', 'n_tokens_mistral': 1838, 'n_tokens_neox': 1746, 'n_words': 436}