UNPKG

@janus-idp/shared-react

Version:

Shared code for utils, types, and React components for the Janus frontend plugins.

16 lines (13 loc) 550 B
import { create, createUnitDependencies, unitDependencies } from 'mathjs'; const math = create({ createUnitDependencies, unitDependencies }); const UNITS = ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]; function formatByteSize(sizeInBytes) { if (!sizeInBytes) { return "N/A"; } const i = Math.floor(Math.log10(sizeInBytes) / 3); const fileSize = math.unit(sizeInBytes, "B").to(UNITS[i]).format({ precision: 3, notation: "auto" }); return fileSize; } export { formatByteSize }; //# sourceMappingURL=format-byte-size.esm.js.map