GithubHelp home page GithubHelp logo

highbreedtech / country-currency-map Goto Github PK

View Code? Open in Web Editor NEW

This project forked from payscale/country-currency-map

0.0 0.0 0.0 1.9 MB

Mapping of countries and their primary currency.

License: Apache License 2.0

JavaScript 100.00%

country-currency-map's Introduction

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'

country-currency-map's People

Contributors

ahaug1289 avatar dependabot[bot] avatar dfenske avatar drumminj avatar fxstrato avatar hypepanda avatar jrskerritt avatar kimpers avatar ncua avatar wardbox avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.