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 |
|
13 | Simple interface for [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) language codes
|
14 |
|
15 | ## Installation
|
16 |
|
17 | ```
|
18 | npm install iso-639-1
|
19 | ```
|
20 |
|
21 | ## Methods
|
22 |
|
23 | ### getName(code)
|
24 | - @param code {string}
|
25 | - @return {string}
|
26 |
|
27 | Lookup language english name by code
|
28 |
|
29 | ### getAllNames()
|
30 | - @return {array}
|
31 |
|
32 | Get array of all language english names
|
33 |
|
34 | ### getNativeName(code)
|
35 | - @param code {string}
|
36 | - @return {string}
|
37 |
|
38 | Lookup language native name by code
|
39 |
|
40 | ### getAllNativeNames()
|
41 | - @return {array}
|
42 |
|
43 | Get array of all language native names
|
44 |
|
45 |
|
46 | ### getCode(name)
|
47 | - @param name {string}
|
48 | - @return {string}
|
49 |
|
50 | Lookup code by english name or native name
|
51 |
|
52 | ### getAllCodes()
|
53 | - @return {array}
|
54 |
|
55 | Get array of all codes
|
56 |
|
57 | ### validate(code)
|
58 | - @param code {string}
|
59 | - @return {boolean}
|
60 |
|
61 | Check 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 |
|
67 | Get the array of the language objects by the given codes
|
68 |
|
69 | ## Usage
|
70 |
|
71 | ```
|
72 | var ISO6391 = require('./iso-639-1')
|
73 |
|
74 | console.log(ISO6391.getName('zh')) // 'Chinese'
|
75 | console.log(ISO6391.getNativeName('zh')) // '中文'
|
76 |
|
77 | console.log(ISO6391.getAllNames()) // ['Afar','Abkhaz', ... ,'Zulu']
|
78 | console.log(ISO6391.getAllNativeNames()) //['Afaraf','аҧсуа бызшәа', ... ,'isiZulu' ]
|
79 |
|
80 | console.log(ISO6391.getCode('Chinese')) // 'zh'
|
81 | console.log(ISO6391.getCode('中文')) // 'zh'
|
82 |
|
83 | console.log(ISO6391.getAllCodes()) //['aa','ab',...,'zu']
|
84 |
|
85 | console.log(ISO6391.validate('en')) // true
|
86 | console.log(ISO6391.validate('xxx')) // false
|
87 |
|
88 | console.log(ISO6391.getLanguages(['en', 'zh']))
|
89 | // [{code:'en',name:'English',nativeName:'English'},{code:'zh',name:'Chinese',nativeName:'中文'}]
|
90 |
|
91 | ```
|