UNPKG

@hitachivantara/uikit-react-core

Version:
27 lines (26 loc) 508 B
//#region src/FileUploader/utils.ts var units = [ "B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" ]; var findBestUnit = (bytes, base = 1e3) => { const i = bytes > 0 ? Math.floor(Math.log(bytes) / Math.log(base)) : 0; const si = Math.min(i, units.length - 1); return { unit: units[si], value: bytes / base ** si }; }; var convertUnits = (bytes, base = 1e3) => { const { unit, value } = findBestUnit(bytes, base); return value.toFixed(2) + unit; }; //#endregion export { convertUnits };