Utility functions for currency symbols and codes.
$ npm i currency-code-symbol-map
or
$ yarn install currency-code-symbol-map
It contains four utility functions along with a mapping of currency codes and symbols.
A Symbol may belong to multiple codes. For example symbol for USD (US Dollar) and CAD (Canadian Dollar) is same, which is $. So this method returns an array of codes.
import { getCodesFromSymbol } from "currency-code-symbol-map";
console.log(getCodesFromSymbol('โน'))
// INR
If
import { getSymbolFromCode } from "currency-code-symbol-map";
console.log(getSymbolFromCode('USD'))
// $
console.log(getCodeFromSymbol('SOME INVALID SYMBOL'));
// undefined
import { isValidCurrencySymbol } from "currency-code-symbol-map";
console.log(isValidCurrencySymbol('$'))
// true
console.log(isValidCurrencySymbol('%'));
// false
import { isValidCurrencyCode } from "currency-code-symbol-map";
console.log(isValidCurrencyCode('USD'))
// true
console.log(isValidCurrencyCode('XYZ'));
// false