(bytes: number)
| 4 | * Format file size in a human-readable format |
| 5 | */ |
| 6 | export const formatFileSize = (bytes: number): string => { |
| 7 | if (bytes === 0) return '0 B'; |
| 8 | const sizes = ['B', 'KB', 'MB', 'GB', 'TB']; |
| 9 | const i = Math.floor(Math.log(bytes) / Math.log(1024)); |
| 10 | const value = bytes / Math.pow(1024, i); |
| 11 | const precision = value >= 10 ? 0 : 1; |
| 12 | return `${value.toFixed(precision)} ${sizes[i]}`; |
| 13 | }; |
| 14 | |
| 15 | /** |
| 16 | * Format annotation location for display. AnnotationBBox: [left, top, width, height] |
no outgoing calls
no test coverage detected