Spaces:
Running
Running
| /** | |
| * Formats bytes into a human-readable string. | |
| * @param bytes - Size in bytes | |
| * @param decimals - Number of decimal places | |
| * @returns Formatted size string | |
| */ | |
| export function formatBytes(bytes: number, decimals = 2) { | |
| if (!+bytes) return '0 Bytes'; | |
| const k = 1024; | |
| const dm = decimals < 0 ? 0 : decimals; | |
| const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; | |
| const i = Math.floor(Math.log(bytes) / Math.log(k)); | |
| return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`; | |
| } | |
| /** | |
| * Formats an ISO timestamp into a readable date and time. | |
| * @param timestamp - ISO string timestamp | |
| * @returns Formatted date string | |
| */ | |
| export function formatDate(timestamp: string) { | |
| try { | |
| const date = new Date(timestamp); | |
| return new Intl.DateTimeFormat('en-US', { | |
| year: 'numeric', | |
| month: 'short', | |
| day: 'numeric', | |
| hour: '2-digit', | |
| minute: '2-digit', | |
| second: '2-digit', | |
| timeZoneName: 'short', | |
| }).format(date); | |
| } catch { | |
| return timestamp; | |
| } | |
| } | |