i18n-iso-countries vs country-list vs countries-list vs country-code-lookup vs country-data
Country Data Libraries Comparison
1 Year
i18n-iso-countriescountry-listcountries-listcountry-code-lookupcountry-dataSimilar Packages:
What's Country Data Libraries?

These libraries provide various functionalities for handling country-related data, including country names, codes, and additional metadata. They are essential for applications that require geographical information, localization, and internationalization. Each library has its unique features and use cases, making them suitable for different scenarios in web development.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
i18n-iso-countries813,199848624 kB474 months agoMIT
country-list321,26927316.6 kB6-MIT
countries-list264,9911,242272 kB1710 months agoMIT
country-code-lookup110,2168860.7 kB6a year agoMIT
country-data62,453516-359 years agoMIT
Feature Comparison: i18n-iso-countries vs country-list vs countries-list vs country-code-lookup vs country-data

Data Coverage

  • i18n-iso-countries:

    I18n-iso-countries specializes in providing localized country names in various languages. It is particularly useful for applications that need to display country names based on the user's language preference.

  • country-list:

    Country-list provides a simple list of country names paired with their ISO codes. It is straightforward and does not include additional metadata, making it suitable for applications that only require basic country identification.

  • countries-list:

    Countries-list provides a comprehensive dataset that includes country names, ISO 3166-1 alpha-2 and alpha-3 codes, currencies, and calling codes. It covers all recognized countries and territories, making it suitable for applications needing extensive geographical data.

  • country-code-lookup:

    Country-code-lookup focuses on providing a quick reference for country codes and names. It includes a limited dataset primarily aimed at fast lookups, which may not be suitable for applications needing detailed country information.

  • country-data:

    Country-data offers a rich dataset that includes country names, ISO codes, languages, currencies, and region information. It is ideal for applications that require detailed country profiles and extensive metadata for each country.

Localization Support

  • i18n-iso-countries:

    I18n-iso-countries excels in localization, providing country names in multiple languages. This makes it the best choice for applications that need to cater to a global audience with varying language preferences.

  • country-list:

    Country-list does not support localization and is designed for applications that only need country names and ISO codes without any localization features.

  • countries-list:

    Countries-list does not provide localization support directly but can be used alongside other libraries to implement localization features in your application.

  • country-code-lookup:

    Country-code-lookup lacks built-in localization support, focusing instead on quick access to country codes and names without additional features.

  • country-data:

    Country-data includes some localization features, particularly in terms of languages spoken in each country, making it useful for applications that require basic localization.

Ease of Use

  • i18n-iso-countries:

    I18n-iso-countries is easy to use, especially for developers familiar with localization practices. Its API is intuitive for retrieving localized country names.

  • country-list:

    Country-list is extremely straightforward, providing a simple API for accessing country names and codes, making it ideal for beginners.

  • countries-list:

    Countries-list is user-friendly and easy to integrate into applications. Its structure allows developers to quickly access the necessary data without complex configurations.

  • country-code-lookup:

    Country-code-lookup is designed for simplicity and speed, making it easy to implement for quick lookups without additional overhead.

  • country-data:

    Country-data is slightly more complex due to its extensive dataset, but it is still manageable for developers familiar with handling larger data structures.

Performance

  • i18n-iso-countries:

    I18n-iso-countries performs well in retrieving localized names, but performance may vary depending on the number of languages supported in the application.

  • country-list:

    Country-list is highly performant due to its simplicity, providing quick access to country names and codes without additional processing.

  • countries-list:

    Countries-list is optimized for performance, allowing for quick access to country data without significant overhead, making it suitable for high-performance applications.

  • country-code-lookup:

    Country-code-lookup is lightweight and designed for fast lookups, ensuring minimal performance impact when retrieving country information.

  • country-data:

    Country-data may have a larger footprint due to its extensive dataset, but it is still efficient for most applications that require detailed country information.

Community and Maintenance

  • i18n-iso-countries:

    I18n-iso-countries has a vibrant community and is regularly updated, making it a reliable choice for applications needing localized country names.

  • country-list:

    Country-list is maintained but may not receive frequent updates, making it suitable for applications that do not require constant changes to country data.

  • countries-list:

    Countries-list has a strong community and is actively maintained, ensuring that the data remains up-to-date and reliable for developers.

  • country-code-lookup:

    Country-code-lookup is less frequently updated but still maintained, making it a stable choice for applications that do not require frequent changes.

  • country-data:

    Country-data is well-maintained with regular updates, ensuring that the dataset remains relevant and accurate for developers.

How to Choose: i18n-iso-countries vs country-list vs countries-list vs country-code-lookup vs country-data
  • i18n-iso-countries:

    Choose i18n-iso-countries if you require localized country names in multiple languages. This library is particularly useful for international applications that need to display country names based on the user's locale.

  • country-list:

    Use country-list for a simple and straightforward list of country names and their ISO codes. This package is perfect for basic applications that need to display country names without extra data or complexity.

  • countries-list:

    Choose countries-list if you need a comprehensive list of countries with their ISO codes and additional information like currency and calling codes. It is well-structured and easy to use for applications that require extensive country data.

  • country-code-lookup:

    Select country-code-lookup if your primary need is to quickly retrieve country information based on ISO codes. This package is lightweight and efficient for applications that require fast lookups without additional metadata.

  • country-data:

    Opt for country-data if you need a rich dataset that includes not only country names and codes but also languages, currencies, and region information. It is ideal for applications that require detailed country profiles and localization support.

README for i18n-iso-countries

i18n-iso-countries

i18n for ISO 3166-1 country codes. We support Alpha-2, Alpha-3 and Numeric codes from 'Wikipedia: Officially assigned code elements'

Installing

Install it using npm: npm install i18n-iso-countries

var countries = require("i18n-iso-countries");

If you use i18n-iso-countries with Node.js, you are done. If you use the package in a browser environment, you have to register the languages you want to use to minimize the file size.

// Support french & english languages.
countries.registerLocale(require("i18n-iso-countries/langs/en.json"));
countries.registerLocale(require("i18n-iso-countries/langs/fr.json"));

Code to Country

Get the name of a country by its ISO 3166-1 Alpha-2, Alpha-3 or Numeric code

var countries = require("i18n-iso-countries");
// in a browser environment: countries.registerLocale(require("i18n-iso-countries/langs/en.json"));
console.log("US (Alpha-2) => " + countries.getName("US", "en")); // United States of America
console.log("US (Alpha-2) => " + countries.getName("US", "de")); // Vereinigte Staaten von Amerika
console.log("USA (Alpha-3) => " + countries.getName("USA", "en")); // United States of America
console.log("USA (Numeric) => " + countries.getName("840", "en")); // United States of America

Get aliases/short name using select

// Some countries have alias/short names defined. `select` is used to control which
// name will be returned.
console.log("GB (select: official) => " + countries.getName("GB", "en", {select: "official"})); // United Kingdom
console.log("GB (select: alias) => " + countries.getName("GB", "en", {select: "alias"})); // UK
console.log("GB (select: all) => " + countries.getName("GB", "en", {select: "all"})); // ["United Kingdom", "UK", "Great Britain"]
// Countries without an alias will always return the offical name
console.log("LT (select: official) => " + countries.getName("LT", "en", {select: "official"})); // Lithuania
console.log("LT (select: alias) => " + countries.getName("LT", "en", {select: "alias"})); // Lithuania
console.log("LT (select: all) => " + countries.getName("LT", "en", {select: "all"})); // ["Lithuania"]

Get all names by their ISO 3166-1 Alpha-2 code

var countries = require("i18n-iso-countries");
// in a browser environment: countries.registerLocale(require("i18n-iso-countries/langs/en.json"));
console.log(countries.getNames("en", {select: "official"})); // { 'AF': 'Afghanistan', 'AL': 'Albania', [...], 'ZM': 'Zambia', 'ZW': 'Zimbabwe' }

Supported languages (ISO 639-1)

In case you want to add new language, please refer ISO 639-1 table.

  • af: Afrikaans
  • am: Amharic
  • ar: Arabic
  • az: Azerbaijani
  • be: Belorussian
  • bg: Bulgarian
  • bn: Bengali
  • br: Breton
  • bs: Bosnian
  • ca: Catalan
  • cs: Czech
  • cy: Cymraeg
  • da: Danish
  • de: German
  • dv: Dhivehi
  • en: English
  • es: Spanish
  • et: Estonian
  • eu: Basque
  • fa: Persian
  • fi: Finnish
  • fr: French
  • ga: Irish
  • gl: Galician
  • el: Greek
  • ha: Hausa
  • he: Hebrew
  • hi: Hindi
  • hr: Croatian
  • hu: Hungarian
  • hy: Armenian
  • is: Icelandic
  • it: Italian
  • id: Indonesian
  • ja: Japanese
  • ka: Georgian
  • kk: Kazakh
  • km: Khmer
  • ko: Korean
  • ku: Kurdish
  • ky: Kyrgyz
  • lt: Lithuanian
  • lv: Latvian
  • mk: Macedonian
  • ml: Malayalam
  • mn: Mongolian
  • mr: Marathi
  • ms: Malay
  • mt: Maltese
  • nb: Norwegian Bokmål
  • nl: Dutch
  • nn: Norwegian Nynorsk
  • no: Norwegian
  • pl: Polish
  • ps: Pashto
  • pt: Portuguese
  • ro: Romanian
  • ru: Russian
  • sd: Sindhi
  • sk: Slovak
  • sl: Slovene
  • so: Somali
  • sq: Albanian
  • sr: Serbian
  • sv: Swedish
  • sw: Swahili
  • ta: Tamil
  • tg: Tajik
  • th: Thai
  • tk: Turkmen
  • tr: Turkish
  • tt: Tatar
  • ug: Uyghur
  • uk: Ukrainian
  • ur: Urdu
  • uz: Uzbek
  • zh: Chinese
  • vi: Vietnamese

List of ISO 639-1 codes

Get all supported languages (ISO 639-1)

var countries = require("i18n-iso-countries");
console.log("List of supported languages => " + countries.getSupportedLanguages());
// List of supported languages => ["cy", "dv", "sw", "eu", "af", "am", ...]

Country to Code

var countries = require("i18n-iso-countries");
// in a browser environment: countries.registerLocale(require("i18n-iso-countries/langs/en.json"));
console.log("United States of America => " + countries.getAlpha2Code("United States of America", "en"));
// United States of America => US

console.log("United States of America => " + countries.getAlpha3Code("United States of America", "en"));
// United States of America => USA

Codes

Convert Alpha-3 to Alpha-2 code

var countries = require("i18n-iso-countries");
// in a browser environment: countries.registerLocale(require("i18n-iso-countries/langs/en.json"));
console.log("USA (Alpha-3) => " + countries.alpha3ToAlpha2("USA") + " (Alpha-2)");
// USA (Alpha-3) => US (Alpha-2)

Convert Numeric to Alpha-2 code

var countries = require("i18n-iso-countries");
// in a browser environment: countries.registerLocale(require("i18n-iso-countries/langs/en.json"));
console.log("840 (Numeric) => " + countries.numericToAlpha2("840") + " (Alpha-2)");
// 840 (Numeric) => US (Alpha-2)

Convert Alpha-2 to Alpha-3 code

var countries = require("i18n-iso-countries");
// in a browser environment: countries.registerLocale(require("i18n-iso-countries/langs/en.json"));
console.log("DE (Alpha-2) => " + countries.alpha2ToAlpha3("DE") + " (Alpha-3)");
// DE (Alpha-2) => DEU (Alpha-3)

Convert Numeric to Alpha-3 code

var countries = require("i18n-iso-countries");
// in a browser environment: countries.registerLocale(require("i18n-iso-countries/langs/en.json"));
console.log("840 (Numeric) => " + countries.numericToAlpha3("840") + " (Alpha-3)");
// 840 (Numeric) => USA (Alpha-3)

Convert Alpha-3 to Numeric code

var countries = require("i18n-iso-countries");
// in a browser environment: countries.registerLocale(require("i18n-iso-countries/langs/en.json"));
console.log(countries.alpha3ToNumeric("SWE"));
// 752

Convert Alpha-2 to Numeric code

var countries = require("i18n-iso-countries");
// in a browser environment: countries.registerLocale(require("i18n-iso-countries/langs/en.json"));
console.log(countries.alpha2ToNumeric("SE"));
// 752

Get all Alpha-2 codes

var countries = require("i18n-iso-countries");
// in a browser environment: countries.registerLocale(require("i18n-iso-countries/langs/en.json"));
console.log(countries.getAlpha2Codes());
// { 'AF': 'AFG', 'AX': 'ALA', [...], 'ZM': 'ZMB', 'ZW': 'ZWE' }

Get all Alpha-3 codes

var countries = require("i18n-iso-countries");
// in a browser environment: countries.registerLocale(require("i18n-iso-countries/langs/en.json"));
console.log(countries.getAlpha3Codes());
// { 'AFG': 'AF', 'ALA': 'AX', [...], 'ZMB': 'ZM', 'ZWE': 'ZW' }

Get all Numeric codes

var countries = require("i18n-iso-countries");
// in a browser environment: countries.registerLocale(require("i18n-iso-countries/langs/en.json"));
console.log(countries.getNumericCodes());
// { '004': 'AF', '008': 'AL', [...], '887': 'YE', '894': 'ZM' }

Validate country code

var countries = require("i18n-iso-countries");
// in a browser environment: countries.registerLocale(require("i18n-iso-countries/langs/en.json"));
console.log(
  countries.isValid("US"),
  countries.isValid("USA"),
  countries.isValid("XX")
);
// true, true, false

Contribution

To add a language:

  • add a json file under langs/
  • add the language to the list in supportedLocales.json at the top
  • add language to section Supported languages in README.md
  • add language to keywords in package.json
  • run npm run lint and npm test
  • open a PR on GitHub

You can check codes here: https://www.iso.org/obp/ui/#home