const UNITS = ['B', 'KB', 'MB', 'GB', 'TB']; /** A size in bytes as a short, localised text (1,5 MB). */ export function formatBytes(bytes: number, language: string): string { let value = Math.max(0, bytes); let unit = 0; while (value >= 1024 && unit < UNITS.length - 1) { value /= 1024; unit++; } return `${new Intl.NumberFormat(language, { maximumFractionDigits: unit === 0 ? 0 : 1 }).format(value)} ${UNITS[unit]}`; }