npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rc-geographic

v1.0.8

Published

Dataset for Countries, Cities, and States

Downloads

39

Readme

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