1function niceBytes(x){
2 const units = ['bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
3 let l = 0, n = parseInt(x, 10) || 0;
4 while(n >= 1024 && ++l){
5 n = n/1024;
6 }
7 return(n.toFixed(n < 10 && l > 0 ? 1 : 0) + ' ' + units[l]);
8}
1function formatBytes(bytes, decimals = 2) {
2 if (bytes === 0) return '0 Bytes';
3
4 const k = 1024;
5 const dm = decimals < 0 ? 0 : decimals;
6 const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
7
8 const i = Math.floor(Math.log(bytes) / Math.log(k));
9
10 return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
11}
1function formatBytes(a,b=2){if(0===a)return"0 Bytes";const c=0>b?0:b,d=Math.floor(Math.log(a)/Math.log(1024));return parseFloat((a/Math.pow(1024,d)).toFixed(c))+" "+["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"][d]}
2
1function bytesToSize(bytes) {
2 const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB']
3 if (bytes === 0) return 'n/a'
4 const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)), 10)
5 if (i === 0) return `${bytes} ${sizes[i]})`
6 return `${(bytes / (1024 ** i)).toFixed(1)} ${sizes[i]}`
7}