Skip to main content
Deno 2 is finally here 🎉️
Learn more

Deprecated

This module is now merged to Deno’s standard modules.

Use https://deno.land/std/fmt/bytes.ts instead.

pretty_bytes v2.0.0

ci

Convert bytes to a human readable string: 1337 → 1.34 kB

A utility for displaying file sizes for humans.

Note: This module was ported from pretty-bytes.

Usage

import { prettyBytes } from "https://deno.land/x/pretty_bytes@v2.0.0/mod.ts";

prettyBytes(1337);
//=> '1.34 kB'

prettyBytes(100);
//=> '100 B'

// Display with units of bits
prettyBytes(1337, { bits: true });
//=> '1.34 kbit'

// Display file size differences
prettyBytes(42, { signed: true });
//=> '+42 B'

// Localized output using German locale
prettyBytes(1337, { locale: "de" });
//=> '1,34 kB'

See the API doc for more details.

License

MIT