Basic library for Countries and States
This is a fork of harpreetkhalsagtbit/country-state-city that excludes the cities functionality, reducing the overall bundle-size by roughly 4.2MB.
Data sourced from hiiamrohit/Countries-States-Cities-database
npm install country-state-lib
or
yarn add country-state-lib
-
ES6 Module usage
import csc from 'country-state-lib' // Import Interfaces` import { ICountry, IState } from 'country-state-lib'
-
AMD Module usage
let csc = require('country-state-lib').default
Accepts a valid CountryCode
eg: 'AS'
and returns Country Details
type: json | ICountry
{
"id": "4",
"sortname": "AS",
"name": "American Samoa",
"phonecode": "1684"
}
Accepts a valid CountryId
and returns Country Details
type: json | ICountry
{
"id": "4",
"sortname": "AS",
"name": "American Samoa",
"phonecode": "1684"
}
Accepts a valid StateId
and returns State Details
type: json | IState
{
"id": 4119,
"name": "Midlands",
"country_id": "246"
}
Accepts a valid CountryId
and returns all States as Array of JSON
type: array of json | IState
[
{
"id": 4119,
"name": "Midlands",
"country_id": "246"
}
]
Returns all Countries
type: array of json | ICountry
[
{
"id": "4",
"sortname": "AS",
"name": "American Samoa",
"phonecode": "1684"
}
]