UNPKG

2.68 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## Usage
22
23### Node.js
24
25```javascript
26const ISO6391 = require('iso-639-1');
27console.log(ISO6391.getName('en')); // 'English'
28```
29
30### ES Module
31
32```javascript
33import ISO6391 from 'iso-639-1';
34console.log(ISO6391.getName('en')); // 'English'
35```
36
37### Browsers
38
39HTML
40
41```html
42<script type="text/javascript" src="./node_modules/iso-639-1/build/index.js"></script>
43```
44
45Visit global variable ISO6391 in js
46
47```javascript
48console.log(ISO6391.getName('en')); // 'English'
49```
50
51## Methods
52
53### getName(code)
54 - @param code {string}
55 - @return {string}
56
57Lookup language english name by code
58
59### getAllNames()
60 - @return {array}
61
62Get array of all language english names
63
64### getNativeName(code)
65 - @param code {string}
66 - @return {string}
67
68Lookup language native name by code
69
70### getAllNativeNames()
71 - @return {array}
72
73Get array of all language native names
74
75
76### getCode(name)
77 - @param name {string}
78 - @return {string}
79
80Lookup code by english name or native name
81
82### getAllCodes()
83 - @return {array}
84
85Get array of all codes
86
87### validate(code)
88 - @param code {string}
89 - @return {boolean}
90
91Check whether the given code is in the list of [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes)
92
93### getLanguages(codes)
94 - @param codes {array}
95 - @return {array}
96
97Get the array of the language objects by the given codes
98
99## Example
100
101```
102const ISO6391 = require('iso-639-1')
103
104console.log(ISO6391.getName('zh')) // 'Chinese'
105console.log(ISO6391.getNativeName('zh')) // '中文'
106
107console.log(ISO6391.getAllNames()) // ['Afar','Abkhaz', ... ,'Zulu']
108console.log(ISO6391.getAllNativeNames()) //['Afaraf','аҧсуа бызшәа', ... ,'isiZulu' ]
109
110console.log(ISO6391.getCode('Chinese')) // 'zh'
111console.log(ISO6391.getCode('中文')) // 'zh'
112
113console.log(ISO6391.getAllCodes()) //['aa','ab',...,'zu']
114
115console.log(ISO6391.validate('en')) // true
116console.log(ISO6391.validate('xx')) // false
117
118console.log(ISO6391.getLanguages(['en', 'zh']))
119// [{code:'en',name:'English',nativeName:'English'},{code:'zh',name:'Chinese',nativeName:'中文'}]
120
121```