UNPKG

@janus-idp/shared-react

Version:

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

18 lines (14 loc) 599 B
'use strict'; var mathjs = require('mathjs'); const math = mathjs.create({ createUnitDependencies: mathjs.createUnitDependencies, unitDependencies: mathjs.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; } exports.formatByteSize = formatByteSize; //# sourceMappingURL=format-byte-size.cjs.js.map