To get started with this library, you need to install it and add it to your project.
Countries States Cities Service is available as an npm package.
# npm
npm install countries-states-cities-service
# yarn
yarn add countries-states-cities-service
Import single named import as follow:
import { Countries, States, Cities } from 'countries-states-cities-service'
The code snippet below shows how to put into action countries-states-cities-service
in some common use cases.
const countries = Countries.getCountries()
asc
sort.const countries = Countries.getCountries({
sort: {
mode: 'asc',
},
})
desc
sort.const countries = Countries.getCountries({
sort: {
mode: 'desc',
},
})
const countries = Countries.getCountries({
sort: {
mode: 'alphabetical',
key: 'iso2',
},
})
const countries = Countries.getCountries({ locale: 'it' })
const countries = Countries.getCountries({ filters: { iso2: 'US' } })
const countries = Countries.getCountries({
filters: { iso2: 'IT' },
locale: 'it',
})
const countries = Countries.getCountries({ filters: { iso3: 'ITA' } })
const states = States.getStates()
asc
sort.const states = States.getStates({
sort: {
mode: 'asc',
},
})
desc
sort.const states = States.getStates({
sort: {
mode: 'desc',
},
})
alphabetical
sort.const states = States.getStates({
sort: {
mode: 'alphabetical',
key: 'name',
},
})
const states = States.getStates({ locale: 'it' })
const states = States.getStates({ filters: { country_code: 'IT' } })
const states = States.getStates({
filters: { country_code: 'IT' },
locale: 'it',
})
const states = States.getStates({
filters: {
country_code: 'IT',
is_region: true,
},
})
const states = States.getStates({
filters: {
country_code: 'IT',
state_code: 'GE',
},
})
const cities = Cities.getCities()
asc
sort.const cities = Cities.getCities({
sort: {
mode: 'asc',
},
})
desc
sort.const cities = Cities.getCities({
sort: {
mode: 'desc',
},
})
alphabetical
sort.const cities = Cities.getCities({
sort: {
mode: 'alphabetical',
key: 'name',
},
})
const cities = Cities.getCities({
filters: {
country_code: 'IT',
},
})
const cities = Cities.getCities({
filters: {
country_code: 'IT',
state_code: '42', // Region iso2
},
})
Any contribution is appreciated. You can get started with the steps below:
Fork this repository (learn how to do this here).
Clone the forked repository.
Make your changes and create a pull request (learn how to do this).
I will attend to your pull request and provide some feedback.
Ping me on Twitter
This repository is licensed under the MIT License.
Don't be shy! 😜