-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathindex.js
37 lines (30 loc) · 774 Bytes
/
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
'use strict';
var data = require('./data.json');
var find = require('lodash.find');
var methods = {
countryCode: function(countryCode) {
if (!countryCode) {
throw new Error('Expected 1 country code as the first argument');
}
return find(data, function(country) {
return country.code === countryCode.toUpperCase();
});
},
get data() {
return data;
}
};
['emoji', 'code', 'name', 'unicode'].forEach(function(prop) {
Object.defineProperty(methods, prop + 's', {
get: function() {
return data.map(function(country) {
return country[prop];
});
}
});
});
// TODO: figure out if this is a good idea
data.forEach(function(prop, index) {
methods[prop.code] = data[index];
});
module.exports = methods;