UNPKG

country_city_regions

Version:

Countries and there relevent cities and their regions. There are few countries which have regions included as well

39 lines (38 loc) 1.16 kB
module.exports = { getCountries: function() { var data = require("./data.json"); var countries = []; for (key in data["countries"]) { countries.push(key); } return countries; }, getCities: function(country) { var splits = country.split(" "); country = null; splits.forEach(function(split) { country = country ? country + " " + split : split; }); var data = require("./data.json"); return data["countries"][country]; }, getCityRegions: function(country) { var splits = country.split(" "); country = null; splits.forEach(function(split) { country = country ? country + " " + split : split; }); var data = require("./data.json"); var getRegionNames = data["regions"][country]; if(getRegionNames === undefined || getRegionNames === "undefined"){ var getAllCities = data["countries"][country]; var allCitiesAsRegion = []; allCitiesAsRegion.push({name:"All Cities"}); getAllCities.forEach(function(city) { allCitiesAsRegion.push({name:city}); }); getRegionNames = allCitiesAsRegion; } return getRegionNames; } };