(bytes: number)
| 6 | } |
| 7 | |
| 8 | export function formatFileSize(bytes: number): string { |
| 9 | if (bytes === 0) return '0 B' |
| 10 | const k = 1024 |
| 11 | const sizes = ['B', 'KB', 'MB', 'GB', 'TB'] |
| 12 | const i = Math.floor(Math.log(bytes) / Math.log(k)) |
| 13 | return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i] |
| 14 | } |
| 15 | |
| 16 | export function formatDateTime(date: string | Date | number): string { |
| 17 | const d = typeof date === 'string' ? new Date(date) : typeof date === 'number' ? new Date(date * 1000) : date |