UNPKG

@transferwise/sensible

Version:
51 lines (44 loc) 1.99 kB
import DEFAULT_AMOUNTS from "./sensible-amounts"; import DEFAULT_ROUTES from "./sensible-routes"; import DEFAULT_TARGETS from "./sensible-targets"; /** * Gets the default amount for a specific currency. * @param {string} currency - The currency code (e.g "JPY"). * @returns {number} The default amount for the given currency or the fallback default amount. */ export function getAmountForCurrency(currency) { return DEFAULT_AMOUNTS[currency] || DEFAULT_AMOUNTS.default; } /** * Gets the currency pair for a specific country. * @param {string} country - The country code (e.g "us"). * @returns {[sourceCurrency: string, targetCurrency: string]} The default currency pair for the given country or the fallback default currency pair. */ export function getCurrencyPairForCountry(country) { const route = getRouteForCountry(country); return [route.slice(0, 3), route.slice(3)]; } /** * Gets the route for a specific country. * @param {string} country - The country code (e.g "us"). * @returns {string} The default route for the given country or the fallback default route. */ export function getRouteForCountry(country) { return DEFAULT_ROUTES[country.toLowerCase()] || DEFAULT_ROUTES.default; } /** * Gets the default target currency for a specific source currency. * @param {string} currency - The source currency code (e.g "USD"). * @returns {string} The default target currency for the given source currency or the fallback default target currency. */ export function getTargetForSourceCurrency(currency) { return getTargetsForSourceCurrency(currency)[0] } /** * Gets all default target currencies for a specific source currency. * @param {string} currency - The source currency code (e.g "USD"). * @returns {string[]} An array of default target currencies for the given source currency or the fallback default target currencies. */ export function getTargetsForSourceCurrency(currency) { return DEFAULT_TARGETS[currency] || DEFAULT_TARGETS.default; }