(n: number)
| 8 | export { formatCost } |
| 9 | |
| 10 | export function formatTokens(n: number): string { |
| 11 | // Guard against Infinity / NaN / negatives that would otherwise leak into |
| 12 | // the UI as "Infinity" or "NaN" strings when an upstream calculation glitches. |
| 13 | if (!Number.isFinite(n)) return '?' |
| 14 | if (n < 0) return '0' |
| 15 | if (n >= 1_000_000) return `${(n / 1_000_000).toFixed(1)}M` |
| 16 | if (n >= 1_000) return `${(n / 1_000).toFixed(1)}K` |
| 17 | return Math.round(n).toString() |
| 18 | } |
| 19 | |
| 20 | /// Returns YYYY-MM-DD for the given date in the process-local timezone. Cheaper than shelling |
| 21 | /// out to Intl.DateTimeFormat for every turn in a loop and avoids the UTC drift that bites |
no outgoing calls
no test coverage detected