UNPKG

@rsc-labs/medusa-store-analytics

Version:
24 lines (23 loc) 943 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.amountToDisplay = exports.getDecimalDigits = void 0; const utils_1 = require("@medusajs/utils"); const DEFAULT_DECIMAL_DIGITS = 2; function getDecimalDigits(currencyCode) { try { const decimalDigits = utils_1.defaultCurrencies[currencyCode.toUpperCase()] !== undefined ? utils_1.defaultCurrencies[currencyCode.toUpperCase()].decimal_digits : undefined; if (decimalDigits !== undefined) { return decimalDigits; } } catch { return DEFAULT_DECIMAL_DIGITS; } return DEFAULT_DECIMAL_DIGITS; } exports.getDecimalDigits = getDecimalDigits; function amountToDisplay(amount, currencyCode) { const decimalDigits = getDecimalDigits(currencyCode); return `${(amount / Math.pow(10, decimalDigits)).toFixed(decimalDigits)} ${currencyCode.toUpperCase()}`; } exports.amountToDisplay = amountToDisplay;