Randagio13 / countries-states-cities-service

Get the World's countries, states, regions and cities
MIT License
16 stars 5 forks source link
# Countries States Cities Service [![NPM](https://nodei.co/npm/countries-states-cities-service.png?compact=true)](https://nodei.co/npm/countries-states-cities-service/)
[![](https://img.shields.io/npm/dt/countries-states-cities-service.svg?style=flat-square)](https://www.npmjs.com/package/countries-states-cities-service)

Table of contents

  1. Mission
  2. Getting started
  3. Usage
  4. Contributors
  5. Need help
  6. Licence
  7. Sponsor

Mission

Getting started

To get started with this library, you need to install it and add it to your project.

Installation

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

Import single named import as follow:

import { Countries, States, Cities } from 'countries-states-cities-service'

Usage

The code snippet below shows how to put into action countries-states-cities-service in some common use cases.

Countries

const countries = Countries.getCountries()
const countries = Countries.getCountries({
  sort: {
    mode: 'asc',
  },
})
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' } })

States

const states = States.getStates()
const states = States.getStates({
  sort: {
    mode: 'asc',
  },
})
const states = States.getStates({
  sort: {
    mode: 'desc',
  },
})
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',
  },
})

Cities

const cities = Cities.getCities()
const cities = Cities.getCities({
  sort: {
    mode: 'asc',
  },
})
const cities = Cities.getCities({
  sort: {
    mode: 'desc',
  },
})
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
  },
})

Contributors

Any contribution is appreciated. You can get started with the steps below:

  1. Fork this repository (learn how to do this here).

  2. Clone the forked repository.

  3. Make your changes and create a pull request (learn how to do this).

  4. I will attend to your pull request and provide some feedback.

Need help?

Ping me on Twitter

License

This repository is licensed under the MIT License.

Sponsor

Don't be shy! 😜

:heart: Sponsor