Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2 #24

Merged
merged 3 commits into from
Oct 4, 2019
Merged

V2 #24

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
"presets": ["es2015", "stage-1"]
"presets": ["@babel/preset-env"],
"plugins": [
"@babel/plugin-proposal-class-properties",
"@babel/plugin-proposal-export-default-from"
]
}
59 changes: 42 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,48 +11,73 @@ Mapping of countries and their primary currency along with currency data.
### Get country data from country name

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

```js
var getCurrency = require('country-currency-map').getCurrency;
getCurrency('USD'); //=> { name: 'U.S. Dollar (USD)', symbolFormat: '${#}' }
getCurrency('CAD'); //=> { name: 'Canadian Dollar (CAD)', symbolFormat: 'C${#}' }
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

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

### Format currency

```js
var formatCurrency = require('country-currency-map').formatCurrency;
formatCurrency('100,000', 'USD'); //=> '$100,000'
formatCurrency('100,000', 'EUR'); //=> '€100,000'
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, currency abbreviation and country abbrevation and returns back the currency string based on the country locale. 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

```js
var formatLocaleCurrency = require("country-currency-map").formatLocaleCurrency;
formatLocaleCurrency(100000.5, "USD", "ES"); // => '$100.000,50
formatLocaleCurrency(3000.2, "EUR", "FR"); // => '€3 000,20
```

There's a fourth boolean parameter to enable abbreviation of the numerical value. Currently this only supports numbers in the trillions.

```js
var formatLocaleCurrency = require("country-currency-map").formatLocaleCurrency;
formatLocaleCurrency(100000.5, "USD", "ES", true); // => '$100k
formatLocaleCurrency(3000.2, "EUR", "FR", true); // => '€3k
```

### Get Currency List

```js
var getCurrencyList = require('country-currency-map').getCurrencyList;
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

```js
var getCurrencyAbbreviationFromName = require('country-currency-map').getCurrencyAbbreviationFromName;
getCurrencyAbbreviationFromName('U.S. Dollar (USD)'); //=> 'USD'
var getCurrencyAbbreviationFromName = require("country-currency-map")
.getCurrencyAbbreviationFromName;
getCurrencyAbbreviationFromName("U.S. Dollar (USD)"); //=> 'USD'
```

### Get Country by Country Abbreviation

```js
var getCountryByAbbreviation = require('country-currency-map').getCountryByAbbreviation;
getCountryByAbbreviation('US'); //=> 'United States'
var getCountryByAbbreviation = require("country-currency-map")
.getCountryByAbbreviation;
getCountryByAbbreviation("US"); //=> 'United States'
```
77 changes: 0 additions & 77 deletions country-currency-map.js

This file was deleted.

Loading