ProvenPin Install

pretty-bytes unit formatting: working versions (tested 2026-10-16)

Format byte counts with pretty-bytes using signed, bits, binary and minimumFractionDigits options, asserting 0, kB/MB/GB boundaries and negative values offline.

passed8 passed · 0 failed2026-10-16 15:21 UTC
Status
passed
Last passed
2026-10-16 15:21 UTC
Tests
8 / 8
Language
TypeScript
Runtime
node v22.23.3
pinned versions3
pretty-bytes@7.2.0@types/node@26.6.5tsx@4.23.15
run it
npm install --no-audit --no-fund --ignore-scripts=false
npm test
test environment
node v22.23.3
linux 6.17.0-1022-azure
x64
runner: github-actions 38923127324

The code

Exactly the files that passed. Your agent can pull them with get_recipe("pretty-bytes-format") (install), or see them on GitHub.

package.json
{
  "name": "pretty-bytes-format",
  "private": true,
  "type": "module",
  "scripts": {
    "test": "node --import tsx --test test/*.test.ts"
  },
  "dependencies": {
    "pretty-bytes": "7.2.0"
  },
  "devDependencies": {
    "@types/node": "26.6.5",
    "tsx": "4.23.15"
  }
}
src/format.ts
import prettyBytes from "pretty-bytes";

export type ByteFormatOptions = {
  signed?: boolean;
  bits?: boolean;
  binary?: boolean;
  minimumFractionDigits?: number;
  maximumFractionDigits?: number;
};

export function formatBytes(bytes: number, options: ByteFormatOptions = {}): string {
  return prettyBytes(bytes, options);
}
test/format.test.ts
import { test } from "node:test";
import assert from "node:assert/strict";
import { formatBytes } from "../src/format.ts";

test("formats zero and small byte counts", () => {
  assert.equal(formatBytes(0), "0 B");
  assert.equal(formatBytes(1), "1 B");
  assert.equal(formatBytes(100), "100 B");
  assert.equal(formatBytes(999), "999 B");
});

test("formats decimal kB, MB and GB boundaries", () => {
  assert.equal(formatBytes(1000), "1 kB");
  assert.equal(formatBytes(1024), "1.02 kB");
  assert.equal(formatBytes(1_000_000), "1 MB");
  assert.equal(formatBytes(1_000_000_000), "1 GB");
});

test("formats negative byte counts", () => {
  assert.equal(formatBytes(-500), "-500 B");
  assert.equal(formatBytes(-1000), "-1 kB");
  assert.equal(formatBytes(-1024), "-1.02 kB");
});

test("formats bits when requested", () => {
  assert.equal(formatBytes(1000, { bits: true }), "1 kbit");
  assert.equal(formatBytes(1024, { bits: true }), "1.02 kbit");
});

test("formats binary units when requested", () => {
  assert.equal(formatBytes(1024, { binary: true }), "1 KiB");
  assert.equal(formatBytes(2048, { binary: true }), "2 KiB");
  assert.equal(formatBytes(1024 * 1024, { binary: true }), "1 MiB");
});

test("adds a sign for positive and negative values", () => {
  assert.equal(formatBytes(1234, { signed: true }), "+1.23 kB");
  assert.equal(formatBytes(-1234, { signed: true }), "-1.23 kB");
});

test("honours minimumFractionDigits", () => {
  assert.equal(formatBytes(1000, { minimumFractionDigits: 2 }), "1.00 kB");
  assert.equal(formatBytes(1500, { minimumFractionDigits: 2 }), "1.50 kB");
});

test("rejects non-finite input", () => {
  assert.throws(() => formatBytes(Number.POSITIVE_INFINITY), TypeError);
});

Connect to ProvenPin

Add the free MCP server so your agent can pull this recipe and others like it. Same setup as the docs.

terminal
claude mcp add --transport http provenpin https://mcp.provenpin.com/mcp

Any other MCP client: Streamable HTTP at https://mcp.provenpin.com/mcp. No API key, no signup.