mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-08 08:39:03 +02:00
250acbf33c
Use new import JSDoc syntax for Typescript annotations GitOrigin-RevId: 782456d637fc8f2de6163b5d70fabf06c1d74964
39 lines
816 B
JavaScript
39 lines
816 B
JavaScript
/**
|
|
* This file is duplicated from services/web/frontend/js/shared/utils/currency.ts
|
|
*/
|
|
|
|
/**
|
|
* @import { CurrencyCode } from '@/shared/utils/currency'
|
|
*/
|
|
|
|
/**
|
|
* @param {number} amount
|
|
* @param {CurrencyCode} currency
|
|
* @param {string} locale
|
|
* @param {boolean} stripIfInteger
|
|
* @returns {string}
|
|
*/
|
|
function formatCurrencyLocalized(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 = {
|
|
formatCurrencyLocalized,
|
|
}
|