MCPcopy Create free account
hub / github.com/PerpetualSoftware/pad / formatBytes

Function formatBytes

web/src/lib/workspaces/exportError.ts:16–26  ·  view source on GitHub ↗
(n: number)

Source from the content-addressed store, hash-verified

14const UNITS = ['B', 'KiB', 'MiB', 'GiB', 'TiB'];
15
16export function formatBytes(n: number): string {
17 let v = n;
18 let i = 0;
19 while (v >= 1024 && i < UNITS.length - 1) {
20 v /= 1024;
21 i++;
22 }
23 if (i === 0) return `${Math.round(v)} B`;
24 const s = v.toFixed(1).replace(/\.0$/, '');
25 return `${s} ${UNITS[i]}`;
26}
27
28function num(v: unknown): v is number {
29 return typeof v === 'number' && Number.isFinite(v);

Callers 2

exportErrorMessageFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected