Basic library for Country, State and City
Initial database fetched from: https://github.com/hiiamrohit/Countries-States-Cities-database Improved and updated Repo from: https://github.com/harpreetkhalsagtbit/country-state-city
npm i countrystatecitylist
-
ES6 Module usage
import csc from 'countrystatecitylist' // Import Interfaces` import { ICountry, IState, ICity } from 'countrystatecitylist'
-
AMD Module usage
let csc = require('countrystatecitylist').default // OR let csc = require('countrystatecitylist')
It accepts a valid CountryCode
(sortname) eg: 'AS'
and returns Country Details
type: json | ICountry
example: getCountryByCode(AS)
{
"id": "4",
"sortname": "AS",
"name": "American Samoa",
"phonecode": "1684"
}
It accepts a valid CountryId
and returns Country Details
type: json | ICountry
example: getCountryById(4)
{
"id": "4",
"sortname": "AS",
"name": "American Samoa",
"phonecode": "1684"
}
It accepts a valid StateId
and returns State Details
type: json | IState
example: getStateById(4119)
{
"id": 4119,
"name": "Midlands",
"country_id": "246"
}
It accepts a valid CityId
and returns City Details
type: json | ICity
example: getCityById(3)
{
"id": "3",
"name": "Port Blair",
"state_id": "1"
}
It accepts a valid CountryId
and returns all States as Array of JSON
type: array of json | IState
[
{
"id": 4119,
"name": "Midlands",
"country_id": "246"
}
]
It accepts a valid CityId
and returns all Cities as Array of JSON
type: array of json | ICity
[
{
"id": "3",
"name": "Port Blair",
"state_id": "1"
}
]
It returns all Countries
type: array of json | ICountry
[
{
"id": "4",
"sortname": "AS",
"name": "American Samoa",
"phonecode": "1684"
}
]