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

std/fmt/bytes.ts>format

Deno standard library
Go to Latest
The Standard Library has been moved to JSR. See the blog post for details.
function format
import { format } from "https://deno.land/std@0.215.0/fmt/bytes.ts";

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

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.215.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'

Parameters

num: number
optional
options: FormatOptions = [UNSUPPORTED]

Returns

string