flo-utils
Version:
30 lines (24 loc) • 537 B
JavaScript
/**
*
* @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;
}
export default btSize;