Track HiveGrid Cloud planning reference
This commit is contained in:
1 parent
b3d5ea6764
commit
e341c5938a
5784 files changed
+1104929
-3
No files matched your search
@@ -0,0 +1,24 @@
|
||||
// Locale-aware number formatter wrapping `Intl.NumberFormat`. Centralised so
|
||||
// every callsite shares a single contract — decimal/percent/compact derive
|
||||
// from this helper to avoid drift between server/client.
|
||||
|
||||
import { getCachedFormatter } from "./cache.js";
|
||||
|
||||
export type FormatNumberOptions = Intl.NumberFormatOptions & { locale: string };
|
||||
|
||||
const numberFormatters = new Map<string, Intl.NumberFormat>();
|
||||
|
||||
export function formatNumber(value: number, options: FormatNumberOptions): string {
|
||||
const { locale, ...rest } = options;
|
||||
return getCachedFormatter(numberFormatters, locale, rest, (formatterLocale, formatterOptions) => new Intl.NumberFormat(formatterLocale, formatterOptions)).format(value);
|
||||
}
|
||||
|
||||
export function formatPercent(value: number, options: FormatNumberOptions): string {
|
||||
const { locale, ...rest } = options;
|
||||
return getCachedFormatter(numberFormatters, locale, { style: "percent", ...rest }, (formatterLocale, formatterOptions) => new Intl.NumberFormat(formatterLocale, formatterOptions)).format(value);
|
||||
}
|
||||
|
||||
export function formatCompactNumber(value: number, options: FormatNumberOptions): string {
|
||||
const { locale, ...rest } = options;
|
||||
return getCachedFormatter(numberFormatters, locale, { notation: "compact", ...rest }, (formatterLocale, formatterOptions) => new Intl.NumberFormat(formatterLocale, formatterOptions)).format(value);
|
||||
}
|
||||
Reference in new issue
Block a user