export function formatBytes(bytes: number): string { if (bytes === 0) return '0 B'; const units = ['B', 'KiB', 'MiB', 'GiB'] as const; const exponent = Math.min(Math.floor(Math.log(bytes) / Math.log(1024)), units.length - 1); const value = bytes / 1024 ** exponent; return `${value >= 10 || exponent === 0 ? value.toFixed(0) : value.toFixed(1)} ${units[exponent]}`; } export function formatPercent(value: number): string { return `${Math.round(Math.min(1, Math.max(0, value)) * 100)}%`; }