Refresh HiveGrid Cloud reference snapshot

This commit is contained in:
david committed 2026-08-03 15:31:14 +02:00
1 parent 5e99e14772
commit 7f88026f79
5955 files changed
+1177325 -188362

No files matched your search

@@ -5,6 +5,11 @@ import { defaultLocale, type SupportedLocale } from "./i18n";
// explicit locale (resolved by getTranslations); client React code uses the
// useLocaleFormatters() hook which reads the active language from i18next.
// Fixed app-wide time zone so SSR (UTC container) and the browser produce the
// same date strings — deterministic output avoids React #418 hydration
// mismatches. A tenant-level time-zone setting is a future change request.
export const APP_TIME_ZONE = "Europe/Berlin";
const numberFormatters = new Map<string, Intl.NumberFormat>();
const dateTimeFormatters = new Map<string, Intl.DateTimeFormat>();
const relativeTimeFormatters = new Map<string, Intl.RelativeTimeFormat>();
@@ -26,7 +31,8 @@ function getDateTimeFormatter(locale: SupportedLocale | string, options?: Intl.D
const key = formatterKey(locale, options as Record<string, unknown> | undefined);
const cached = dateTimeFormatters.get(key);
if (cached) return cached;
const formatter = new Intl.DateTimeFormat(locale ?? defaultLocale, options);
// Default to the fixed app time zone; an explicitly passed timeZone wins.
const formatter = new Intl.DateTimeFormat(locale ?? defaultLocale, { timeZone: APP_TIME_ZONE, ...options });
dateTimeFormatters.set(key, formatter);
return formatter;
}
@@ -40,23 +46,54 @@ function getRelativeTimeFormatter(locale: SupportedLocale | string, options?: In
return formatter;
}
// Numeric placeholder for values that are missing or not representable. Never
// surface `NaN`, `Infinity` or `null` to a user: a dash reads as "no value",
// while `NaN €` reads as a broken page.
export const MISSING_NUMBER_PLACEHOLDER = "—";
/**
* Coerces loader payloads into a finite number, or `null` when that is
* impossible. Prisma `Decimal` columns survive the turbo-stream loader
* serialization as structural objects rather than strings, so a bare
* `Number(value)` on the client yields `NaN`. Route loaders should normalize
* decimals server-side; this stays as the last line of defence.
*/
export function toFiniteNumber(value: unknown): number | null {
if (typeof value === "number") return Number.isFinite(value) ? value : null;
if (typeof value === "bigint") return Number(value);
if (typeof value === "string") {
const parsed = Number(value.trim());
return value.trim() && Number.isFinite(parsed) ? parsed : null;
}
if (value && typeof value === "object" && "toString" in value) {
const parsed = Number(String(value));
return Number.isFinite(parsed) ? parsed : null;
}
return null;
}
export function formatNumber(value: number, locale: SupportedLocale | string, options?: Intl.NumberFormatOptions): string {
if (!Number.isFinite(value)) return MISSING_NUMBER_PLACEHOLDER;
return getNumberFormatter(locale, options).format(value);
}
export function formatCurrency(value: number, currency: string, locale: SupportedLocale | string, options?: Intl.NumberFormatOptions): string {
if (!Number.isFinite(value)) return MISSING_NUMBER_PLACEHOLDER;
return getNumberFormatter(locale, { style: "currency", currency, ...options }).format(value);
}
export function formatCurrencyFromCents(cents: number, currency: string, locale: SupportedLocale | string, options?: Intl.NumberFormatOptions): string {
if (!Number.isFinite(cents)) return MISSING_NUMBER_PLACEHOLDER;
return formatCurrency(cents / 100, currency, locale, options);
}
export function formatPercent(value: number, locale: SupportedLocale | string, options?: Intl.NumberFormatOptions): string {
if (!Number.isFinite(value)) return MISSING_NUMBER_PLACEHOLDER;
return getNumberFormatter(locale, { style: "percent", ...options }).format(value);
}
export function formatCompactNumber(value: number, locale: SupportedLocale | string, options?: Intl.NumberFormatOptions): string {
if (!Number.isFinite(value)) return MISSING_NUMBER_PLACEHOLDER;
return getNumberFormatter(locale, { notation: "compact", ...options }).format(value);
}