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

x/hex/src/lib/stdx/fmt/bytes.ts

An ecosystem delivering practices, philosophy and portability. Powered By Deno and JavaScript.
Latest
import * as hex from "https://deno.land/x/hex@0.6.5/src/lib/stdx/fmt/bytes.ts";

Pretty print bytes.

Based on pretty-bytes. A utility for displaying file sizes for humans.

This module is browser compatible.

Examples

Example 1

import { format } from "https://deno.land/std@0.224.0/fmt/bytes.ts";

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

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

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

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

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

Functions

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

f
prettyBytes
deprecated

Interfaces

The options for pretty printing the byte numbers.