Files
paradox-save-parser-frontend/src/lib/formatBytes.ts
T
2026-09-23 18:24:45 +02:00

12 lines
378 B
TypeScript

export const KILOBYTE = 1024
export const MEGABYTE = 1024 * KILOBYTE
/**
* Formats a byte count for error messages and status lines, e.g. "12.3 MB".
*/
export function formatBytes(bytes: number): string {
if (bytes >= MEGABYTE) return `${(bytes / MEGABYTE).toFixed(1)} MB`
if (bytes >= KILOBYTE) return `${(bytes / KILOBYTE).toFixed(1)} KB`
return `${bytes} B`
}