1.0.0 • Published 4 years ago

country-state-lib v1.0.0

Weekly downloads
4
License
GPL-3.0
Repository
github
Last release
4 years ago

country-state-lib

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

Install

npm install country-state-lib

or

yarn add country-state-lib

Usage

  • 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

Documentation

getCountryByCode(code)


Accepts a valid CountryCode eg: 'AS' and returns Country Details

type: json | ICountry

{
	"id": "4",
	"sortname": "AS",
	"name": "American Samoa",
	"phonecode": "1684"
}

getCountryById(id)


Accepts a valid CountryId and returns Country Details

type: json | ICountry

{
	"id": "4",
	"sortname": "AS",
	"name": "American Samoa",
	"phonecode": "1684"
}

getStateById(id)


Accepts a valid StateId and returns State Details

type: json | IState

{
	"id": 4119,
	"name": "Midlands",
	"country_id": "246"
}

getStatesOfCountry(countryId)


Accepts a valid CountryId and returns all States as Array of JSON

type: array of json | IState

[
  {
    "id": 4119,
    "name": "Midlands",
    "country_id": "246"
  }
]

getAllCountries

Returns all Countries

type: array of json | ICountry

[
  {
    "id": "4",
    "sortname": "AS",
    "name": "American Samoa",
    "phonecode": "1684"
  }
]