mirror of
https://github.com/overleaf/overleaf.git
synced 2024-10-17 21:05:04 -04:00
40 lines
678 B
TypeScript
40 lines
678 B
TypeScript
|
export type CurrencyCode =
|
||
|
| 'AUD'
|
||
|
| 'BRL'
|
||
|
| 'CAD'
|
||
|
| 'CHF'
|
||
|
| 'CLP'
|
||
|
| 'COP'
|
||
|
| 'DKK'
|
||
|
| 'EUR'
|
||
|
| 'GBP'
|
||
|
| 'INR'
|
||
|
| 'MXN'
|
||
|
| 'NOK'
|
||
|
| 'NZD'
|
||
|
| 'PEN'
|
||
|
| 'SEK'
|
||
|
| 'SGD'
|
||
|
| 'USD'
|
||
|
|
||
|
export function formatCurrencyLocalized(
|
||
|
amount: number,
|
||
|
currency: CurrencyCode,
|
||
|
locale: string,
|
||
|
stripIfInteger = false
|
||
|
): string {
|
||
|
if (stripIfInteger && Number.isInteger(amount)) {
|
||
|
return amount.toLocaleString(locale, {
|
||
|
style: 'currency',
|
||
|
currency,
|
||
|
minimumFractionDigits: 0,
|
||
|
currencyDisplay: 'narrowSymbol',
|
||
|
})
|
||
|
}
|
||
|
return amount.toLocaleString(locale, {
|
||
|
style: 'currency',
|
||
|
currency,
|
||
|
currencyDisplay: 'narrowSymbol',
|
||
|
})
|
||
|
}
|