country-currency-map
Mapping of countries and their primary currency along with currency data.
Installation
npm install country-currency-map
Usage
Get country data from country name
var getCountry = getCountry;; //=> { abbreviation: 'US', currency: 'USD' }; //=> { abbreviation: 'CA', currency: 'CAD' }
Get currency data from currency abbreviation
var getCurrency = getCurrency;; //=> { name: 'U.S. Dollar (USD)', symbolFormat: '${#}' }; //=> { name: 'Canadian Dollar (CAD)', symbolFormat: 'C${#}' }
Get currency abbreviation from a country name
var getCurrencyAbbreviation = getCurrencyAbbreviation;; //=> 'USD'; //=> 'CAD'
Format currency
var formatCurrency = formatCurrency;; //=> '$100,000'; //=> '€100,000'
Format Locale Currency
This function takes a number and currency abbreviation then returns back the currency string based on the country locale (checks navigator language and defaults to EN). If toLocaleString options are not supported or the value passed is not a number, it will fallback to formatCurrency. Note, NodeJS only support EN locale out of the box. If you need support for other locales please see: https://www.npmjs.com/package/intl
var formatLocaleCurrency = formatLocaleCurrency;; // US locale => '$100.000; // FR locale => '€3 000,20
There's a third boolean parameter for additional options:
autoFixed
- defaults to true, if value >= 1000 then will set fixed precision to 0locale
- set locale to override navigator settingsabbreviate
- default to false, if true will abbreviate the numerical value. Currently this only supports numbers into the trillions.
var formatLocaleCurrency = formatLocaleCurrency;; // => $100k; // => €3k; // => €3k; // => $3,000.20
Get Currency List
var getCurrencyList = getCurrencyList;; //=> [ { abbr: "AFA", name: "Afghanistan Afghani (AFA)", symbolFormat: "AFA {#}" }, { abbr: "ALL", name: "Albanian Lek (ALL)", symbolFormat:, "ALL {#}" }, ... ]
Get Currency Abbreviation From Name
var getCurrencyAbbreviationFromName = getCurrencyAbbreviationFromName;; //=> 'USD'
Get Country by Country Abbreviation
var getCountryByAbbreviation = getCountryByAbbreviation;; //=> 'United States'