UNPKG

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