| export function formatBytes(bytes: number, decimals: number = 1): string { | |
| if (bytes === 0) return "0 Bytes"; | |
| const k = 1024; | |
| const sizes = ["Bytes", "KB", "MB", "GB", "TB", "PB"]; | |
| const i = Math.floor(Math.log(bytes) / Math.log(k)); | |
| return `${parseFloat((bytes / Math.pow(k, i)).toFixed(decimals))}${sizes[i]}`; | |
| } | |
| export function formatTime(ms: number): string { | |
| if (ms < 1000) { | |
| return `${Math.round(ms)}ms`; | |
| } | |
| const seconds = ms / 1000; | |
| if (seconds < 60) { | |
| return `${seconds.toFixed(1)}s`; | |
| } | |
| const minutes = Math.floor(seconds / 60); | |
| const remainingSeconds = Math.round(seconds % 60); | |
| return `${minutes}m ${remainingSeconds}s`; | |
| } | |
| export function formatNumber(num: number): string { | |
| return new Intl.NumberFormat("en-US").format(num); | |
| } | |