Skip to content

src/cli/format.ts — shared formatters

Small string formatters shared by multiple CLI subcommands.

export function formatBytes(n: number): string

Human-readable byte size with B / KB / MB / GB / TB / PB suffixes and one decimal of precision below 10 of any unit. Powers of 1024.

InputOutput
00 B
10231023 B
10241.0 KB
9 * 1024 + 1009.1 KB
10 * 102410 KB
1024 ** 21.0 MB
5 * 1024 ** 35.0 GB
  • vx cache prune output (Pruned N entries (1.3 GB freed)).
  • The future vx stats command (not yet implemented; the runs table is queryable directly via sqlite3 today).

tests/cli.test.ts includes a formatBytes table-driven case set.