-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathlanguage-list.js
42 lines (34 loc) · 1.05 KB
/
language-list.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
'use strict'
var data = require('./data.json');
/**
* Precompute measure and code lookups.
*/
var languageNameMap = {};
var languageCodeMap = {};
data.forEach(function(language) {
languageNameMap[language.language.toLowerCase()] = language.code;
languageCodeMap[language.code.toLowerCase()] = language.language;
});
module.exports = LanguageList;
function LanguageList() {
if (!(this instanceof LanguageList)) return new LanguageList();
};
LanguageList.prototype.getLanguageCode = function getLanguageCode(name) {
return languageNameMap[name.toLowerCase()];
};
LanguageList.prototype.getLanguageName = function getLanguageNames(code) {
return languageCodeMap[code.toLowerCase()];
};
LanguageList.prototype.getLanguageNames = function getLanguageNames() {
return data.map(function(language) {
return language.language;
});
};
LanguageList.prototype.getLanguageCodes = function getLanguageCodes() {
return data.map(function(language) {
return language.code;
});
};
LanguageList.prototype.getData = function getData() {
return data;
};