Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/anupkumarpanwar/country-state-picker
NPM package to get the list of countries, states and dial codes.
https://github.com/anupkumarpanwar/country-state-picker
countries country-state-picker dial-code npm phone-code picker state
Last synced: 7 days ago
JSON representation
NPM package to get the list of countries, states and dial codes.
- Host: GitHub
- URL: https://github.com/anupkumarpanwar/country-state-picker
- Owner: AnupKumarPanwar
- Created: 2019-08-14T06:40:38.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-06-16T22:01:31.000Z (6 months ago)
- Last Synced: 2024-12-15T03:49:34.072Z (10 days ago)
- Topics: countries, country-state-picker, dial-code, npm, phone-code, picker, state
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/country-state-picker
- Size: 9.68 MB
- Stars: 10
- Watchers: 1
- Forks: 16
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Country State Picker
NPM package to get the list of countries and their states.
[![npm version](https://badge.fury.io/js/country-state-picker.svg)](https://badge.fury.io/js/country-state-picker)
## Installation
`npm i country-state-picker --save`
## Usage
### `getCountries()`
This function will return the array of all the countries.
#### Output
```javascript
[
{
"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()`
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:
```javascript
let states = getStates('in');console.log(states)
```#### Output
```javascript
[
"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()`
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:
```javascript
let country = getCountry('+91');console.log(country)
```#### Output
```javascript
{
"name": "India",
"code": "in",
"dial_code": "+91"
}
```### `getFilteredCountries([])`
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:
```javascript
let filteredCountries = getFilteredCountries(['+91', 'us', 'Australia']);console.log(filteredCountries)
```#### Output
```javascript
[
{
"name": "India",
"code": "in",
"dial_code": "+91"
},
{
"name": "United States of America",
"code": "us",
"dial_code": "+1"
},
{
"name": "Australia",
"code": "au",
"dial_code": "+61"
}
]
```