-
Notifications
You must be signed in to change notification settings - Fork 28
/
index.js
47 lines (39 loc) · 1.28 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
var statesAndLocalGov = require('./src/statesAndLocalGov.json');
function _lower(input) {
return input.toLowerCase().trim()
}
module.exports = {
all: function() {
return statesAndLocalGov;
},
states: function () {
return statesAndLocalGov.map(function (nigeriaStates) {
return nigeriaStates.state;
});
},
senatorial_districts: function (state) {
state = _lower(state);
if (!state || state == "") {
throw new Error('Invalid Nigeria State');
}
if (['fct', 'f.c.t', 'abuja', 'f c t'].includes(state)) {
state = 'Federal Capital Territory'
}
const response = statesAndLocalGov.find(function (nigeriaStates) {
return _lower(nigeriaStates.state) === _lower(state);
});
return response.senatorial_districts;
},
lgas: function (state) {
state = _lower(state);
if (!state || state == "") {
throw new Error('Invalid Nigeria State');
}
if (['fct', 'f.c.t', 'abuja', 'f c t'].includes(state)) {
state = 'Federal Capital Territory'
}
return statesAndLocalGov.find(function (nigeriaStates) {
return _lower(nigeriaStates.state) === _lower(state);
});
}
};