Show file sizes in listings
This commit is contained in:
16
app/helpers/human-file-size.js
Normal file
16
app/helpers/human-file-size.js
Normal file
@@ -0,0 +1,16 @@
|
||||
import { helper } from '@ember/component/helper';
|
||||
|
||||
export default helper(function(fileSizeInBytes/*, options*/) {
|
||||
if (fileSizeInBytes < 1024) {
|
||||
return `${fileSizeInBytes} bytes`;
|
||||
}
|
||||
|
||||
var i = -1;
|
||||
var byteUnits = ['KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
||||
do {
|
||||
fileSizeInBytes = fileSizeInBytes / 1024;
|
||||
i++;
|
||||
} while (fileSizeInBytes > 1024);
|
||||
|
||||
return String(Math.max(fileSizeInBytes, 0.1).toFixed(1) + ' ' +byteUnits[i]);
|
||||
});
|
||||
Reference in New Issue
Block a user