diff options
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/utils.ts | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 33737b50..897b0f5a 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -334,16 +334,25 @@ export const f = ( locale = "en-US", minimumFractionDigits = 2, maximumFractionDigits = 2, -) => - new Intl.NumberFormat(locale, { +) => { + const l = typeof locale === "function" ? locale() : locale || "en-US"; + const cur = currency || "USD"; + const region = l.length >= 2 ? l.slice(-2) : ""; + const currencyDisplay = + region && cur.startsWith(region) ? "narrowSymbol" : "symbol"; + return new Intl.NumberFormat(l, { style: "currency", - currency: currency || "USD", + currency: cur, + currencyDisplay, minimumFractionDigits, maximumFractionDigits, }).format(s); +}; -export const s = (s: number, locale = "en-US"): string => - new Intl.NumberFormat(locale, { maximumFractionDigits: 0 }).format(s); +export const s = (s: number, locale = "en-US"): string => { + const l = typeof locale === "function" ? locale() : locale || "en-US"; + return new Intl.NumberFormat(l, { maximumFractionDigits: 0 }).format(s); +}; export const sat = (s: number): string => `${si(Math.abs(s)).toString()}`; |
