UNPKG

@hitachivantara/uikit-react-core

Version:

Core React components for the NEXT Design System.

14 lines (13 loc) 553 B
"use strict"; Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); const units = ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]; const 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 }; }; const convertUnits = (bytes, base = 1e3) => { const { unit, value } = findBestUnit(bytes, base); return value.toFixed(2) + unit; }; exports.convertUnits = convertUnits;