Security News
Combatting Alert Fatigue by Prioritizing Malicious Intent
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
currency-symbol-map
Advanced tools
The currency-symbol-map npm package provides a simple way to get the currency symbol for a given currency code or country. It is useful for applications that need to display currency symbols dynamically based on user input or locale settings.
Get currency symbol by currency code
This feature allows you to get the currency symbol for a given currency code. For example, passing 'USD' will return the dollar symbol '$'.
const currencySymbolMap = require('currency-symbol-map');
const symbol = currencySymbolMap('USD');
console.log(symbol); // Output: $
Get currency symbol by country name
This feature allows you to get the currency symbol for a given country name. For example, passing 'United States' will return the dollar symbol '$'.
const currencySymbolMap = require('currency-symbol-map');
const symbol = currencySymbolMap('United States');
console.log(symbol); // Output: $
Get currency code by currency symbol
This feature allows you to get the currency code for a given currency symbol. For example, passing '€' will return the currency code 'EUR'.
const currencySymbolMap = require('currency-symbol-map');
const code = currencySymbolMap.symbolToCurrency('€');
console.log(code); // Output: EUR
The currency-codes package provides a comprehensive list of currency codes and their associated information, including symbols. It is more detailed and includes additional information such as currency names and numeric codes, but it requires more effort to extract just the symbol.
The currency-formatter package allows for formatting numbers as currency strings, including the appropriate currency symbol. It is more focused on formatting and includes options for locale-specific formatting, making it more versatile for applications that need to display formatted currency values.
The iso-currency package provides ISO 4217 currency codes and their associated information, including symbols. It is similar to currency-codes but focuses specifically on ISO standards, making it a good choice for applications that need to adhere to these standards.
A function to lookup the currency symbol for a given currency code and vice versa.
npm install currency-symbol-map
var getSymbolFromCurrency = require('currency-symbol-map').getSymbolFromCurrency;
getSymbolFromCurrency('GBP'); //=> '£'
getSymbolFromCurrency('EUR'); //=> '€'
getSymbolFromCurrency('USD'); //=> '$'
getSymbolFromCurrency('NOT A VALID CODE'); //=> undefined
var getCurrencyFromSymbol = require('currency-symbol-map').getCurrencyFromSymbol;
getCurrencyFromSymbol('£'); //=> 'GBP'
getCurrencyFromSymbol('€'); //=> 'EUR'
getCurrencyFromSymbol('$'); //=> 'USD'
getCurrencyFromSymbol('NOT A VALID CODE'); //=> undefined
var symbolCurrencyMap = require('currency-symbol-map').symbolCurrencyMap;
/*
{
"$": "USD",
"£": "GBP",
...
}
*/
var currencySymbolMap = require('currency-symbol-map').currencySymbolMap;
/*
{
"USD": "$",
"GBP": "£",
...
}
*/
Old usage still works, but could be removed in future versions.
var getSymbol = require('currency-symbol-map')
getSymbol('GBP') //=> '£'
getSymbol('EUR') //=> '€'
getSymbol('USD') //=> '$'
getSymbol('NOT A VALID CODE') //=> '?'
npm test
Currency symbols originally sourced from xe, but maintained and updated by contributors.
FAQs
A function to lookup the currency symbol for a given currency code
We found that currency-symbol-map demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.