UNPKG

country-state-city-js

Version:

A fast & light weight JS library to get countries geographical information including states, cities, iso codes, etc.

279 lines (245 loc) 5.36 kB
### Overview --- A simple yet powerful module to get country, state and city with their interrelated data. Use this tool to create awesome dropdowns for selecting country state sities, or any other purposes you have... ### Features --- * Beautiful API with Inter-related (Relational) data access * Highly optimised and faster data reads * Total 249 Countries, 4,928 States, 1,48,873 Cities * Geo Locations * Region and Languages * Dialcodes * Lite version API ### Getting Started --- ```js npm install country-state-city-js@latest ``` ### API Methods --- * Country() * State() * City() * CountryLite() * StateLite() * CityLite() ### Usage --- #### Country() and CountryLite() ```js //ES6 import { Country, CountryLite } from 'country-state-city-js' //Legacy const { Country, CountryLite } = require('country-state-city-js') ``` ```js //1. Get all countries const countries = Country() or CountryLite() //Both country and country light methods share same parameters and options ``` ```js //2. Get all countries with states const countries = Country({ states:true }) ``` ```js //3. Get all countries with states and cities const countries = Country({ states:true, cities:true }) ``` ```js //4. Get a country record with ISO2 code const india = Country('IN') const unitedStates = Country('US') const australia = Country('AU') ``` ```js //5. Get a country record with states const india = Country('IN', { states:true }) ``` ```js //6. Get a country record with states and cities const india = Country('IN', { states:true, cities:true }) ``` #### State() or StateLite() *Note: Country iso2 parameter is mandatory* ```js //ES6 import { State, StateLite } from 'country-state-city-js' //Legacy const { State, StateLite } = require('country-state-city-js') ``` ```js //1. Get all states of a country const states = State('IN') or StateLite('IN') ``` ```js //2. Get all states with cities const states = State('IN', { cities:true }) ``` ```js //3. Get a state of a country const state = State('IN', 'DL') //Delhi state of India const state = State('US', 'NY') //New York state of USA ``` ```js //4. Get a state with cities const state = Country('IN', 'DL', { cities:true }) ``` #### City() or CityLite() *Note: Country iso2 and State iso parameter is mandatory* ```js //ES6 import { City, CityLite } from 'country-state-city-js' //Legacy const { City, CityLite } = require('country-state-city-js') ``` ```js //1. Get all cities of a state of country const cities = City('IN', 'UP') or CityLite('IN', 'UP') const cities = City('US', 'NY') or CityLite('US', 'NY') ``` ### Country Object --- ```js { "name": "India", "native": "भारत", "code": "IN", "iso": { "alpha2": "IN", "alpha3": "IND", "numeric": "356" }, "region": { "main": "Asia", "sub": "Southern Asia", "code": "142" }, "geo": { "latitude": "28.6353", "longitude": "77.225" }, "dialcode": "+91", "capital": { "name": "New Delhi", "latitude": "28.6", "longitude": "77.200000" }, "currency": { "code": "INR", "name": "Indian Rupee", "symbol": "Rs", "native": "₹" }, "flag": { "emoji": "🇮🇳" }, "tld": ".in", "languages": [ "Hindi", "Gujarati", "Kashmiri", "Kannada", "Malayalam", "Marathi", "Nepali", "Oriya", "Panjabi / Punjabi", "Tamil", "Telugu", "Sindhi", "Urdu", "Bengali", "Sanskrit", "Assamese", "Maithili", "Dogri", "Boro", "Meitei", "Santali", "Konkani" ] } ``` ### Country Lite Object --- ```js { "name": "India", "code": "IN", "dialcode": "+91", "currency": "INR", "flag": "🇮🇳" } ``` ### State Object --- ```js { "name": "New York", "countryCode": "US", "fipsCode": "36", "iso": "NY", "latitude": "40.71277530", "longitude": "-74.00597280" } ``` ### State Lite Object --- ```js { "name": "New York", "iso": "NY" } ``` ### City Object --- ```js { "name": "Karol Bagh", "latitude": "28.65136000", "longitude": "77.19072000" } ``` ### Cities Lite Array --- ```js [ "Alipur", "Bawana", "Central Delhi", "Delhi", "Deoli", "East Delhi", "Karol Bagh", "Najafgarh", "Narela", "New Delhi", "North Delhi", "North East Delhi", "North West Delhi", "Nangloi Jat", "Pitampura", "Rohini", "South Delhi", "South West Delhi", "West Delhi" ] ``` ### License --- [MIT](https://github.com/codecravegit/country-state-city-js/blob/master/LICENSE.txt) ### Data Sources --- 1. Multiple sources from internet ### Show your Support --- If you like my work, please support and share it to your fellow people. * [Star this repository](https://github.com/codecravegit/country-state-city-js) * [Share my work](https://www.linkedin.com/sharing/share-offsite/?url=https://github.com/codecravegit/country-state-city-js) * Feel free to fork and experiment, if found any bug or have any suggestion, do let me know. * Any data related issue? [Open an issue](https://github.com/codecravegit/country-state-city-js/issues/new) ### Changelog --- *Any further major changes will be updated here with version code.* <br/> #### Thank you and have a great time ahead!