rc-geographic
TypeScript icon, indicating that this package has built-in type declarations

1.0.8 • Public • Published

rc-geographic

Dataset for Countries, States, and Cities

WebsiteDocumentation

npm version install size npm downloads Known Vulnerabilities

Table of Contents

Features

  • Read Country List
  • Read States by Country
  • Read Cities by Country and State
  • Get the Longitude and Latitude of the Country, State, and City

Browser Support

Chrome Firefox Safari Opera Edge IE
Latest Latest Latest Latest Latest 11

Installing

$ npm install rc-geographic

API Summary

Methods which you can use

Function Return
getAllCountries() Return all countries ICountry[]
getCountryByCode(countryCode: str) Return country by Country code ICountry
getCountryByKeyValue(key: ICountryUniqueKeys, value: str) Return country by any specified code ICountry
getAllStates() Return all States IState[]
getStatesByCountry(countryCode: str) Return states by Country code IState[]
getStateByKeyValue(key: IStateUniqueKeys, value: str) Return state by any specified code IState
getAllCities() Return all Cities ICity[]
getCityByKeyValue(key: ICityUniqueKeys, value: str) Return city by any specified code ICity
getCitiesByCountry(countryCode: str) Return cities by Country code ICity[]
getCitiesByCountryAndState(countryCode: str, stateCode: str) Return cities by country and state code ICity[]

API

getAllCountries()

Return all countries

return type: json | ICountry[]

import { getAllCountries } from 'rc-geographic';

let countryList = getAllCountries();

[
    {
        "capital": "Kabul",
        "continent": "Asia",
        "currency": "Afghani",
        "iso2": "AF",
        "iso3": "AFG",
        "isoNumeric": "004",
        "name": "Afghanistan",
        "phoneCode": "93"
    }
    ...
]

getCountryByCode(countryCode: str)

Return country by ISO2 Country code

return type: json | ICountry

import { getCountryByCode } from 'rc-geographic';

let country = getCountryByCode("AF");

{
    "capital": "Kabul",
    "continent": "Asia",
    "currency": "Afghani",
    "iso2": "AF",
    "iso3": "AFG",
    "isoNumeric": "004",
    "name": "Afghanistan",
    "phoneCode": "93"
}

getCountryByKeyValue(key: ICountryUniqueKeys, value: str)

Return country by any specified code

return type: json | ICountry

import { getCountryByKeyValue } from 'rc-geographic';

let country = getCountryByKeyValue("iso3", "AFG");

{
    "capital": "Kabul",
    "continent": "Asia",
    "currency": "Afghani",
    "iso2": "AF",
    "iso3": "AFG",
    "isoNumeric": "004",
    "name": "Afghanistan",
    "phoneCode": "93"
}

getAllStates()

Return all states

return type: json | IState[]

import { getAllStates } from 'rc-geographic';

let stateList = getAllStates();

[
    {
        "cCode": "US",
        "code": "MD",
        "lat": "39.00039",
        "lng": "-76.74997",
        "name": "Maryland",
        "pCode": "",
        "tZone": "America/New_York"
    }
    ...
]

getStatesByCountry(countryCode: str)

Return states by ISO2 Country code

return type: json | IState[]

import { getStatesByCountry } from 'rc-geographic';

let stateList = getStatesByCountry("US");

[
    {
        "cCode": "US",
        "code": "MD",
        "lat": "39.00039",
        "lng": "-76.74997",
        "name": "Maryland",
        "pCode": "",
        "tZone": "America/New_York"
    }
    ...
]

getStateByKeyValue(key: IStateUniqueKeys, value: str)

Return state by any specified code

return type: json | IState

import { getStateByKeyValue } from 'rc-geographic';

let state = getStateByKeyValue("code", "MD");

{
    "cCode": "US",
    "code": "MD",
    "lat": "39.00039",
    "lng": "-76.74997",
    "name": "Maryland",
    "pCode": "",
    "tZone": "America/New_York"
}

getAllCities()

Return all cities

return type: json | ICity[]

import { getAllCities } from 'rc-geographic';

let cityList = getAllCities();

[
    {
        "cCode": "US",
        "code": "US-1",
        "lat": "30.88296",
        "lng": "-87.77305",
        "name": "Bay Minette",
        "pCode": "",
        "sCode": "AL"
        "tZone": "America/Chicago"
    }
    ...
]

getCityByKeyValue(key: ICityUniqueKeys, value: str)

Return city by any specified code

return type: json | ICity

import { getCityByKeyValue } from 'rc-geographic';

let city = getCityByKeyValue("code", "US-1");

{
    "cCode": "US",
    "code": "US-1",
    "lat": "30.88296",
    "lng": "-87.77305",
    "name": "Bay Minette",
    "pCode": "",
    "sCode": "AL"
    "tZone": "America/Chicago"
}

getCitiesByCountry(countryCode: str)

Return cities by ISO2 Country code

return type: json | ICity[]

import { getCitiesByCountry } from 'rc-geographic';

let cityList = getCitiesByCountry("US");

[
    {
        "cCode": "US",
        "code": "US-1",
        "lat": "30.88296",
        "lng": "-87.77305",
        "name": "Bay Minette",
        "pCode": "",
        "sCode": "AL"
        "tZone": "America/Chicago"
    }
    ...
]

getCitiesByCountryAndState(countryCode: str, stateCode: str)

Return cities by ISO2 Country code, and state code

return type: json | ICity[]

import { getCitiesByCountryAndState } from 'rc-geographic';

let cityList = getCitiesByCountryAndState("US", 'FL');

[
    {
        "cCode": "US",
        "code": "US-11",
        "lat": "28.18085",
        "lng": "-82.68177",
        "name": "Trinity",
        "pCode": "",
        "sCode": "FL"
        "tZone": "America/New_York"
    }
    ...
]

Types

ICountry

export interface ICountry {
    name: string;
    iso2: string;
    iso3: string;
    isoNumeric: string;
    phoneCode: string;
    currency: string;
    continent: string;
    capital: string;
}

ICountryUniqueKeys

export type ICountryUniqueKeys = 'iso2' | 'iso3' | 'isoNumeric';

ICountryKeys

export type ICountryKeys = 'name' | 'iso2' | 'iso3' | 'isoNumeric' | 'phoneCode' | 'currency' | 'continent' | 'capital';

IState

export interface IState {
    code: string;
    name: string;
    cCode: string;
    pCode: string;
    lat: string;
    lng: string;
    tZone: string;
}

IStateUniqueKeys

export type IStateUniqueKeys = 'code';

IStateKeys

export type IStateKeys = 'code' | 'name' | 'cCode' | 'pCode' | 'lat' | 'lat' | 'tZone';

ICity

export interface ICity {
    code: string;
    name: string;
    cCode: string;
    sCode: string;
    pCode: string;
    lat: string;
    lng: string;
    tZone: string;
}

ICityUniqueKeys

export type ICityUniqueKeys = 'code';

ICityKeys

export type ICityKeys = 'code' | 'name' | 'cCode' | 'sCode' | 'pCode' | 'lat' | 'lat' | 'tZone';

Package Sidebar

Install

npm i rc-geographic

Weekly Downloads

17

Version

1.0.8

License

MIT

Unpacked Size

31.5 MB

Total Files

61

Last publish

Collaborators

  • chamara-g