-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathcountryCodes.js
65 lines (51 loc) · 1.46 KB
/
countryCodes.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
'use strict';
var countryCodes = require('./countryCodes.json'), Map = require("collections/map");
var countryCodesMap = new Map();
for ( var i = 0, len = countryCodes.length; i < len; i++) {
var country = countryCodes[i];
countryCodesMap.set(country.countryName.toLowerCase(), country);
countryCodesMap.set(country.iso2.toLowerCase(), country);
countryCodesMap.set(country.iso3.toLowerCase(), country);
if (country.phoneCode)// because some territories are landless and no phones exist there :-)
countryCodesMap.set(country.phoneCode.toLowerCase(), country);
countryCodesMap.set(country, country);
}
var CountryCodes = function() {
};
CountryCodes.getAll = function() {
return countryCodes;
};
CountryCodes.getCountry = function(param) {
return (param)?countryCodesMap.get(param.toLowerCase()):undefined;
};
CountryCodes.getISO2 = function(param) {
if(!param)
return undefined;
var country = countryCodesMap.get(param.toLowerCase());
if (country) {
return country.iso2;
} else {
return undefined;
}
};
CountryCodes.getISO3 = function(param) {
if(!param)
return undefined;
var country = countryCodesMap.get(param.toLowerCase());
if (country) {
return country.iso3;
} else {
return undefined;
}
};
CountryCodes.getPhoneCode = function(param) {
if(!param)
return undefined;
var country = countryCodesMap.get(param.toLowerCase());
if (country) {
return country.phoneCode;
} else {
return undefined;
}
};
module.exports = CountryCodes;