mobitel-iso-639-locales

1.1.2 • Public • Published

Mobitel Ltd. ISO-639 Locales

NodeJs module based on ISO-639 for validate and get basic info by locale

Attention

This module writing and testing on NodeJs v.8+ and NPM v.5+. Using the module in previous versions of NodeJs does not guarantee correct works.

Navigation

Installation

npm i --save mobitel-iso-639-locales

up to navigation

Example

const isoLocale = required('mobitel-iso-639-locales');
 
// get locale list
const locales = isoLocale.list; //=> array like [{locale: 'af', name: 'Afrikaans (South Africa)'}, ...];
 
// get locale code list
const localeCodes = isoLocale.codeList; //=> array like ['af', 'af-ZA' ...];
 
// validate
const valid = isoLocale.validate('af'); //=> true
const invalid = isoLocale.validate('arr'); //=> false
 
// get data
const data = isoLocale.get('af-ZA'); //=> {locale: 'af', name: 'Afrikaans (South Africa)'}
const noData = isoLocale.get('af-ZARA'); //=> null

up to navigation

API

.list

Property - {locale: String, name: String}[] - contains full locale list.

Example

const locales = isoLocale.list; //=> array like [{locale: 'af', name: 'Afrikaans (South Africa)'}, ...];

up to navigation

.codeList

Property - String[] - contains full locale codes list.

Example

const localeCodes = isoLocale.codeList; //=> array like ['af', 'af-ZA' ...];

up to navigation

.validate(code)

Argument - String - locale code like 'af' or 'af-ZA'.

If code exist return true, otherwise false.

Example

const valid = isoLocale.validate('af'); //=> true
const invalid = isoLocale.validate('arr'); //=> false

up to navigation

.get(code)

Argument - String - locale code like 'af' or 'af-ZA'.

If code exist return object with simple locale data like {locale: 'af', name: 'Afrikaans'}, otherwise null.

Example

const data = isoLocale.get('af-ZA'); //=> {locale: 'af', name: 'Afrikaans (South Africa)'}
const noData = isoLocale.get('af-ZARA'); //=> null

up to navigation

Test

npm run test

up to navigation

License

MIT License. Copyright (c) 2017 Mobitel Ltd

up to navigation

Package Sidebar

Install

npm i mobitel-iso-639-locales

Weekly Downloads

25

Version

1.1.2

License

MIT

Last publish

Collaborators

  • mobitel-ltd