npm module to associate country codes with country names
JavaScript
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
README.md
countrycode.js
package.json

README.md

This module allows you to find a country's name from its country code, and a country's code from its name.

Installation

npm install countrycode

Usage

var countryCode = require("countrycode");

var myCountry = "Albania";

var myCountrySearch = "alb";

var myCodeSearch = 93;

var myCountrysCode = countryCode.getCode(myCountry);
console.log(myCountrysCode); // Prints 213

var verifyCountryName = countryCode.getCountry(myCountriesCode);
console.log(verifyCountryName);	// Prints "Albania"

var findCountriesLike = countryCode.searchCountry(myCountrySearch);

// Prints [ { country: 'Albania', code: 213 }, { country: 'Svalbard', code: 0 } ]
console.log(findCountriesLike);

var findCodesLike = countryCode.searchCode(myCodeSearch);

// Prints [ { country: 'Afghanistan', code: 93 }, { country: 'Ecuador', code: 593 }, 
//          { country: 'Turkmenistan', code: 993 } ]
console.log(findCodesLike);

Note: Country names are NOT case sensitive