Files
shahondin1624 31300cc2a2 Include shared/ dir in repo (gitignore allowlist)
The previous commit referenced shared/ansi.ts, shared/format.ts, and
shared/ctx.ts but those files were filtered by the default-deny
.gitignore. Adding !/shared/ to the allowlist so the imports actually
resolve in a fresh clone.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-24 00:05:38 +02:00

30 lines
822 B
TypeScript

/**
* Small formatting helpers. Pure, no side effects, no external imports.
*/
/**
* Format a token count as a compact human-readable string.
* formatTokens(42) = "42"
* formatTokens(1234) = "1.2k"
* formatTokens(12345) = "12k"
*/
export function formatTokens(n: number): string {
if (n < 1000) return String(n);
if (n < 10_000) return `${(n / 1000).toFixed(1)}k`;
return `${Math.round(n / 1000)}k`;
}
/**
* Format a millisecond duration for the working indicator / timers.
* formatElapsed(450) = "0s"
* formatElapsed(42_000) = "42s"
* formatElapsed(90_500) = "1m 30s"
*/
export function formatElapsed(ms: number): string {
const total = Math.max(0, Math.floor(ms / 1000));
const m = Math.floor(total / 60);
const s = total % 60;
if (m > 0) return `${m}m ${s}s`;
return `${s}s`;
}