node package manager

Introducing npm Enterprise add-ons. Integrate third-party dev tools into npm…

i18n-iso-countries

i18n for ISO 3166-1 country codes

i18n-iso-countries

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' } 
  • ar: arabic
  • de: german
  • en: english
  • es: spanish
  • et: estonian
  • fi: finnish
  • fr: french
  • nb: Norwegian Bokmål
  • nl: dutch
  • nn: Norwegian Nynorsk
  • pt: portuguese
  • sv: swedish
  • tr: turkish
var countries = require("i18n-iso-countries");
console.log("United States => " + countries.getAlpha2Code('United States', 'en'));
// United States => US 
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' } 

To add a language:

  • add a json file under langs/
  • add the language to the data object in index.js at the top
  • add language to section Supported languages in README.md
  • add language to keywords in package.json
  • run npm install && make test to make sure that tests are passing
  • open a PR on GitHub