jiq
Version:
Use existing javascript knowledge to query or modify data
19 lines (18 loc) • 538 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.filesize = void 0;
function filesize(bytes) {
const thresh = 1024;
if (Math.abs(bytes) < thresh) {
return bytes + ' B';
}
const units = ['KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
let u = -1;
const r = 10;
do {
bytes /= thresh;
++u;
} while (Math.round(Math.abs(bytes) * r) / r >= thresh && u < units.length - 1);
return bytes.toFixed(1) + ' ' + units[u];
}
exports.filesize = filesize;
;