Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

country-state-picker

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

country-state-picker

NPM package to get the list of countries and their states.

  • 1.1.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.6K
decreased by-59.84%
Maintainers
1
Weekly downloads
 
Created
Source

Country State Picker

NPM package to get the list of countries and their states.

npm version

Installation

npm i country-state-picker --save

Usage

getCountries()

This function will return the array of all the countries.

Output
[
    {
        "name": "Afghanistan",
        "code": "af",
        "dial_code": "+93"
    },
    {
        "name": "Albania",
        "code": "al",
        "dial_code": "+355"
    },
    {
        "name": "Algeria",
        "code": "dz",
        "dial_code": "+213"
    },
    {
        "name": "Andorra",
        "code": "ad",
        "dial_code": "+376"
    }
  ...
]

getStates(<country_code>)

This function will return the array of all the states of a given country.

Example

To get the list of all the states of INDIA, the function call will look like:

let states = getStates('in');

console.log(states)
Output
[
    "Assam",
    "Goa",
    "Madhya Pradesh",
    "Manipur",
    "Meghalaya",
    "Mizoram",
    "National Capital Territory of Delhi",
    "Sikkim",
    "Andhra Pradesh",
    "Arunachal Pradesh",
    "Bihar",
    "Chhattisgarh",
    "Gujarat",
    "Haryana",
    "Himachal Pradesh",
    "Jammu and Kashmir",
    "Jharkhand",
    "Karnataka",
    "Kerala",
    "Maharashtra",
    "Nagaland",
    "Odisha",
    "Punjab",
    "Rajasthan",
    "Tamil Nad",
    "Uttarakhand",
    "Telangana",
    "Tripura",
    "Andaman and Nicobar Islands",
    "Chandigarh",
    "Dadra and Nagar Haveli",
    "Daman and Di",
    "Lakshadweep",
    "Puducherry",
    "Uttar Pradesh",
    "West Bengal"
]

getCountry(<country_name | country_code | dial_code>)

This function will return the country corresponding to the argument passed.

Example

To get the country having dial code "+91", the function call will look like:

let country = getCountry('+91');

console.log(country)
Output
{
    "name": "India",
    "code": "in",
    "dial_code": "+91"
}

getFilteredCountries([<country_name | country_code | dial_code>])

This function will receive an array of arguments and return the array of countries corresponding to the argument.

Example

To get only India, USA and Australia country objects, the function call will look like:

let filteredCountries = getFilteredCountries(['+91', 'us', 'Australia']);

console.log(filteredCountries)
Output
[
    {
        "name": "India",
        "code": "in",
        "dial_code": "+91"
    }, 
    {
        "name": "United States of America",
        "code": "us",
        "dial_code": "+1"
    },
    {
        "name": "Australia",
        "code": "au",
        "dial_code": "+61"
    }
]

Keywords

FAQs

Package last updated on 17 May 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc