22 lines
743 B
TypeScript
22 lines
743 B
TypeScript
/**
|
|
* Shared formatting utilities.
|
|
*/
|
|
|
|
export function formatSize(bytes: number | null | undefined): string {
|
|
if (!bytes) return "—";
|
|
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(0)} KB`;
|
|
if (bytes < 1024 * 1024 * 1024)
|
|
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
return `${(bytes / (1024 * 1024 * 1024)).toFixed(2)} GB`;
|
|
}
|
|
|
|
export function formatDuration(seconds: number | null | undefined): string {
|
|
if (!seconds) return "—";
|
|
const h = Math.floor(seconds / 3600);
|
|
const m = Math.floor((seconds % 3600) / 60);
|
|
const s = Math.floor(seconds % 60);
|
|
if (h > 0)
|
|
return `${h}:${m.toString().padStart(2, "0")}:${s.toString().padStart(2, "0")}`;
|
|
return `${m}:${s.toString().padStart(2, "0")}`;
|
|
}
|