Socket
Socket
Sign inDemoInstall

currency-symbol-map

Package Overview
Dependencies
0
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.1.0 to 4.0.0

28

currency-symbol-map.js

@@ -1,30 +0,10 @@

var currencySymbolMap = require('./map');
var currencySymbolMap = require('./map')
var symbolCurrencyMap = {};
Object.keys(currencySymbolMap).forEach(function (key) {
symbolCurrencyMap[currencySymbolMap[key]] = key
})
function getSymbolFromCurrency(currencyCode) {
module.exports = function getSymbolFromCurrency (currencyCode) {
if (typeof currencyCode !== 'string') return undefined
var code = currencyCode.toUpperCase();
var code = currencyCode.toUpperCase()
if (!currencySymbolMap.hasOwnProperty(code)) return undefined
return currencySymbolMap[code];
return currencySymbolMap[code]
}
function getCurrencyFromSymbol(symbol) {
if (!symbolCurrencyMap.hasOwnProperty(symbol)) return undefined
return symbolCurrencyMap[symbol]
}
function getSymbol(currencyCode) {
if (typeof currencyCode !== 'string') return '?'
var symbol = getSymbolFromCurrency(currencyCode.toUpperCase())
return symbol !== undefined ? symbol : '?'
}
module.exports = getSymbol
module.exports.getSymbolFromCurrency = getSymbolFromCurrency
module.exports.getCurrencyFromSymbol = getCurrencyFromSymbol
module.exports.symbolCurrencyMap = symbolCurrencyMap
module.exports.currencySymbolMap = currencySymbolMap

284

map.js

@@ -1,121 +0,165 @@

module.exports =
{ "ALL": "L"
, "AFN": "؋"
, "ARS": "$"
, "AWG": "ƒ"
, "AUD": "$"
, "AZN": "₼"
, "BSD": "$"
, "BBD": "$"
, "BYR": "p."
, "BZD": "BZ$"
, "BMD": "$"
, "BOB": "Bs."
, "BAM": "KM"
, "BWP": "P"
, "BGN": "лв"
, "BRL": "R$"
, "BND": "$"
, "KHR": "៛"
, "CAD": "$"
, "KYD": "$"
, "CLP": "$"
, "CNY": "¥"
, "COP": "$"
, "CRC": "₡"
, "HRK": "kn"
, "CUP": "₱"
, "CZK": "Kč"
, "DKK": "kr"
, "DOP": "RD$"
, "XCD": "$"
, "EGP": "£"
, "SVC": "$"
, "EEK": "kr"
, "EUR": "€"
, "FKP": "£"
, "FJD": "$"
, "GHC": "₵"
, "GIP": "£"
, "GTQ": "Q"
, "GGP": "£"
, "GYD": "$"
, "HNL": "L"
, "HKD": "$"
, "HUF": "Ft"
, "ISK": "kr"
, "INR": "₹"
, "IDR": "Rp"
, "IRR": "﷼"
, "IMP": "£"
, "ILS": "₪"
, "JMD": "J$"
, "JPY": "¥"
, "JEP": "£"
, "KES": "KSh"
, "KZT": "лв"
, "KPW": "₩"
, "KRW": "₩"
, "KGS": "лв"
, "LAK": "₭"
, "LVL": "Ls"
, "LBP": "£"
, "LRD": "$"
, "LTL": "Lt"
, "MKD": "ден"
, "MYR": "RM"
, "MUR": "₨"
, "MXN": "$"
, "MNT": "₮"
, "MZN": "MT"
, "NAD": "$"
, "NPR": "₨"
, "ANG": "ƒ"
, "NZD": "$"
, "NIO": "C$"
, "NGN": "₦"
, "NOK": "kr"
, "OMR": "﷼"
, "PKR": "₨"
, "PAB": "B/."
, "PYG": "Gs"
, "PEN": "S/."
, "PHP": "₱"
, "PLN": "zł"
, "QAR": "﷼"
, "RON": "lei"
, "RUB": "₽"
, "RMB": "¥"
, "SHP": "£"
, "SAR": "﷼"
, "RSD": "Дин."
, "SCR": "₨"
, "SGD": "$"
, "SBD": "$"
, "SOS": "S"
, "ZAR": "R"
, "LKR": "₨"
, "SEK": "kr"
, "CHF": "CHF"
, "SRD": "$"
, "SYP": "£"
, "TZS": "TSh"
, "TWD": "NT$"
, "THB": "฿"
, "TTD": "TT$"
, "TRY": "₺"
, "TRL": "₤"
, "TVD": "$"
, "UGX": "USh"
, "UAH": "₴"
, "GBP": "£"
, "USD": "$"
, "UYU": "$U"
, "UZS": "лв"
, "VEF": "Bs"
, "VND": "₫"
, "YER": "﷼"
, "ZWD": "Z$"
, "GEL": "₾"
, "KZT": "₸"
module.exports = {
'AED': 'د.إ',
'AFN': '؋',
'ALL': 'L',
'ANG': 'ƒ',
'AOA': 'Kz',
'ARS': '$',
'AUD': '$',
'AWG': 'ƒ',
'AZN': '₼',
'BAM': 'KM',
'BBD': '$',
'BDT': '৳',
'BGN': 'лв',
'BHD': '.د.ب',
'BIF': 'FBu',
'BMD': '$',
'BND': '$',
'BOB': 'Bs.',
'BRL': 'R$',
'BSD': '$',
'BTC': '฿',
'BTN': 'Nu.',
'BWP': 'P',
'BYR': 'p.',
'BZD': 'BZ$',
'CAD': '$',
'CDF': 'FC',
'CHF': 'Fr.',
'CLP': '$',
'CNY': '¥',
'COP': '$',
'CRC': '₡',
'CUC': '$',
'CUP': '₱',
'CVE': '$',
'CZK': 'Kč',
'DJF': 'Fdj',
'DKK': 'kr',
'DOP': 'RD$',
'DZD': 'دج',
'EEK': 'kr',
'EGP': '£',
'ERN': 'Nfk',
'ETB': 'Br',
'EUR': '€',
'FJD': '$',
'FKP': '£',
'GBP': '£',
'GEL': '₾',
'GGP': '£',
'GHC': '₵',
'GHS': 'GH₵',
'GIP': '£',
'GMD': 'D',
'GNF': 'FG',
'GTQ': 'Q',
'GYD': '$',
'HKD': '$',
'HNL': 'L',
'HRK': 'kn',
'HTG': 'G',
'HUF': 'Ft',
'IDR': 'Rp',
'ILS': '₪',
'IMP': '£',
'INR': '₹',
'IQD': 'ع.د',
'IRR': '﷼',
'ISK': 'kr',
'JEP': '£',
'JMD': 'J$',
'JPY': '¥',
'KES': 'KSh',
'KGS': 'лв',
'KHR': '៛',
'KMF': 'CF',
'KPW': '₩',
'KRW': '₩',
'KYD': '$',
'KZT': '₸',
'LAK': '₭',
'LBP': '£',
'LKR': '₨',
'LRD': '$',
'LSL': 'M',
'LTL': 'Lt',
'LVL': 'Ls',
'MAD': 'MAD',
'MDL': 'lei',
'MGA': 'Ar',
'MKD': 'ден',
'MMK': 'K',
'MNT': '₮',
'MOP': 'MOP$',
'MUR': '₨',
'MVR': 'Rf',
'MWK': 'MK',
'MXN': '$',
'MYR': 'RM',
'MZN': 'MT',
'NAD': '$',
'NGN': '₦',
'NIO': 'C$',
'NOK': 'kr',
'NPR': '₨',
'NZD': '$',
'OMR': '﷼',
'PAB': 'B/.',
'PEN': 'S/.',
'PGK': 'K',
'PHP': '₱',
'PKR': '₨',
'PLN': 'zł',
'PYG': 'Gs',
'QAR': '﷼',
'RMB': '¥',
'RON': 'lei',
'RSD': 'Дин.',
'RUB': '₽',
'RWF': 'R₣',
'SAR': '﷼',
'SBD': '$',
'SCR': '₨',
'SDG': 'ج.س.',
'SEK': 'kr',
'SGD': '$',
'SHP': '£',
'SLL': 'Le',
'SOS': 'S',
'SRD': '$',
'SSP': '£',
'STD': 'Db',
'SVC': '$',
'SYP': '£',
'SZL': 'E',
'THB': '฿',
'TJS': 'SM',
'TMT': 'T',
'TND': 'د.ت',
'TOP': 'T$',
'TRL': '₤',
'TRY': '₺',
'TTD': 'TT$',
'TVD': '$',
'TWD': 'NT$',
'TZS': 'TSh',
'UAH': '₴',
'UGX': 'USh',
'USD': '$',
'UYU': '$U',
'UZS': 'лв',
'VEF': 'Bs',
'VND': '₫',
'VUV': 'VT',
'WST': 'WS$',
'XAF': 'FCFA',
'XBT': 'Ƀ',
'XCD': '$',
'XOF': 'CFA',
'XPF': '₣',
'YER': '﷼',
'ZAR': 'R',
'ZWD': 'Z$'
}
{
"name": "currency-symbol-map",
"version": "3.1.0",
"version": "4.0.0",
"description": "A function to lookup the currency symbol for a given currency code",
"main": "currency-symbol-map.js",
"scripts": {
"test": "./node_modules/mocha/bin/mocha test.js",
"test:watch": "./node_modules/mocha/bin/mocha test.js --watch"
"test": "standard && tape test.js | tap-spec"
},

@@ -26,5 +25,3 @@ "publishConfig": {

},
"devDependencies": {
"mocha": "^2.4.5"
}
"devDependencies": {}
}
# currency-symbol-map
A function to lookup the currency symbol for a given currency code and vice versa.
A function to lookup the currency symbol for a given currency code.

@@ -13,49 +13,20 @@ ## Installation

```js
var getSymbolFromCurrency = require('currency-symbol-map').getSymbolFromCurrency;
getSymbolFromCurrency('GBP'); //=> '£'
getSymbolFromCurrency('EUR'); //=> '€'
getSymbolFromCurrency('USD'); //=> '$'
getSymbolFromCurrency('NOT A VALID CODE'); //=> undefined
const getSymbolFromCurrency = require('currency-symbol-map')
getSymbolFromCurrency('GBP') //=> '£'
getSymbolFromCurrency('EUR') //=> '€'
getSymbolFromCurrency('USD') //=> '$'
getSymbolFromCurrency('NOT A VALID CODE') //=> undefined
```
### Get currency code from symbol
### Exposed map for other processing
```js
var getCurrencyFromSymbol = require('currency-symbol-map').getCurrencyFromSymbol;
getCurrencyFromSymbol('£'); //=> 'GBP'
getCurrencyFromSymbol('€'); //=> 'EUR'
getCurrencyFromSymbol('$'); //=> 'USD'
getCurrencyFromSymbol('NOT A VALID CODE'); //=> undefined
```
### Exposed maps for other processing
```js
var symbolCurrencyMap = require('currency-symbol-map').symbolCurrencyMap;
/*
const currencySymbolMap = require('currency-symbol-map/map')
// =>
{
"$": "USD",
"£": "GBP",
...
"USD": "$",
"GBP": "£",
}
*/
var currencySymbolMap = require('currency-symbol-map').currencySymbolMap;
/*
{
"USD": "$",
"GBP": "£",
...
}
*/
```
## Shorthand usage
```js
var getSymbol = require('currency-symbol-map')
getSymbol('GBP') //=> '£'
getSymbol('EUR') //=> '€'
getSymbol('USD') //=> '$'
getSymbol('NOT A VALID CODE') //=> '?'
```
## Tests

@@ -66,2 +37,10 @@ ```bash

## Changelog
### 4.0.0
- the reverse lookup feature was removed (retrieving currency given a symbol) because
there is not a deterministic way to do so (i.e. the same symbol is used by multiple currencies).
- in previous versions, an unsuccessful lookup would return the `'?'` character. It now returns
`undefined` so that it is up to you how to handle the failure.
## Credits

@@ -68,0 +47,0 @@

@@ -1,157 +0,29 @@

var assert = require('assert');
const test = require('tape')
var getSymbol = require('./currency-symbol-map');
var getSymbolFromCurrency = require('./currency-symbol-map').getSymbolFromCurrency;
var getCurrencyFromSymbol = require('./currency-symbol-map').getCurrencyFromSymbol;
var symbolCurrencyMap = require('./currency-symbol-map').symbolCurrencyMap;
var currencySymbolMap = require('./currency-symbol-map').currencySymbolMap;
const getSymbolFromCurrency = require('./')
const currencySymbolMap = require('./map')
describe('currency-symbol-map', function() {
describe('getSymbolFromCurrency()', function () {
test('getSymbolFromCurrency(): valid params', t => {
t.equal('$', getSymbolFromCurrency('USD'), 'should return $ when USD is provided')
t.equal('£', getSymbolFromCurrency('GBP'), 'should return £ when GBP is provided')
t.equal('€', getSymbolFromCurrency('EUR'), 'should return € when EUR is provided')
t.equal('€', getSymbolFromCurrency('eur'), 'should return € when eur is provided')
t.equal(undefined, getSymbolFromCurrency('NON-EXISTENT-CODE'), 'should return undefined when code is non-existent')
t.end()
})
describe('invalid params', function() {
it('should return undefined when param is not a string', function () {
assert.equal(undefined, getSymbolFromCurrency(1));
});
test('getSymbolFromCurrency(): invalid params', t => {
t.equal(undefined, getSymbolFromCurrency(1), 'should return undefined when param is not a string')
t.equal(undefined, getSymbolFromCurrency(null), 'should return undefined when param is null')
t.equal(undefined, getSymbolFromCurrency(false), 'should return undefined when param is false')
t.equal(undefined, getSymbolFromCurrency(), 'should return undefined when param is undefined')
t.end()
})
it('should return undefined when param is null', function () {
assert.equal(undefined, getSymbolFromCurrency(null));
});
it('should return undefined when param is false', function () {
assert.equal(undefined, getSymbolFromCurrency(false));
});
it('should return undefined when param is undefined', function () {
assert.equal(undefined, getSymbolFromCurrency());
});
})
describe('valid params', function() {
it('should return $ when USD is provided', function () {
assert.equal('$', getSymbolFromCurrency('USD'));
});
it('should return £ when GBP is provided', function () {
assert.equal('£', getSymbolFromCurrency('GBP'));
});
it('should return € when EUR is provided', function () {
assert.equal('€', getSymbolFromCurrency('EUR'));
});
it('should return undefined when code is non-existent', function() {
assert.equal(undefined, getSymbolFromCurrency('NON-EXISTENT-CODE'));
});
describe('allows for lowercase params', function() {
it('should return € when EUR is provided', function () {
assert.equal('€', getSymbolFromCurrency('eur'));
});
})
})
});
describe('getCurrencyFromSymbol()', function() {
it('should return USD when $ is provided', function() {
assert.equal('USD', getCurrencyFromSymbol('$'));
});
it('should return GBP when £ is provided', function() {
assert.equal('GBP', getCurrencyFromSymbol('£'));
});
it('should return EUR when € is provided', function() {
assert.equal('EUR', getCurrencyFromSymbol('€'));
});
it('should return undefined when symbol is non-existent', function() {
assert.equal(undefined, getCurrencyFromSymbol('NON-EXISTENT-SYMBOL'));
});
});
describe('getSymbol() [deprecated]', function() {
describe('invalid params', function() {
it('should return undefined when param is not a string', function () {
assert.equal('?', getSymbol(1));
});
it('should return undefined when param is null', function () {
assert.equal('?', getSymbol(null));
});
it('should return undefined when param is false', function () {
assert.equal('?', getSymbol(false));
});
it('should return undefined when param is undefined', function () {
assert.equal('?', getSymbol());
});
})
describe('valid params', function() {
it('should return $ when USD is provided', function() {
assert.equal('$', getSymbol('USD'));
});
it('should return £ when GBP is provided', function() {
assert.equal('£', getSymbol('GBP'));
});
it('should return € when EUR is provided', function() {
assert.equal('€', getSymbol('EUR'));
});
it('should return ? when code is non-existent', function() {
assert.equal('?', getSymbol('NON-EXISTENT-CODE'));
});
describe('allows for lowercase params', function() {
it('should return € when EUR is provided', function () {
assert.equal('€', getSymbol('eur'));
});
})
})
});
});
describe('currency-symbol-map [generated]', function() {
describe('getSymbolFromCurrency()', function () {
var generateTestName = function(symbol, currency) {
return "should return " + symbol + " when " + currency + " is provided";
};
for (var symbol in symbolCurrencyMap) {
var currency = symbolCurrencyMap[symbol];
it.apply(this, [generateTestName(symbol, currency), function() {
assert.equal(symbol, getSymbolFromCurrency(currency));
}]);
}
});
describe('getCurrencyFromSymbol()', function() {
var generateTestName = function(symbol, currency) {
return "should return " + currency + " when " + symbol + " is provided";
};
for (var currency in currencySymbolMap) {
var symbol = currencySymbolMap[currency];
it.apply(this, [generateTestName(symbol, currency), function() {
assert.equal(currency, getCurrencyFromSymbol(symbol));
}]);
}
});
});
test('currency-symbol-map: sanity check every value in map', t => {
const currencies = Object.keys(currencySymbolMap)
const obj = {}
currencies.forEach(code => { obj[code] = getSymbolFromCurrency(code) })
t.deepEqual(obj, currencySymbolMap)
t.end()
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc