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-currency-map

v2.1.7

Published

Mapping of countries and their primary currency.

Downloads

22,123

Readme

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 = require("country-currency-map").getCountry;
getCountry("United States"); //=> { abbreviation: 'US', currency: 'USD' }
getCountry("Canada"); //=> { abbreviation: 'CA', currency: 'CAD' }

Get currency data from currency abbreviation

var getCurrency = require("country-currency-map").getCurrency;
getCurrency("USD"); //=> { name: 'U.S. Dollar (USD)', symbolFormat: '${#}' }
getCurrency("CAD"); //=> { name: 'Canadian Dollar (CAD)', symbolFormat: 'C${#}' }

Get currency abbreviation from a country name

var getCurrencyAbbreviation = require("country-currency-map")
  .getCurrencyAbbreviation;
getCurrencyAbbreviation("United States"); //=> 'USD'
getCurrencyAbbreviation("Canada"); //=> 'CAD'

Format currency

var formatCurrency = require("country-currency-map").formatCurrency;
formatCurrency("100,000", "USD"); //=> '$100,000'
formatCurrency("100,000", "EUR"); //=> '€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 = require("country-currency-map").formatLocaleCurrency;
formatLocaleCurrency(100000.5, "USD"); // US locale => '$100.000
formatLocaleCurrency(3000.2, "EUR"); // FR locale => '€3 000,20

There's a third boolean parameter for additional options:

  1. autoFixed - defaults to true, if value >= 1000 then will set fixed precision to 0
  2. locale - set locale to override navigator settings
  3. abbreviate - default to false, if true will abbreviate the numerical value. Currently this only supports numbers into the trillions.
var formatLocaleCurrency = require("country-currency-map").formatLocaleCurrency;
formatLocaleCurrency(100000.5, "USD", { abbreviate: true }); // => $100k
formatLocaleCurrency(3000.2, "EUR", { abbreviate: true }); // => €3k
formatLocaleCurrency(3000.2, "EUR", { abbreviate: true }); // => €3k
formatLocaleCurrency(3000.2, "USD", { autoFixed: false }); // => $3,000.20

Get Currency List

var getCurrencyList = require("country-currency-map").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 = require("country-currency-map")
  .getCurrencyAbbreviationFromName;
getCurrencyAbbreviationFromName("U.S. Dollar (USD)"); //=> 'USD'

Get Country by Country Abbreviation

var getCountryByAbbreviation = require("country-currency-map")
  .getCountryByAbbreviation;
getCountryByAbbreviation("US"); //=> 'United States'