🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

country-state-lib

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

country-state-lib

Library for fetching Countries and States

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

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"
  }
]

Keywords

Country

FAQs

Package last updated on 18 Nov 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts