This repository has been archived on 2023-01-27. You can view files and clone it, but cannot push or open issues or pull requests.
cad/formatter.js
2022-10-15 19:16:08 +02:00

22 lines
607 B
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.sizeToString = void 0;
exports.sizeToString = (bytes, si = true) => {
var units;
var u;
var b = bytes;
var thresh = si ? 1000 : 1024;
if (Math.abs(b) < thresh) {
return b + ' B';
}
units = si
? ['kB', 'MB', 'GB', 'TB']
: ['KiB', 'MiB', 'GiB', 'TiB'];
u = -1;
do {
b /= thresh;
++u;
} while (Math.abs(b) >= thresh && u < units.length - 1);
return b.toFixed(1) + ' ' + units[u];
};
//# sourceMappingURL=formatter.js.map