@jsenv/log
Advanced tools
Comparing version 1.6.2 to 1.6.3
{ | ||
"name": "@jsenv/log", | ||
"version": "1.6.2", | ||
"version": "1.6.3", | ||
"description": "Nice and dynamic logs in the terminal", | ||
@@ -35,3 +35,3 @@ "license": "MIT", | ||
"scripts": { | ||
"test": "node ./scripts/test.mjs" | ||
"test": "node --conditions=development ./scripts/test.mjs" | ||
}, | ||
@@ -38,0 +38,0 @@ "dependencies": { |
@@ -1,20 +0,31 @@ | ||
import { require } from "@jsenv/utils/require.js" | ||
import { setRoundedPrecision } from "./decimals.js" | ||
const bytes = require("bytes") | ||
// https://github.com/visionmedia/bytes.js | ||
export const byteAsFileSize = (metricValue) => { | ||
return bytes(metricValue, { decimalPlaces: 2, unitSeparator: " " }) | ||
return formatBytes(metricValue) | ||
} | ||
export const byteAsMemoryUsage = ( | ||
metricValue, | ||
{ fixedDecimals = true } = {}, | ||
) => { | ||
return bytes(metricValue, { | ||
decimalPlaces: 2, | ||
unitSeparator: " ", | ||
fixedDecimals, | ||
export const byteAsMemoryUsage = (metricValue) => { | ||
return formatBytes(metricValue, { fixedDecimals: true }) | ||
} | ||
const formatBytes = (number, { fixedDecimals = false } = {}) => { | ||
if (number === 0) { | ||
return `0 B` | ||
} | ||
const exponent = Math.min( | ||
Math.floor(Math.log10(number) / 3), | ||
BYTE_UNITS.length - 1, | ||
) | ||
const unitNumber = number / Math.pow(1000, exponent) | ||
const unitName = BYTE_UNITS[exponent] | ||
const decimals = unitName === "B" ? 0 : 1 | ||
const unitNumberRounded = setRoundedPrecision(unitNumber, { | ||
decimals, | ||
}) | ||
if (fixedDecimals) { | ||
return `${unitNumberRounded.toFixed(decimals)} ${unitName}` | ||
} | ||
return `${unitNumberRounded} ${unitName}` | ||
} | ||
const BYTE_UNITS = ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"] |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18479
579