(ms: number | null | undefined)
| 34 | |
| 35 | /** Format a duration in ms as a compact human string (e.g. "840ms", "2.4s", "1m03s"). */ |
| 36 | export function formatDuration(ms: number | null | undefined): string { |
| 37 | if (ms === null || ms === undefined || !Number.isFinite(ms)) return '—'; |
| 38 | if (ms < 1000) return `${Math.round(ms)}ms`; |
| 39 | if (ms < 60000) return `${(ms / 1000).toFixed(1)}s`; |
| 40 | const m = Math.floor(ms / 60000); |
| 41 | const s = Math.floor((ms % 60000) / 1000); |
| 42 | return `${m}m${String(s).padStart(2, '0')}s`; |
| 43 | } |
| 44 | |
| 45 | /** Format a token count compactly (e.g. "512", "12.4k", "1.20M"). */ |
| 46 | export function formatTokens(n: number | null | undefined): string { |
no outgoing calls
no test coverage detected