UNPKG

2.21 kBMarkdownView Raw
1# ISO-639-1
2[![NPM Version][npm-image]][npm-url]
3[![Build Status][travis-image]][travis-url]
4[![Download Count][download-url]][npm-url]
5
6[travis-image]: https://travis-ci.org/meikidd/iso-639-1.svg?branch=master
7[travis-url]: https://travis-ci.org/meikidd/iso-639-1
8[npm-image]: https://img.shields.io/npm/v/iso-639-1.svg?style=flat-square
9[npm-url]: https://npmjs.org/package/iso-639-1
10[download-url]: https://img.shields.io/npm/dt/iso-639-1.svg?style=flat-square
11
12
13Simple interface for [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) language codes
14
15## Installation
16
17```
18npm install iso-639-1
19```
20
21## Methods
22
23### getName(code)
24 - @param code {string}
25 - @return {string}
26
27Lookup language english name by code
28
29### getAllNames()
30 - @return {array}
31
32Get array of all language english names
33
34### getNativeName(code)
35 - @param code {string}
36 - @return {string}
37
38Lookup language native name by code
39
40### getAllNativeNames()
41 - @return {array}
42
43Get array of all language native names
44
45
46### getCode(name)
47 - @param name {string}
48 - @return {string}
49
50Lookup code by english name or native name
51
52### getAllCodes()
53 - @return {array}
54
55Get array of all codes
56
57### validate(code)
58 - @param code {string}
59 - @return {boolean}
60
61Check whether the given code is in the list of [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes)
62
63### getLanguages(codes)
64 - @param codes {array}
65 - @return {array}
66
67Get the array of the language objects by the given codes
68
69## Usage
70
71```
72var ISO6391 = require('./iso-639-1')
73
74console.log(ISO6391.getName('zh')) // 'Chinese'
75console.log(ISO6391.getNativeName('zh')) // '中文'
76
77console.log(ISO6391.getAllNames()) // ['Afar','Abkhaz', ... ,'Zulu']
78console.log(ISO6391.getAllNativeNames()) //['Afaraf','аҧсуа бызшәа', ... ,'isiZulu' ]
79
80console.log(ISO6391.getCode('Chinese')) // 'zh'
81console.log(ISO6391.getCode('中文')) // 'zh'
82
83console.log(ISO6391.getAllCodes()) //['aa','ab',...,'zu']
84
85console.log(ISO6391.validate('en')) // true
86console.log(ISO6391.validate('xxx')) // false
87
88console.log(ISO6391.getLanguages(['en', 'zh']))
89// [{code:'en',name:'English',nativeName:'English'},{code:'zh',name:'Chinese',nativeName:'中文'}]
90
91```