![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
i18n-iso-countries
Advanced tools
The i18n-iso-countries npm package provides functionalities for working with ISO 3166-1 country codes. It allows you to get country names in different languages, convert between different country code formats, and validate country codes.
Get Country Name by Alpha-2 Code
This feature allows you to get the name of a country given its Alpha-2 code. You can specify the language in which you want the country name.
const countries = require('i18n-iso-countries');
countries.registerLocale(require('i18n-iso-countries/langs/en.json'));
const countryName = countries.getName('US', 'en');
console.log(countryName); // Output: United States
Get Alpha-2 Code by Country Name
This feature allows you to get the Alpha-2 code of a country given its name. You can specify the language in which the country name is provided.
const countries = require('i18n-iso-countries');
countries.registerLocale(require('i18n-iso-countries/langs/en.json'));
const countryCode = countries.getAlpha2Code('United States', 'en');
console.log(countryCode); // Output: US
Validate Country Code
This feature allows you to validate whether a given country code is a valid ISO 3166-1 Alpha-2 code.
const countries = require('i18n-iso-countries');
const isValid = countries.isValid('US');
console.log(isValid); // Output: true
Get Country Names in All Languages
This feature allows you to get the names of all countries in a specified language.
const countries = require('i18n-iso-countries');
countries.registerLocale(require('i18n-iso-countries/langs/en.json'));
countries.registerLocale(require('i18n-iso-countries/langs/fr.json'));
const countryNames = countries.getNames('en');
console.log(countryNames); // Output: { 'AF': 'Afghanistan', 'AX': 'Åland Islands', ... }
The country-list package provides a list of country names and their corresponding ISO 3166-1 Alpha-2 codes. It is simpler and more lightweight compared to i18n-iso-countries, but it does not support multiple languages or validation of country codes.
The iso-3166-1 package provides ISO 3166-1 country codes and names. It is similar to i18n-iso-countries but does not offer as extensive support for multiple languages and lacks some of the additional functionalities like validation.
The countries-list package provides a comprehensive list of countries with their ISO 3166-1 codes, names, and additional information like currency and phone codes. It offers more detailed information compared to i18n-iso-countries but may be overkill if you only need basic country code and name functionalities.
i18n for ISO 3166-1 country codes. We support Alpha-2, Alpha-3 and Numeric codes from http://en.wikipedia.org/wiki/ISO_3166-1#Officially_assigned_code_elements
Install it using npm: npm install i18n-iso-countries
var countries = require("i18n-iso-countries");
// Support french & english languages.
countries.registerLocale(require("i18n-iso-countries/langs/en.json"));
countries.registerLocale(require("i18n-iso-countries/langs/fr.json"));
var countries = require("i18n-iso-countries");
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
var countries = require("i18n-iso-countries");
console.log(countries.getNames("en")); // { 'AF': 'Afghanistan', 'AL': 'Albania', [...], 'ZM': 'Zambia', 'ZW': 'Zimbabwe' }
ar
: Arabicaz
: Azerbaijanibe
: Belorussianbg
: Bulgarianbs
: Bosnianca
: Catalancs
: Czechda
: Danishde
: Germanen
: Englishes
: Spanishet
: Estonianfa
: Persianfi
: Finnishfr
: Frenchel
: Greekhe
: Hebrewhr
: Croatianhu
: Hungarianhy
: Armenianit
: Italianid
: Indonesianja
: Japaneseka
: Georgiankk
: Kazakhko
: Koreanky
: Kyrgyzlt
: Lithuanianlv
: Latvianmk
: Macedonianmn
: Mongoliannb
: Norwegian Bokmålnl
: Dutchnn
: Norwegian Nynorskpl
: Polishpt
: Portuguesero
: Romanianru
: Russiansk
: Slovaksl
: Slovenesr
: Serbiansv
: Swedishtr
: Turkishuk
: Ukrainianuz
: Uzbekzh
: Chinesevar countries = require("i18n-iso-countries");
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
var countries = require("i18n-iso-countries");
console.log("USA (Alpha-3) => " + countries.alpha3ToAlpha2("USA") + " (Alpha-2)");
// USA (Alpha-3) => US (Alpha-2)
var countries = require("i18n-iso-countries");
console.log("840 (Numeric) => " + countries.numericToAlpha2("840") + " (Alpha-2)");
// 840 (Numeric) => US (Alpha-2)
var countries = require("i18n-iso-countries");
console.log("DE (Alpha-2) => " + countries.alpha2ToAlpha3("DE") + " (Alpha-3)");
// DE (Alpha-2) => DEU (Alpha-3)
var countries = require("i18n-iso-countries");
console.log("840 (Numeric) => " + countries.numericToAlpha3("840") + " (Alpha-3)");
// 840 (Numeric) => USA (Alpha-3)
var countries = require("i18n-iso-countries");
console.log(countries.alpha3ToNumeric("SWE"));
// 752
var countries = require("i18n-iso-countries");
console.log(countries.alpha2ToNumeric("SE"));
// 752
var countries = require("i18n-iso-countries");
console.log(countries.getAlpha2Codes());
// { 'AF': 'AFG', 'AX': 'ALA', [...], 'ZM': 'ZMB', 'ZW': 'ZWE' }
var countries = require("i18n-iso-countries");
console.log(countries.getAlpha3Codes());
// { 'AFG': 'AF', 'ALA': 'AX', [...], 'ZMB': 'ZM', 'ZWE': 'ZW' }
var countries = require("i18n-iso-countries");
console.log(countries.getNumericCodes());
// { '004': 'AF', '008': 'AL', [...], '887': 'YE', '894': 'ZM' }
var countries = require("i18n-iso-countries");
console.log(countries.isValid("US"), countries.isValid("USA"), countries.isValid("XX")));
// true, true, false
To add a language:
data
object in enty-node.js at the topnpm install && make test
to make sure that tests are passingFAQs
i18n for ISO 3166-1 country codes
The npm package i18n-iso-countries receives a total of 400,975 weekly downloads. As such, i18n-iso-countries popularity was classified as popular.
We found that i18n-iso-countries demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.