1.0.8 • Published 1 year ago

rc-geographic v1.0.8

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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

ChromeFirefoxSafariOperaEdgeIE
Latest ✔Latest ✔Latest ✔Latest ✔Latest ✔11 ✔

Installing

$ npm install rc-geographic

API Summary

Methods which you can use

FunctionReturn
getAllCountries()Return all countriesICountry[]
getCountryByCode(countryCode: str)Return country by Country codeICountry
getCountryByKeyValue(key: ICountryUniqueKeys, value: str)Return country by any specified codeICountry
getAllStates()Return all StatesIState[]
getStatesByCountry(countryCode: str)Return states by Country codeIState[]
getStateByKeyValue(key: IStateUniqueKeys, value: str)Return state by any specified codeIState
getAllCities()Return all CitiesICity[]
getCityByKeyValue(key: ICityUniqueKeys, value: str)Return city by any specified codeICity
getCitiesByCountry(countryCode: str)Return cities by Country codeICity[]
getCitiesByCountryAndState(countryCode: str, stateCode: str)Return cities by country and state codeICity[]

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';
1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago