robert-util
Version:
Utilities for robert and robert-server packages
28 lines (27 loc) • 766 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseSize = exports.sizes = void 0;
const ratio = 1024;
exports.sizes = {
k: Math.pow(ratio, 1),
m: Math.pow(ratio, 2),
g: Math.pow(ratio, 3),
t: Math.pow(ratio, 4),
p: Math.pow(ratio, 5),
e: Math.pow(ratio, 6),
z: Math.pow(ratio, 7),
y: Math.pow(ratio, 8)
};
function parseSize(size) {
var _a;
if (typeof size === "number")
return size;
const bytes = parseInt(size.match(/^\d+/)[0]);
const unit = size
.replace(/^\d+\s*/, "")
.trimEnd()
.replace(/[bB]$/, "")
.toLowerCase();
return bytes * ((_a = exports.sizes[unit]) !== null && _a !== void 0 ? _a : 0);
}
exports.parseSize = parseSize;