UNPKG

current-currency

Version:

Making it easy to work with currencies and cryptos!

23 lines (22 loc) 939 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.extract = void 0; const currencies_1 = require("../utils/currencies"); const currencies_2 = require("../types/currencies"); const cryptocurrencies_1 = require("../types/cryptocurrencies"); const cryptocurrencies_2 = require("../utils/cryptocurrencies"); /** * Extracts the currency from a string * @param currencyString The string containing amount and currency code */ function extract(currencyString) { const currencySymbol = currencyString.replace(/[0-9,. ]/g, ""); if (currencies_2.CURRENCY_CODES.includes(currencySymbol)) { return currencies_1.Currencies[currencySymbol]; } if (cryptocurrencies_1.CRYPTO_CURRENCY_CODES.includes(currencySymbol)) { return cryptocurrencies_2.Cryptocurrencies[currencySymbol]; } throw new Error("Unsupported currency code"); } exports.extract = extract;