A lightweight and efficient package for accessing country and city data. Easily integrate country and city information into your JavaScript or TypeScript applications.
- Retrieve country and city lists
- Get country or city by label
- Optimized, minified JSON data for fast lookups
- TypeScript types included
- Simple, synchronous API
npm install country-city-multilanguage
import { getCountries, getCountryByLabel } from 'country-city-multilanguage';
import { getCities, getCitiesByCountry, getCityByLabel } from 'country-city-multilanguage';
const countries = getCountries();
console.log(countries);
/*
[
{label: "Afghanistan", label_ar: "أفغانستان", label_fr: "Afghanistan"},
{label: "Morocco", label_ar: "المغرب", label_fr:" Maroc"},
// ...
]
*/
const country = getCountryByLabel('Morocco');
console.log(country);
/*
{label: "Morocco", label_ar: "المغرب", label_fr:" Maroc"}
*/
const allCities = getCities();
console.log(allCities);
/*
[
{ country: 'Morocco', cities: [{ "label": "Kenitra", "label_ar": "القنيطرة", "label_fr": "Kenitra" }, ...] },
// ...
]
*/
const citiesInFrance = getCitiesByCountry('Morocco');
console.log(citiesInFrance);
/*
[
{ "label": "Kenitra", "label_ar": "القنيطرة", "label_fr": "Kenitra" },
{ "label": "Mohammedia", "label_ar": "المحمدية", "label_fr": "Mohammedia" },
// ...
]
*/
const city = getCityByLabel('Morocco', 'Kenitra');
console.log(city);
/*
{ "label": "Kenitra", "label_ar": "القنيطرة", "label_fr": "Kenitra" }
*/
Returns an array of country objects.
Returns a country object matching the given label.
Returns an array of all city objects grouped by country.
Returns an array of city objects for the given country label.
Returns a city object matching the given label within the specified country.
Contributions are welcome! Please open an issue or submit a pull request.
MIT License. See LICENSE for details.