Skip to main content

readableBytes

Converts a number of bytes to a human readable file size.

Parameters

  • bytes number of bytes to show

  • options Object? user provided options object

    • options.decimals number? optional number of decimals to show
    • options.minUnit ("byte(s)" | "kB" | "MB" | "GB" | "TB" | "PB")? minimum unit to display; if undefined, the most appropriate unit is selected automatically

Examples

readableBytes(1234);
// => 1.205078125 kB

readableBytes(1234, { decimals: 2 });
// => 1.21 kB

readableBytes(500, { minUnit: 'kB' });
// => 0.48828125 kB

readableBytes(500, { decimals: 2, minUnit: 'kB' });
// => 0.49 kB kB

Returns string of human readable file size.

Meta

  • version: 1.0.0