Skip to main content
variable prettyBytes
import { prettyBytes } from "https://deno.land/x/30_seconds_of_typescript@v1.0.1/util.ts";

Converts a number in bytes to a human-readable string.

Use an array dictionary of units to be accessed based on the exponent. Use Number.toPrecision() to truncate the number to a certain number of digits. Return the prettified string by building it up, taking into account the supplied options and whether it is negative or not. Omit the second argument, precision, to use a default precision of 3 digits. Omit the third argument, divider, to add space between the number and unit by default.

type

(
num: number,
precision?,
addSpace?,
) => unknown