lazy-country-city-state

v0.0.2
This is the library to process country city state.

This is the library to process country city state.

Basic library for Country, State and City

Data Source:

It's a customization of https://github.com/harpreetkhalsagtbit/country-state-city/tree/master/lib

Lazy load to use

Due to its size, we need to lazy load it. But don't worry, we have a hook to do that. Just put it in the component that you want to use the lazyLoad.

import { useLazyLoad } from 'lazy-country-city-state';
  const { ready: countryReady } = useLazyLoad('country');
  const { ready: stateReady } = useLazyLoad('state');
  const { ready: cityReady } = useLazyLoad('city');

Note: If you want to use it outside of the component, please using loadData

import { loadData } from 'lazy-country-city-state';

Docs

Docs

getCountryByCode(code)

It accepts a valid CountryCode eg: 'AS' and returns Country Details

type: json | ICountry

{
    "isoCode": "IN",
    "name": "India",
    "phonecode": "91",
    "flag": "🇮🇳",
    "currency": "INR",
    "latitude": "20.00000000",
    "longitude": "77.00000000",
    "timezones": [
        {
            "zoneName": "Asia\/Kolkata",
            "gmtOffset": 19800,
            "gmtOffsetName": "UTC+05:30",
            "abbreviation": "IST",
            "tzName": "Indian Standard Time"
        }
    ]
}

getStatesOfCountry(countryCode)

It accepts a valid CountryCode and returns all States as Array of JSON

type: array of json | IState

[
    {
        "name": "Delhi",
        "isoCode": "DL",
        "countryCode": "IN",
        "latitude": "28.70405920",
        "longitude": "77.10249020"
    }
]

getCitiesOfState(countryCode, stateCode)

It accepts a valid CountryCode, StateCode and returns all Cities as Array of JSON

type: array of json | ICity

[
    {
        "name": "New Delhi",
        "countryCode": "IN",
        "stateCode": "DL",
        "latitude": "28.63576000",
        "longitude": "77.22445000"
    }
]

getCitiesOfCountry(countryCode)

It accepts a valid CountryCode and returns all Cities as Array of JSON

type: array of json | ICity

[
    {
        "name": "New Delhi",
        "countryCode": "IN",
        "stateCode": "DL",
        "latitude": "28.63576000",
        "longitude": "77.22445000"
    }
]

getAllCountries

It returns all Countries

type: array of json | ICountry

[
    {
        "isoCode": "IN",
        "name": "India",
        "phonecode": "91",
        "flag": "🇮🇳",
        "currency": "INR",
        "latitude": "20.00000000",
        "longitude": "77.00000000",
        "timezones": [
            {
                "zoneName": "Asia\/Kolkata",
                "gmtOffset": 19800,
                "gmtOffsetName": "UTC+05:30",
                "abbreviation": "IST",
                "tzName": "Indian Standard Time"
            }
        ]
    }
]

getAllStates

It returns all States

type: array of json | IState

[
    {
        "name": "Delhi",
        "isoCode": "DL",
        "countryCode": "IN",
        "latitude": "28.70405920",
        "longitude": "77.10249020"

    }
]

getAllCities

It returns all Cities

type: array of json | ICity

[
    {
        "name": "Delhi",
        "isoCode": "DL",
        "countryCode": "IN",
        "latitude": "28.70405920",
        "longitude": "77.10249020"
    }
]

*** Contribution guide ***

yarn processData
  • Copy all files in build folder to public folder

Metadata

  • MIT
  • Whatever
  • Unknown
  • released 2/26/2021

Downloads

Maintainers