-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlanguage-name-map.js
43 lines (37 loc) · 1.15 KB
/
language-name-map.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*!
* language-name-map v0.3.0
* (c) 2020 Yurii Derevych
* Released under the BSD-2-Clause License.
*/
'use strict'
/**
* @author Yurii Derevych <[email protected]>
* @description A function to lookup the language name for a given locale ISO 639-1 code. In data included: english names, native names and directionality.
* @example
* getLangNameFromCode('uk').name
* getLangNameFromCode('uk').native
* getLangNameFromCode('uk').dir
* getLangCodeList()
* @public
* @version 0.3.0
* @license BSD-2-Clause
*/
const languageNameMap = require('./map')
module.exports.getLangNameFromCode = function (langCode) {
if (typeof langCode !== 'string') return undefined
const code = langCode.toLowerCase()
if (!{}.hasOwnProperty.call(languageNameMap, code)) return undefined
return {
name: languageNameMap[code].name,
native: languageNameMap[code].native,
dir: (Number(languageNameMap[code].dir) === 1) ? 'ltr' : 'rtl'
}
}
module.exports.getLangCodeList = function () {
const arr = []
Object.keys(languageNameMap).forEach((key) => {
arr.push(key)
})
return arr
}
module.exports.languageNameMap = languageNameMap