npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

i18n-iso-countries-regions

v1.1.1

Published

i18n for ISO 3166 country and regions

Downloads

162

Readme

i18n-iso-countries-regions

i18n for ISO 3166 country and regions

i18n-iso-countries-regions

This package provides internationalization (i18n) support for ISO standard country and region codes. It allows you to retrieve localized country and region names based on the ISO codes.

Installation

You can install i18n-iso-countries-regions via npm. Open your terminal and run the following command:

npm install i18n-iso-countries-regions


Usage
To use i18n-iso-countries-regions in your project, follow these steps:

1- Require the package in your JavaScript file:

const {
  getAllCountriesName,
  getAllCountriesCallingCode,
  getCallingCodeByCountryCode,
  getCallingCodeByCountryName,
  getRegionsByCountryCode,
  getRegionsByCountryName,
  getCountryInfoByCountryCode
} = require('i18n-iso-countries-regions');


2- Use the provided functions to retrieve country and region information:

getAllCountriesName(language): Returns an array of all countries with their ISO codes and localized names.

const allCountries = getAllCountriesName('en');
console.log(allCountries);
/* Output: [
  { iso: 'AD', name: 'Andorra' },
  { iso: 'AE', name: 'United Arab Emirates' },
  { iso: 'AF', name: 'Afghanistan' },
  { iso: 'AG', name: 'Antigua and Barbuda' },
  // ... 
]

3- getAllCountriesCallingCode(language): Returns an array of all countries with their ISO codes, localized names, and calling codes.

const allCountries = getAllCountriesCallingCode('fr');
console.log(allCountries);
/* Output: [
  { iso: 'AD', name: 'Andorre', callingCode: '376' },
  { iso: 'AE', name: 'Émirats arabes unis', callingCode: '971' },
  { iso: 'AF', name: 'Afghanistan', callingCode: '93' },
  { iso: 'AG', name: 'Antigua-et-Barbuda', callingCode: '1' },
  { iso: 'AI', name: 'Anguilla', callingCode: '1' },
  // ...
]

4-getCallingCodeByCountryCode(isoCode): Returns the calling code for a given ISO country code.

const callingCode = getCallingCodeByCountryCode('US');
console.log(callingCode);
/* Output: "1" (for United States)

5- getCallingCodeByCountryName(countryName): Returns the calling code for a given country name.

const callingCode = getCallingCodeByCountryName('United States');
console.log(callingCode);
/* Output: "1"

6- getRegionsByCountryCode(language, countryCode): Returns an array of regions for a given ISO country code, with their ISO codes and localized names.

const regions = getRegionsByCountryCode('fr', 'TN');
console.log(regions);
/* Output:[
  { iso: '22', name: 'Gouvernorat de Zaghouan' },
  { iso: '11', name: 'Gouvernorat de Tunis' },
  { iso: '72', name: 'Gouvernorat de Tozeur' },
  { iso: '83', name: 'Gouvernorat de Tataouine' },
  { iso: '51', name: 'Gouvernorat de Sousse' },
  // ...
  ]

7- getRegionsByCountryName(language, countryName): Returns an array of regions for a given country name, with their ISO codes and localized names.

const regions = getRegionsByCountryName('fr', 'Andorre');
console.log(regions);
/* Output:[
  { iso: '06', name: 'Sant Julià de Lòria' },
  { iso: '05', name: 'Ordino' },
  { iso: '04', name: 'La Massana' },
  { iso: '03', name: 'Encamp' },
  { iso: '02', name: 'Canillo' },
  { iso: '07', name: 'Andorre-la-Vieille' },
  { iso: '08', name: 'Escaldes-Engordany' }
]

8- Use the provided functions to retrieve country and region information:

getCountryInfoByCountryCode(language, countryCode): Returns an object containing comprehensive information about a country for the specified ISO country code and language

const countryInfo = getCountryInfoByCountryCode('en', 'US');
console.log(countryInfo);
/* Output:
{
  iso: 'US',
  name: 'United States',
  callingCode: '1',
  regions: [
    { iso: 'CA', name: 'California' },
    { iso: 'NY', name: 'New York' },
    // ...
  ]
}



Note :
Customize the language parameter (optional):

By default, the functions accept a language parameter set to 'en' for English. You can pass a different language code to retrieve localized names in different languages.

That's it! You can now use i18n-iso-countries-regions to retrieve localized country and region information in your project.

Please note that this is a simplified example, and you may need to adapt it to your specific use case or provide additional information based on the functionalities your package offers.

### Supported languages

- English (en)
- Russian (ru)
- German (de)
- French (fr)
- Spanish (es)
- Chinese (zh)
- Hindi (hi)
- Portuguese (pt)
- Japanese (ja)
- Arabic (ar)
- Italian (it)
- Hebrew (he)