UNPKG

@chatui/core

Version:

The React library for Chatbot UI

16 lines (15 loc) 504 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var UNITS = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; var k = 1024; var _default = exports.default = function _default(bytes, decimals) { if (bytes < 1) { return "".concat(bytes, " ").concat(UNITS[0]); } var dm = decimals || 2; var i = Math.floor(Math.log(bytes) / Math.log(k)); return "".concat(parseFloat((bytes / Math.pow(k, i)).toFixed(dm)), " ").concat(UNITS[i]); };