-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
39 lines (35 loc) · 1.13 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
var _CountryData = require('./countrydata.json')
_ = require('lodash')
function CountryHelper()
{
var countries = _.map(_CountryData, function(country)
{
return _.pick(country, 'code','name');
})
Object.defineProperties(this,
{
'countries': {
'get': function()
{
return countries;
}
}
})
}
_.extend(CountryHelper.prototype,
{
states: function(countryCode)
{
return _CountryData[countryCode.toUpperCase()] && _CountryData[countryCode.toUpperCase()].states;
},
countryName: function(countryCode)
{
return _CountryData[countryCode.toUpperCase()] && _CountryData[countryCode.toUpperCase()].name;
},
stateName: function(countryCode,stateCode)
{
return _CountryData[countryCode.toUpperCase()] && _CountryData[countryCode.toUpperCase()].states[stateCode] && _CountryData[countryCode.toUpperCase()].states[stateCode];
}
});
var CountryHelperInstance = new CountryHelper();
module.exports = CountryHelperInstance;