Security News
Highlights from the 2024 Rails Community Survey
A record 2,709 developers participated in the 2024 Ruby on Rails Community Survey, revealing key tools, practices, and trends shaping the Rails ecosystem.
country-locale-map
Advanced tools
Provides mapping between country codes and provides default country locales. Includes optional fuzzy matching for country name.
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
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
clm.getAlpha3ByAlpha2('CA'); //returns 'CAN'
clm.getLocaleByAlpha2('CA'); //returns 'en_CA'
clm.getCountryNameByAlpha2('CA'); //returns 'Canada'
clm.getNumericByAlpha2('CA'); //returns '124'
clm.getCurrencyByAlpha2('CA'); //returns 'CAD'
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"
}
*/
clm.getAlpha3ByAlpha2('CAN'); //returns 'CA'
clm.getLocaleByAlpha3('CAN'); //returns 'en_CA'
clm.getCountryNameByAlpha3('CAN'); //returns 'Canada'
clm.getNumericByAlpha3('CAN'); //returns '124'
clm.getCurrencyByAlpha3('CAN'); //returns 'CAD'
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"
}
*/
clm.getAlpha2ByNumeric('123'); //returns 'CA'
clm.getAlpha3ByNumeric('124'); //returns 'CAN'
clm.getLocaleByNumeric('124'); //returns 'en_CA'
clm.getCountryNameByNumeric('124'); //returns 'Canada'
clm.getCurrencyByNumeric('124'); //returns 'CAD'
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"
}
*/
clm.getAlpha2ByName('Canada'); //returns 'CA'
clm.getAlpha3ByName('Canada'); //returns 'CAN'
clm.getLocaleByName('Canada'); //returns 'en_CA'
clm.getNumericByName('Canada'); //returns '124'
clm.getCurrencyByName('Canada'); //returns 'CAD'
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"
}
*/
clm.getAllCountries();
/*returns
the list of all countries
*/
FAQs
Provides mapping between country codes and provides default country locales. Includes optional fuzzy matching for country name.
The npm package country-locale-map receives a total of 42,503 weekly downloads. As such, country-locale-map popularity was classified as popular.
We found that country-locale-map demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer 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
A record 2,709 developers participated in the 2024 Ruby on Rails Community Survey, revealing key tools, practices, and trends shaping the Rails ecosystem.
Security News
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.