UNPKG

flo-utils

Version:
38 lines (30 loc) 672 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; /** * * @name btSize 容量置换 为 bt * @param {*} size * @returns */ function btSize(size) { var types = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; var k = 1024; if (typeof size === 'string') { var num = parseFloat(size); var unit = size.replace(num, ''); var i = types.indexOf(unit.trim().toUpperCase()); if (i < 0) { return 0; } return parseInt(num * Math.pow(k, i), 10); } if (typeof size === 'number') { return size; } return 0; } var _default = btSize; exports.default = _default;