# locale-id

> Parse and normalize locale id

Latest version **1.1.2** (published 2019-03-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install locale-id
pnpm add locale-id
yarn add locale-id
bun add locale-id
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.2 |
| Published | 2019-03-10 |
| First published | 2016-01-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >= 6.0.0 |
| Dependencies | 3 |
| Unpacked size | 102.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | Zlatko Fedor |
| Maintainers | zlatkofedor |
| Keywords | localeId, locale-id |

## Links

- npm: https://www.npmjs.com/package/locale-id
- Repository: https://github.com/CherryProjects/locale-id
- Issues: https://github.com/CherryProjects/locale-id/issues
- npm.io page: https://npm.io/package/locale-id

## Dependencies (3)

- [debug](https://npm.io/package/debug.md) ^3.2.6
- [lodash](https://npm.io/package/lodash.md) ^4.17.11
- [@babel/runtime](https://npm.io/package/@babel/runtime.md) ^7.3.4

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 1.1.2 (latest) — 2019-03-10
- 1.1.1 — 2019-03-10
- 1.0.3 — 2019-03-10
- 1.0.2 — 2016-03-24
- 1.0.1 — 2016-03-06
- 0.0.8 — 2016-01-09
- 0.0.6 — 2016-01-09
- 0.0.5 — 2016-01-09
- 0.0.4 — 2016-01-09
- 0.0.3 — 2016-01-09
- 0.0.2 — 2016-01-09

## README

# Locale ID

Parse and normalize locale ID. [ICU Locale ID](http://userguide.icu-project.org/locale)

[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Test coverage][coveralls-image]][coveralls-url]

[npm-image]: https://img.shields.io/npm/v/locale-id.svg?style=flat-square
[npm-url]: https://www.npmjs.com/locale-id
[travis-image]: https://img.shields.io/travis/CherryProjects/locale-id/master.svg?style=flat-square
[travis-url]: https://travis-ci.org/CherryProjects/locale-id
[coveralls-image]: https://img.shields.io/coveralls/CherryProjects/locale-id/master.svg?style=flat-square
[coveralls-url]: https://coveralls.io/r/CherryProjects/locale-id?branch=master
[github-url]: https://github.com/CherryProjects/locale-id

# Installation

Install via npm.

```sh
npm install locale-id
```

# Support us

Star this project on [GitHub][github-url].

# Usage

### parse

```js
import parse from 'locale-id';

const locale = parse('sk-sk');
console.log(result); // => { language: 'sk', country: 'SK' }

const value = parse('sk_Latin_SK');
console.log(value); // => { language: 'sk', script: 'Latin', country: 'SK' }
```

### normalize

```js
import { normalize } from 'locale-id';

const value = normalize('sk-sk');
console.log(value); // => sk_SK
```

### getLanguage

```js
import { getLanguage } from 'locale-id';

const value = getLanguage('sk-sk');
console.log(value); // => sk
```

### getCountry

```js
import { getCountry } from 'locale-id';

const value = getCountry('cs-cz');
console.log(value); // => CZ
```

### getScript

```js
import { getScript } from 'locale-id';

const value = getScript('sk-latin-sk');
console.log(value); // => Latin
```

### getVariant

```js
import { getVariant } from 'locale-id';

const value = getVariant('sr_Latn_RS_REVISED@currency=USD');
console.log(value); // => REVISED
```


### getKeyword

```js
import { getKeyword } from 'locale-id';

const value = getKeyword('sk-latin-sk@currency=USD');
console.log(value); // => currency=USD
```

### normalizeAcceptLanguage

```js
import { normalizeAcceptLanguage } from 'locale-id';

const value = normalizeAcceptLanguage('da, en-gb;q=0.8, en;q=0.7');
console.log(value); // => ['da', 'en_GB', 'en']
```

### getBest

```js
import { getBest } from 'locale-id';

getBest(['en', 'en_US', 'en_UK', 'sk_SK'], 'en-uk').should.equal('en_UK');
getBest(['en', 'en_US', 'en_UK', 'sk_SK'], 'en-br').should.equal('en');
getBest(['en', 'en_US', 'en_UK', 'sk_SK'], 'sk-SK').should.equal('sk_SK');

should(getBest(['en', 'en_US', 'en_UK', 'sk_SK'], 'sk-md')).equal(void 0);
should(getBest(['en', 'en_US', 'en_UK', 'sk_SK'], 'sk-md', 'en')).equal('en');
should(getBest(['en', 'en_US', 'en_UK', 'sk_SK'], 'sk-md', 'en', true)).equal('sk_SK');

should(getBest(['en_US', 'en_UK', 'sk_SK'], 'en-US', 'sk_SK', true)).equal('en_US');
should(getBest(['en_US', 'en_UK', 'sk_SK'], 'en', 'sk_SK', true)).equal('en_US');
```

You can speed up getBest function:

```js
import { getBest, prepareSupported } from 'locale-id';

const supported = prepareSupported(['en', 'en_US', 'en_UK', 'sk_SK']);

getBest(supported, 'en-uk').should.equal('en_UK');
```

# Running Tests

To run the test suite, first invoke the following command within the repo, installing the development dependencies:

```sh
npm install
```

Then run the tests:

```sh
npm test
```

---
_Source: https://npm.io/package/locale-id · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
