(bytes: number)
| 1 | export const formatFileSize = (bytes: number): string => { |
| 2 | if (bytes === 0) { |
| 3 | return '0 bytes'; |
| 4 | } |
| 5 | |
| 6 | const k = 1024; |
| 7 | const sizes = ['bytes', 'KB', 'MB', 'GB']; |
| 8 | |
| 9 | const i = Math.floor(Math.log(bytes) / Math.log(k)); |
| 10 | return `${Number.parseFloat((bytes / k ** i).toFixed(2))} ${sizes[i]}`; |
| 11 | }; |
no test coverage detected