Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
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
var countries = require("i18n-iso-countries");
console.log("US (Alpha-2) => " + countries.getName("US", "en")); // United States
console.log("US (Alpha-2) => " + countries.getName("US", "de")); // Vereinigte Staaten von Amerika
console.log("USA (Alpha-3) => " + countries.getName("USA", "en")); // United States
console.log("USA (Numeric) => " + countries.getName("840", "en")); // United States
var countries = require("i18n-iso-countries");
console.log(countries.getNames("en")); // { 'AF': 'Afghanistan', 'AL': 'Albania', [...], 'ZM': 'Zambia', 'ZW': 'Zimbabwe' }
en
: englishde
: germannl
: dutchfr
: frenchsv
: swedishes
: spanishpt
: portuguesefi
: finnishet
: estonianar
: arabicvar countries = require("i18n-iso-countries");
console.log("United States => " + countries.getAlpha2Code('United States', 'en')); // US
var countries = require("i18n-iso-countries");
console.log("USA (Alpha-3) => " + countries.alpha3ToAlpha2("USA") + " (Alpha-2)"); // United States
var countries = require("i18n-iso-countries");
console.log("840 (Numeric) => " + countries.numericToAlpha2("840") + " (Alpha-2)"); // United States
var countries = require("i18n-iso-countries");
console.log("DE (Alpha-2) => " + countries.alpha2ToAlpha3("DE") + " (Alpha-3)"); // Germany
var countries = require("i18n-iso-countries");
console.log("840 (Numeric) => " + countries.numericToAlpha3("840") + " (Alpha-3)"); // United States
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()); // { '4': 'AF', '8': 'AL', [...], '887': 'YE', '894': 'ZM' }
FAQs
i18n for ISO 3166-1 country codes
The npm package i18n-iso-countries receives a total of 558,402 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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.