(bytes)
| 4 | const LOG_K = Math.log(K); |
| 5 | |
| 6 | export function formatBytes(bytes) { |
| 7 | if (bytes === 0) { |
| 8 | return '0 Bytes'; |
| 9 | } |
| 10 | |
| 11 | const index = Math.floor(Math.log(bytes) / LOG_K); |
| 12 | const value = Number((bytes / (K ** index)).toFixed(DECIMALS)); // Use Number to show "1 KB" instead of "1.000 KB" |
| 13 | |
| 14 | return `${value} ${SIZES[index]}`; |
| 15 | } |
no outgoing calls
no test coverage detected