Files
Aether/frontend/src/features/overview/format.ts
T
elky 066ea87d72 feat: revamp analytics dashboards and harden database migrations
Add dashboard and overview analytics, health monitoring, provider expense tracking, and announcement updates across the gateway and frontend.

Keep schema migrations free of historical backfills while preserving automatic backfill execution. Bound migration deadlines, run schema preparation before Compose replacement, and anonymize deleted dashboard users.

Include the current documentation cleanup and regression coverage.
2026-10-01 11:48:17 +08:00

29 lines
1.4 KiB
TypeScript

import type { OverviewAmount } from '@/api/overview'
import { getI18nLocale } from '@/i18n'
export function count(value: number | null | undefined): string {
return value == null ? '-' : new Intl.NumberFormat(getI18nLocale(), { maximumFractionDigits: 2 }).format(value)
}
export function attributionLabel(kind: string | null | undefined): string {
const zh = getI18nLocale() === 'zh-CN'
if (kind === 'employee') return zh ? '成员账号' : 'Member account'
if (kind === 'standalone') return zh ? '独立余额 Key' : 'Standalone balance key'
return !kind || kind === 'unknown' ? (zh ? '未知' : 'Unknown') : kind
}
export function money(amount: OverviewAmount | null | undefined): string {
if (amount?.value == null) return '-'
const number = Number(amount.value)
if (!Number.isFinite(number)) return '-'
return new Intl.NumberFormat(getI18nLocale(), { style: 'currency', currency: amount.currency || 'USD', currencyDisplay: 'narrowSymbol', minimumFractionDigits: 2, maximumFractionDigits: 6 }).format(number)
}
export function percent(value: number | null | undefined): string {
return value == null ? '-' : `${(value * 100).toFixed(2)}%`
}
export function timestamp(value: string | null | undefined, timezone?: string): string {
return !value ? '-' : new Intl.DateTimeFormat(getI18nLocale(), { dateStyle: 'short', timeStyle: 'short', timeZone: timezone }).format(new Date(value))
}