mobitel-iso-639-locales
v1.1.2
Published
NodeJs module based on ISO-639 for validate and get basic info by locale
Downloads
102
Maintainers
Readme
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
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
API
.list
Property - {locale: String, name: String}[]
- contains full locale list.
Example
const locales = isoLocale.list; //=> array like [{locale: 'af', name: 'Afrikaans (South Africa)'}, ...];
.codeList
Property - String[]
- contains full locale codes list.
Example
const localeCodes = isoLocale.codeList; //=> array like ['af', 'af-ZA' ...];
.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
.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
Test
npm run test
License
MIT License. Copyright (c) 2017 Mobitel Ltd up to navigation