npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

country-locale-map

v1.9.4

Published

Provides mapping between country codes and provides default country locales. Includes optional fuzzy matching for country name.

Downloads

239,559

Readme

Country Locale Map Build Status

Provides easy conversion between country codes and names as well as a default locale for each country. Includes fuzzy matching for country name lookups. Methods return undefined if no matches are found

Usage

const clm = require('country-locale-map');
clm.getAlpha3ByAlpha2('CA'); //returns 'CAN' 

If you would like locales to be returned with - instead of_ you can set an environment variable

CLM_MODE='INTL' in a .env file using dotenv just make sure that dotenv is required before requiring the country local map library

Functions

Alpha2

  • getAlpha3ByAlpha2(alpha2)
clm.getAlpha3ByAlpha2('CA'); //returns 'CAN' 
  • getLocaleByAlpha2(alpha2)
clm.getLocaleByAlpha2('CA'); //returns 'en_CA' 
  • getCountryNameByAlpha2(alpha2)
clm.getCountryNameByAlpha2('CA'); //returns 'Canada' 
  • getNumericByAlpha2(alpha2)
clm.getNumericByAlpha2('CA'); //returns '124' 
  • getCurrencyByAlpha2(alpha2)
clm.getCurrencyByAlpha2('CA'); //returns 'CAD' 
  • getCountryByAlpha2(alpha2)
clm.getCountryByAlpha2('CA'); 

/*returns 

    {
        "name":"Canada",
        "alpha2":"CA",
        "alpha3":"CAN",
        "numeric":"124",
        "locales":["en_CA","fr_CA"],
        "default_locale":"en_CA",
        "currency":"CAD",
        "languages":["en","fr"],
        "capital":"Ottawa",
        "emoji":"🇨🇦",
        "emojiU":"U+1F1E8 U+1F1E6",
        "fips":"CA",
        "internet":"CA",
        "continent":"Americas",
        "region":"North America"
    }

*/

Alpha3

  • getAlpha2ByAlpha3(alpha3)
clm.getAlpha3ByAlpha2('CAN'); //returns 'CA' 
  • getLocaleByAlpha3(alpha3)
clm.getLocaleByAlpha3('CAN'); //returns 'en_CA' 
  • getCountryNameByAlpha3(alpha3)
clm.getCountryNameByAlpha3('CAN'); //returns 'Canada' 
  • getNumericByAlpha3(alpha3)
clm.getNumericByAlpha3('CAN'); //returns '124' 
  • getCurrencyByAlpha3(alpha3)
clm.getCurrencyByAlpha3('CAN'); //returns 'CAD' 
  • getCountryByAlpha3(alpha3)
clm.getCountryByAlpha3('CAN');


/*returns 

    {
        "name":"Canada",
        "alpha2":"CA",
        "alpha3":"CAN",
        "numeric":"124",
        "locales":["en_CA","fr_CA"],
        "default_locale":"en_CA",
        "currency":"CAD",
        "languages":["en","fr"],
        "capital":"Ottawa",
        "emoji":"🇨🇦",
        "emojiU":"U+1F1E8 U+1F1E6",
        "fips":"CA",
        "internet":"CA",
        "continent":"Americas",
        "region":"North America"
    }

*/

Numeric

  • getAlpha2ByNumeric(numeric)
clm.getAlpha2ByNumeric('123'); //returns 'CA' 
  • getAlpha3ByNumeric(numeric)
clm.getAlpha3ByNumeric('124'); //returns 'CAN' 
  • getLocaleByNumeric(numeric)
clm.getLocaleByNumeric('124'); //returns 'en_CA' 
  • getCountryNameByNumeric(numeric)
clm.getCountryNameByNumeric('124'); //returns 'Canada' 
  • getCurrencyByNumeric(numeric)
clm.getCurrencyByNumeric('124'); //returns 'CAD' 
  • getCountryByNumeric(numeric)
clm.getCountryByNumeric('124');


/*returns 

    {
        "name":"Canada",
        "alpha2":"CA",
        "alpha3":"CAN",
        "numeric":"124",
        "locales":["en_CA","fr_CA"],
        "default_locale":"en_CA",
        "currency":"CAD",
        "languages":["en","fr"],
        "capital":"Ottawa",
        "emoji":"🇨🇦",
        "emojiU":"U+1F1E8 U+1F1E6",
        "fips":"CA",
        "internet":"CA",
        "continent":"Americas",
        "region":"North America"
    }

*/

Name

  • getAlpha2ByName(country, fuzzy)
clm.getAlpha2ByName('Canada'); //returns 'CA' 
  • getAlpha3ByName(country, fuzzy)
clm.getAlpha3ByName('Canada'); //returns 'CAN' 
  • getLocaleByName(country, fuzzy)
clm.getLocaleByName('Canada'); //returns 'en_CA' 
  • getNumericByName(country, fuzzy)
clm.getNumericByName('Canada'); //returns '124' 
  • getCurrencyByName(country, fuzzy)
clm.getCurrencyByName('Canada'); //returns 'CAD' 
  • getCountryByName(country, fuzzy)
clm.getCountryByName('Canada');

/*returns 

    {
        "name":"Canada",
        "alpha2":"CA",
        "alpha3":"CAN",
        "numeric":"124",
        "locales":["en_CA","fr_CA"],
        "default_locale":"en_CA",
        "currency":"CAD",
        "languages":["en","fr"],
        "capital":"Ottawa",
        "emoji":"🇨🇦",
        "emojiU":"U+1F1E8 U+1F1E6",
        "fips":"CA",
        "internet":"CA",
        "continent":"Americas",
        "region":"North America"
    }

*/

if true is passed for fuzzy these functions will do a fuzzy match if it can't find an exact match eg:

clm.getCountryByName('Candaa', true);

/*returns 

    {
        "name":"Canada",
        "alpha2":"CA",
        "alpha3":"CAN",
        "numeric":"124",
        "locales":["en_CA","fr_CA"],
        "default_locale":"en_CA",
        "currency":"CAD",
        "languages":["en","fr"],
        "capital":"Ottawa",
        "emoji":"🇨🇦",
        "emojiU":"U+1F1E8 U+1F1E6",
        "fips":"CA",
        "internet":"CA",
        "continent":"Americas",
        "region":"North America"
    }

*/
  • getAllCountries()
clm.getAllCountries();

/*returns 
    the list of all countries 
*/