all-cities
v0.1.0
Published
JSON Object containing list of all countries, states and cities.
Downloads
9
Readme
countrycitystatejson
JSON formatted data containing the world's countries, states/provinces, and cities.
Usage
knock yourself out
yourhandle.getAll()
Returns entire DB in JSON format. ~ 2.5MB
yourhandle.getCountries()
yourhandle.getCountriesShort()
yourhandle.getCountryByShort(shortName)
yourhandle.getCountryInfoByShort(shortName)
yourhandle.getStatesByShort(shortName)
yourhandle.getCities(shortName, state)
if u really care this is a copied text
In my search for a good database in JSON format that contained Countries and their associated states and cities, I found disparate solutions. While I found a great database of countries from https://github.com/annexare/Countries and a great database of cities from https://github.com/lutangar/cities.json, I required a linkage between them via states/provinces. I did indeed found a solution https://www.npmjs.com/package/country-state-city. However, it did not have rich enough data from the other databases. In addition, a spot check on that particular database showed errors. The United States showed 57 states, those 7 extra entries were also incorrect (e.g. it contained state entries for the US named: Midland, Seward, Lowa, etc). Why didn't I just fix it and make a pull request you say? The issue with that particular database was that the entries were linked together with integer ID's. So in order to lookup a list of states in a country, you need to use the country id. This indexing scheme extended down the hierarchy; in order to find the cities of a state, the parameter was a a state id, which stemmed from a country id. While this indexing scheme is high performant, it made edits and updates to the data somewhat painful. Any change in or update would require a reindexing of the whole data set. So in order for me to remove the 7 erroneous US states, extra code would need to be written to reindex. The solution I present you merges the rich data from https://github.com/annexare/Countries, merges it with https://www.npmjs.com/package/country-state-city and replaces the integer indexing scheme with named keys. This makes recompiling the final JSON object easier. Any edits to the underyling raw data can recompile the final json without a need for indexing. I'm making the assumption that there will be more edits and updates required. I personally only fixed the 7 erroneous states for country code US, and have not confirmed any other state/province and city for accuracy. In addition, removing the integer id indexing and replacing it with named indeces should not have a performance hit if you are using the V8 engine.