| 6 | * @returns {string} Formatted string (e.g., "1.5 KB") |
| 7 | */ |
| 8 | const formatBytes = bytes => { |
| 9 | if (bytes === 0) { |
| 10 | return '0 B'; |
| 11 | } |
| 12 | const units = ['B', 'KB', 'MB', 'GB']; |
| 13 | const index = Math.floor(Math.log(Math.abs(bytes)) / Math.log(1024)); |
| 14 | return (bytes / Math.pow(1024, index)).toFixed(2) + ' ' + units[index]; |
| 15 | }; |
| 16 | |
| 17 | /** |
| 18 | * Calculates percentage change |