What is currency-symbol-map?
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.
What are currency-symbol-map's main functionalities?
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
Other packages similar to currency-symbol-map
currency-codes
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.
currency-formatter
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.
iso-currency
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.
currency-symbol-map
A function to lookup the currency symbol for a given currency code.
Installation
npm install currency-symbol-map
Usage
Get symbol from currency code
const getSymbolFromCurrency = require('currency-symbol-map')
import getSymbolFromCurrency from 'currency-symbol-map'
getSymbolFromCurrency('GBP')
getSymbolFromCurrency('EUR')
getSymbolFromCurrency('USD')
getSymbolFromCurrency('NOT A VALID CODE')
Exposed map for other processing
const currencyToSymbolMap = require('currency-symbol-map/map')
import currencyToSymbolMap from 'currency-symbol-map/map'
console.log(currencyToSymbolMap)
{
"USD": "$",
"GBP": "£",
…
}
Tests
npm test
Changelog
5.1.0
- Add CNH Currency mapping: #82
5.0.1
- upgraded linter and improved code formatting (#63)
5.0.0
- added some missing currencies (#61)
- fixed the BTC symbol (#50)
- fixed the KZT symbol (#52)
- fixed the SGD symbol (#55)
- added TypeScript typings (#53)
- upgraded test libraries & added extra test cases (#62)
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
Currency symbols originally sourced from xe, but maintained
and updated by contributors.