UNPKG

@malga-checkout/core

Version:
47 lines (45 loc) 1 kB
const formatCurrency = (value, currencyFormat = 'BRL') => { const currenciesWithoutDecimal = [ 'YER', 'AFN', 'ALL', 'BIF', 'CLP', 'DJF', 'GNF', 'ISK', 'JPY', 'KMF', 'KRW', 'LAK', 'LBP', 'MGA', 'MMK', 'MRO', 'PYG', 'RSD', 'RWF', 'SLL', 'SOS', 'STD', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF', ]; const currentValue = currenciesWithoutDecimal.includes(currencyFormat) ? value : value / 100; const currency = new Intl.NumberFormat('pt-BR', { style: 'currency', currency: currencyFormat, }); return currency.format(currentValue); }; const parseAmountDecimalToInteger = (amount) => { const parsedAmount = amount * 100; return parsedAmount.toFixed(); }; export { formatCurrency as f, parseAmountDecimalToInteger as p };