-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
78 lines (59 loc) · 1.61 KB
/
index.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
const lcid = require('windows-locale')
const iso = require('iso639-codes')
const langs = require('langs').all()
const all = []
let lcidLanguage
let isoLanguage
const lcidKeys = Object.keys(lcid)
const isoKeys = Object.keys(iso)
lcidKeys.map(id => {
lcidLanguage = id
const locale = {
name: lcid[lcidLanguage].language,
local: null,
location: lcid[lcidLanguage].location,
tag: lcid[lcidLanguage].tag,
lcid: lcid[lcidLanguage].id,
'iso639-2': null,
'iso639-1': null
}
isoLanguage = isoKeys.find(name => name.toLowerCase() === lcid[lcidLanguage].language.toLowerCase())
if (isoLanguage) {
locale['iso639-2'] = iso[isoLanguage]['iso639-2']
locale['iso639-1'] = iso[isoLanguage]['iso639-1']
const nameLocal = langs.find(element => {
if (element['2T']) {
return element['2T'].toLowerCase() === locale['iso639-2']
}
return false
})
if (nameLocal) {
locale.local = nameLocal.local
}
}
all.push(locale)
})
const where = (key = 'name', text = '') => {
if (key === 'lcid') {
return all.find(element => element[key] === text)
}
return all.find(element => element[key].toLowerCase() === text.toLowerCase())
}
const getByName = text => where('name', text)
const getByNameLocal = text => where('local', text)
const getByLocation = text => where('location', text)
const getByTag = text => where('tag', text)
const getByLCID = id => where('lcid', Number(id))
const getByISO6392 = text => where('iso639-2', text)
const getByISO6391 = text => where('iso639-1', text)
module.exports = {
all,
where,
getByName,
getByNameLocal,
getByLocation,
getByTag,
getByLCID,
getByISO6392,
getByISO6391
}