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

countries-states-cities

v1.0.6

Published

Countries, states/regions, cities.

Downloads

2,638

Readme

Countries, states/regions, cities.

Data from: https://github.com/dr5hn/countries-states-cities-database

Install

npm i countries-states-cities

OR

yarn add countries-states-cities

Usage

  • ES6 Module usage

    import csc from 'countries-states-cities'
  • AMD Module usage

    let csc = require('countries-states-cities')

Docs

csc.getCountryByCode(code)

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

type: json | ICountry

{
    "id": 233,
    "name": "United States",
    "iso3": "USA",
    "iso2": "US",
    "phone_code": "1",
    "capital": "Washington",
    "currency": "USD",
    "native": "United States",
    "region": "Americas",
    "subregion": "Northern America",
    "timezones": [
        {
            "zoneName": "America\/Adak",
            "gmtOffset": -36000,
            "gmtOffsetName": "UTC-10:00",
            "abbreviation": "HST",
            "tzName": "Hawaii–Aleutian Standard Time"
        },
        {
            "zoneName": "America\/Anchorage",
            "gmtOffset": -32400,
            "gmtOffsetName": "UTC-09:00",
            "abbreviation": "AKST",
            "tzName": "Alaska Standard Time"
        },
    ],
    "emoji": "🇺🇸",
    "emojiU": "U+1F1FA U+1F1F8"
}

csc.getCountryById(id)

It accepts a valid CountryId and returns Country Details

type: json | ICountry

{
    "id": 31,
    "name": "Brazil",
    "iso3": "BRA",
    "iso2": "BR",
    "phone_code": "55",
    "capital": "Brasilia",
    "currency": "BRL",
    "native": "Brasil",
    "region": "Americas",
    "subregion": "South America",
    "timezones": [
        {
            "zoneName": "America\/Araguaina",
            "gmtOffset": -10800,
            "gmtOffsetName": "UTC-03:00",
            "abbreviation": "BRT",
            "tzName": "Brasília Time"
        },
        {
            "zoneName": "America\/Bahia",
            "gmtOffset": -10800,
            "gmtOffsetName": "UTC-03:00",
            "abbreviation": "BRT",
            "tzName": "Brasília Time"
        },
    ],
    "emoji": "🇧🇷",
    "emojiU": "U+1F1E7 U+1F1F7"
}

csc.getStateById(id)

It accepts a valid StateId and returns State Details

type: json | IState

{
    "id": 1997,
    "name": "Rio de Janeiro",
    "country_id": 31,
    "country_code": "BR",
    "state_code": "RJ"
}

csc.getCityById(id)

It accepts a valid CityId and returns City Details

type: json | ICity

{
    "id": 16796,
    "name": "Paris",
    "state_id": 866,
    "state_code": "ON",
    "country_id": 39,
    "country_code": "CA",
    "latitude": "43.20000000",
    "longitude": "-80.38333000"
}

csc.getStatesOfCountry(countryId)

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

type: array of json | IState

[
  {
    "id": 1462,
    "name": "Washington",
    "country_id": 233,
    "country_code": "US",
    "state_code": "WA"
  }
]

csc.getCitiesOfState(stateId)

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

type: array of json | ICity

[
  {
    "id": 7052,
    "name": "Roma",
    "state_id": 3905,
    "state_code": "QLD",
    "country_id": 14,
    "country_code": "AU",
    "latitude": "-26.56741000",
    "longitude": "148.78751000"
  }
]

csc.getAllCountries

It returns all Countries

type: array of json | ICountry

[
  {
    "id": 39,
    "name": "Canada",
    "iso3": "CAN",
    "iso2": "CA",
    "phone_code": "1",
    "capital": "Ottawa",
    "currency": "CAD",
    "native": "Canada",
    "region": "Americas",
    "subregion": "Northern America",
    "emoji": "🇨🇦",
    "emojiU": "U+1F1E8 U+1F1E6"
  }
]

Insights

Total Countries: 250 Total States/Regions/Municipalities: 4,874 Total Cities/Towns/Districts: 146,156

Last Updated On: 22nd December 2020