-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
31 lines (25 loc) · 966 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
/* jshint esversion: 6 */
String.prototype.normalize = require("./normalize");
let autocomplete = (function () {
const countries = require("./countries.json");
return {
cities: (key) => {
let re = new RegExp(key.normalize().toLocaleUpperCase());
let data = [];
Object.keys(countries).forEach(country => {
Object.keys(countries[country]).forEach(uf => {
if (uf == "code") return;
Object.keys(countries[country][uf]).forEach(city => {
if(re.test(city)) {
countries[country][uf][city].country = country;
countries[country][uf][city].uf = uf;
data.push(countries[country][uf][city]);
}
});
});
});
return data;
}
};
}());
module.exports = autocomplete;