// How big something is, in words a person reads at a glance. const UNITS = { MB: 1024 ** 2, GB: 1024 ** 3 } as const; /** * `bytes` in `unit`, with one decimal below 10 and none above. Sizes sit in lists * where a 2.7 MB package and a 95 MB AppImage are compared, and "3 MB" next to * "95 MB" loses the only distinction that matters at the small end. */ export function roughSize(bytes: number, unit: keyof typeof UNITS): string { const n = bytes / UNITS[unit]; return `${n < 10 ? n.toFixed(1) : n.toFixed(0)} ${unit}`; }