TypeScript 97.4%
SQL 1%
JavaScript 0.9%
CSS 0.6%
1import type { PolyModel } from "@/lib/ai/core/types";23/** "$0.25", "$10", "—" — USD per 1M tokens. Server- and client-safe. */4export function formatPrice(v: number | null | undefined): string {5 if (v === undefined || v === null || Number.isNaN(v)) return "—";6 if (v === 0) return "$0";7 if (v < 0.01) return `$${v.toFixed(4).replace(/0+$/, "")}`;8 if (v < 1) return `$${v.toFixed(2)}`;9 return `$${Number.isInteger(v) ? v : v.toFixed(2).replace(/\.?0+$/, "")}`;10}1112/** "$2 / $10" input / output per 1M. */13export function formatPricePair(m: PolyModel): string {14 const p = m.pricing;15 if (!p || (p.inputPerMillion === undefined && p.outputPerMillion === undefined)) return "—";16 return `${formatPrice(p.inputPerMillion)} / ${formatPrice(p.outputPerMillion)}`;17}1819export function formatContext(n: number | null | undefined): string {20 if (!n) return "—";21 if (n >= 1_000_000) return `${(n / 1_000_000).toFixed(2).replace(/\.?0+$/, "")}M`;22 if (n >= 1_000) return `${(n / 1_000).toFixed(1).replace(/\.?0+$/, "")}K`;23 return String(n);24}2526/** ISO date → "Sep 8, 2026" (UTC, deterministic for SSR). */27export function formatIsoDate(v: unknown): string {28 if (typeof v !== "string" || !v) return "—";29 const d = new Date(v);30 if (Number.isNaN(d.getTime())) return v;31 return d.toLocaleDateString("en-US", { month: "short", day: "numeric", year: "numeric", timeZone: "UTC" });32}33