# locale-code

> locale code based on iso-639-1 and iso-3166-1

Latest version **2.0.2** (published 2019-03-11) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.2 |
| Published | 2019-03-11 |
| First published | 2015-08-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 317.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 36 |
| Author | meikidd |
| Maintainers | meikidd |
| Keywords | locale, i18n, language |

## Links

- npm: https://www.npmjs.com/package/locale-code
- Repository: https://github.com/meikidd/locale-code
- Homepage: https://github.com/meikidd/locale-code#readme
- Issues: https://github.com/meikidd/locale-code/issues
- npm.io page: https://npm.io/package/locale-code

## Dependencies (2)

- [iso-639-1-zh](https://npm.io/package/iso-639-1-zh.md) ^2.0.4
- [iso-3166-1-alpha-2](https://npm.io/package/iso-3166-1-alpha-2.md) ~1.0.0

## Alternatives

- [messageformat](https://npm.io/package/messageformat.md) — 329.7K weekly downloads
- [@mintlify/scraping](https://npm.io/package/@mintlify/scraping.md) — 294.8K weekly downloads
- [@mintlify/previewing](https://npm.io/package/@mintlify/previewing.md) — 209.5K weekly downloads
- [@mintlify/prebuild](https://npm.io/package/@mintlify/prebuild.md) — 209.5K weekly downloads
- [@mintlify/link-rot](https://npm.io/package/@mintlify/link-rot.md) — 206.3K weekly downloads

## Recent versions

- 2.0.2 (latest) — 2019-03-11
- 2.0.1 — 2018-01-22
- 2.0.0 — 2018-01-18
- 1.1.1 — 2016-05-02
- 1.1.0 — 2016-05-01
- 1.0.1 — 2016-04-30
- 1.0.0 — 2015-09-10
- 0.1.3 — 2015-08-26
- 0.1.2 — 2015-08-26
- 0.1.1 — 2015-08-26

## README

# locale-code
[![NPM Version][npm-image]][npm-url]
[![Build Status][travis-image]][travis-url]
[![Download Count][download-url]][npm-url]

[travis-image]: https://travis-ci.org/meikidd/locale-code.svg?branch=master
[travis-url]: https://travis-ci.org/meikidd/locale-code
[npm-image]: https://img.shields.io/npm/v/locale-code.svg?style=flat-square
[npm-url]: https://npmjs.org/package/locale-code
[download-url]: https://img.shields.io/npm/dt/locale-code.svg?style=flat-square

Simple interface for [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) language codes and [ISO-3166-1-alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) country codes.

## Install

```
npm install locale-code
```


## Methods


### getLanguageCode(code) 
  - @param code {string}
  - @return {string}

Lookup language code from locale code

### getLanguageName(code) 
  - @param code {string}
  - @return {string}

Lookup language english name by code

### getLanguageNativeName(code) 
  - @param code {string}
  - @return {string}

Lookup language native name by code

### validateLanguageCode(code) 
  - @param code {string}
  - @return {boolean}

Check whether the given code is in the list of [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes)

### getLanguages(codes) 
  - @param codes {array}
  - @return {array}

Get the array of the language objects by the given codes


### getCountryCode(code) 
  - @param code {string}
  - @return {string}

Lookup country code from locale code

### getCountryName(code) 
  - @param code {string}
  - @return {string}

Lookup country name by code

### validateCountryCode(code) 
  - @param code {string}
  - @return {boolean}

Check whether the given code is in the list of [ISO-3166-1-alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)

### validate(code) 
  - @param code {string}
  - @return {boolean}

Check whether the given code is in the list of [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) and [ISO-3166-1-alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)


## Usage

```
var  LocaleCode = require('locale-code')

console.log(LocaleCode.getLanguageCode('en-US')); // 'en'

console.log(LocaleCode.getLanguageName('zh-CN')); // 'Chinese'

console.log(LocaleCode.getLanguageNativeName('zh-CN')); // '中文'

console.log(LocaleCode.getLanguageZhName('es-ES')); // '西班牙语'

console.log(LocaleCode.validateLanguageCode('en-US')); // true

console.log(LocaleCode.validateLanguageCode('bb-US')); // false

console.log(LocaleCode.getLanguages(['en-US','zh-CN'])); 
// [{code:'en-US', name:'English', nativeName:'English', zhName:'英语'}, {code:'zh-CN', name:'Chinese', nativeName:'中文', zhName:'中文'}]


console.log(LocaleCode.getCountryCode('en-US')); // 'US'

console.log(LocaleCode.getCountryName('en-US')); // 'United States'

console.log(LocaleCode.validateCountryCode('en-US')); // true

console.log(LocaleCode.validateCountryCode('en-ZZ')); // false

console.log(LocaleCode.validate('en-US')); // true

console.log(LocaleCode.validate('en_US')); // false

console.log(LocaleCode.validate('bb-XX')); // false

```

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