mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2025-08-07 23:00:04 +02:00

[web] Clean up localized currency format test (`local-ccy-format-v2`) GitOrigin-RevId: 30d671479522b87ee9205994508b745d2b0ae4c3
38 lines
811 B
JavaScript
38 lines
811 B
JavaScript
/**
|
|
* This file is duplicated from services/web/frontend/js/shared/utils/currency.ts
|
|
*/
|
|
|
|
/**
|
|
* @import { CurrencyCode } from '../../../types/subscription/currency'
|
|
*/
|
|
|
|
/**
|
|
* @param {number} amount
|
|
* @param {CurrencyCode} currency
|
|
* @param {string} locale
|
|
* @param {boolean} stripIfInteger
|
|
* @returns {string}
|
|
*/
|
|
function formatCurrency(amount, currency, locale, stripIfInteger) {
|
|
const options = { style: 'currency', currency }
|
|
if (stripIfInteger && Number.isInteger(amount)) {
|
|
options.minimumFractionDigits = 0
|
|
}
|
|
|
|
try {
|
|
return amount.toLocaleString(locale, {
|
|
...options,
|
|
currencyDisplay: 'narrowSymbol',
|
|
})
|
|
} catch {}
|
|
|
|
try {
|
|
return amount.toLocaleString(locale, options)
|
|
} catch {}
|
|
|
|
return `${currency} ${amount}`
|
|
}
|
|
|
|
module.exports = {
|
|
formatCurrency,
|
|
}
|