@sanity/form-builder
Version:
Sanity form builder
16 lines (15 loc) • 605 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.formatBytes = formatBytes;
/* method which returns a file size in a readable format */
function formatBytes(bytes) {
var decimals = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
if (bytes === 0) return '0 Bytes';
var k = 1024;
var dm = decimals < 0 ? 0 : decimals;
var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
var i = Math.floor(Math.log(bytes) / Math.log(k));
return "".concat(parseFloat((bytes / Math.pow(k, i)).toFixed(dm)), " ").concat(sizes[i]);
}