Files
Home-Assistant/custom_components/maintenance_supporter/frontend-src/helpers/format-bytes.ts
T
2026-07-08 10:43:39 -04:00

8 lines
310 B
TypeScript

/** Human-readable byte size (B / KB / MB) for document storage figures. */
export function formatBytes(bytes: number | undefined): string {
const b = bytes ?? 0;
if (b < 1024) return `${b} B`;
if (b < 1024 * 1024) return `${(b / 1024).toFixed(1)} KB`;
return `${(b / (1024 * 1024)).toFixed(1)} MB`;
}