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

country-state-city-js

v2.5.0

Published

A fast & light weight JS library to get countries geographical information including states, cities, iso codes, etc.

Downloads

9,015

Readme

Overview


A simple yet powerful module to get country, state and city with their interrelated data. Use this tool to create awesome dropdowns for selecting country state sities, or any other purposes you have...

Features


  • Beautiful API with Inter-related (Relational) data access
  • Highly optimised and faster data reads
  • Total 249 Countries, 4,928 States, 1,48,873 Cities
  • Geo Locations
  • Region and Languages
  • Dialcodes
  • Lite version API

Getting Started


npm install country-state-city-js@latest

API Methods


  • Country()
  • State()
  • City()
  • CountryLite()
  • StateLite()
  • CityLite()

Usage


Country() and CountryLite()

//ES6
import { Country, CountryLite } from 'country-state-city-js'

//Legacy
const { Country, CountryLite } = require('country-state-city-js')
//1. Get all countries

const countries = Country() or CountryLite()

//Both country and country light methods share same parameters and options
//2. Get all countries with states

const countries = Country({ states:true })
//3. Get all countries with states and cities

const countries = Country({ states:true, cities:true })
//4. Get a country record with ISO2 code

const india = Country('IN')
const unitedStates = Country('US')
const australia = Country('AU')
//5. Get a country record with states

const india = Country('IN', { states:true })
//6. Get a country record with states and cities

const india = Country('IN', { states:true, cities:true })

State() or StateLite()

Note: Country iso2 parameter is mandatory

//ES6
import { State, StateLite } from 'country-state-city-js'

//Legacy
const { State, StateLite } = require('country-state-city-js')
//1. Get all states of a country

const states = State('IN') or StateLite('IN')
//2. Get all states with cities

const states = State('IN', { cities:true })
//3. Get a state of a country

const state = State('IN', 'DL') //Delhi state of India
const state = State('US', 'NY') //New York state of USA
//4. Get a state with cities

const state = Country('IN', 'DL', { cities:true })

City() or CityLite()

Note: Country iso2 and State iso parameter is mandatory

//ES6
import { City, CityLite } from 'country-state-city-js'

//Legacy
const { City, CityLite } = require('country-state-city-js')
//1. Get all cities of a state of country

const cities = City('IN', 'UP') or CityLite('IN', 'UP')
const cities = City('US', 'NY') or CityLite('US', 'NY')

Country Object


{
    "name": "India",
    "native": "भारत",
    "code": "IN",
    "iso": {
    "alpha2": "IN",
    "alpha3": "IND",
    "numeric": "356"
},
"region": {
    "main": "Asia",
    "sub": "Southern Asia",
    "code": "142"
},
"geo": {
    "latitude": "28.6353",
    "longitude": "77.225"
},
    "dialcode": "+91",
    "capital": {
    "name": "New Delhi",
    "latitude": "28.6",
    "longitude": "77.200000"
},
    "currency": {
    "code": "INR",
    "name": "Indian Rupee",
    "symbol": "Rs",
    "native": "₹"
},
"flag": {
    "emoji": "🇮🇳"
},
"tld": ".in",
"languages": [
        "Hindi",
        "Gujarati",
        "Kashmiri",
        "Kannada",
        "Malayalam",
        "Marathi",
        "Nepali",
        "Oriya",
        "Panjabi / Punjabi",
        "Tamil",
        "Telugu",
        "Sindhi",
        "Urdu",
        "Bengali",
        "Sanskrit",
        "Assamese",
        "Maithili",
        "Dogri",
        "Boro",
        "Meitei",
        "Santali",
        "Konkani"
    ]
}

Country Lite Object


{
    "name": "India",
    "code": "IN",
    "dialcode": "+91",
    "currency": "INR",
    "flag": "🇮🇳"
}

State Object


{
    "name": "New York",
    "countryCode": "US",
    "fipsCode": "36",
    "iso": "NY",
    "latitude": "40.71277530",
    "longitude": "-74.00597280"
}

State Lite Object


{
    "name": "New York",
    "iso": "NY"
}

City Object


{
    "name": "Karol Bagh",
    "latitude": "28.65136000",
    "longitude": "77.19072000"
}

Cities Lite Array


[
    "Alipur",
    "Bawana",
    "Central Delhi",
    "Delhi",
    "Deoli",
    "East Delhi",
    "Karol Bagh",
    "Najafgarh",
    "Narela",
    "New Delhi",
    "North Delhi",
    "North East Delhi",
    "North West Delhi",
    "Nangloi Jat",
    "Pitampura",
    "Rohini",
    "South Delhi",
    "South West Delhi",
    "West Delhi"
]

License


MIT

Data Sources


  1. Multiple sources from internet

Show your Support


If you like my work, please support and share it to your fellow people.

Changelog


Any further major changes will be updated here with version code.

Thank you and have a great time ahead!