pretty-bytes

Convert byte counts into human-readable strings like 1337 → 1.34 kB, with binary, bit, and locale-aware formatting options.

Library
npm
v7.1.3
1,308stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
63/100Good
Development Activity68
Maintenance44
Community52
Maturity60
Momentum28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
71/100Good
Architecture78
Code Quality92
Innovation80
Learning Curve35

pretty-bytes is a zero-dependency utility that turns raw byte counts into strings people can actually read, converting 1337 into 1.34 kB using SI decimal units by default. It handles both number and bigint inputs, so it works equally well for small UI values and for arbitrarily large byte counts that would otherwise lose precision in a Number.

Beyond the basic conversion, it exposes a focused set of options for real-world display needs: binary (KiB/MiB) units for memory reporting, bit units for bitrate displays, signed output for diffs, locale-aware number formatting, explicit fraction-digit control, and fixed-width padding for aligning values in tables or progress bars. The whole implementation ships as a single small ESM module with a hand-written TypeScript declaration file, making it a common building block wherever a byte count needs to be shown to a user.

What You Get

  • A single prettyBytes(number, options?) function with no runtime dependencies, distributed as ESM with bundled TypeScript types.
  • Support for both number and bigint inputs, so extremely large byte counts (beyond safe integer range) still format correctly.
  • SI (kB, MB, GB…) and binary (KiB, MiB, GiB…) unit modes, plus a parallel bit/bibit mode for bitrate displays.
  • Locale-aware output via Intl-backed toLocaleString, with explicit minimum/maximum fraction-digit control and truncation instead of rounding when digits are specified.
  • A fixedWidth option that right-pads results for aligned columns in tables, logs, or progress bars.

Common Use Cases

  • Displaying file sizes in upload/download UIs, file managers, or admin dashboards.
  • Formatting memory, disk, or bandwidth usage in CLI tools and monitoring dashboards.
  • Showing bitrate or transfer-speed figures in networking or media tooling.
  • Rendering aligned, fixed-width byte columns in terminal tables or progress bars.

Under The Hood

Architecture The whole package is a single ESM module (index.js) built from small, composable pure functions rather than a class or stateful pipeline: toLocaleString handles locale-aware number rendering, log10/log/divide implement bigint-safe math (since Math.log/division don’t work directly on bigint), buildLocaleOptions translates the public options into Intl number-format options, and applyFixedWidth handles the final padding step. The exported prettyBytes function composes these in a clear linear flow — validate input, normalize options, pick a unit table, compute the exponent, divide, format, then pad — so despite having no internal module boundaries, the separation of concerns is explicit and each helper could be swapped or extended (e.g. new unit tables) without touching the others.

Tech Stack The package has zero runtime dependencies and ships as pure ESM ("type": "module") targeting Node.js 20+, relying only on built-in Number#toLocaleString/Intl for localization. Its devDependencies are entirely tooling: ava for the test runner, xo (an opinionated ESLint preset used across Sindre Sorhus’s packages) for linting, and tsd for type-level testing against the hand-written index.d.ts. There is no build step — the published package is the same JavaScript and declaration file present in the repo.

Code Quality The test suite (test.js) is extensive relative to the package’s size, covering invalid-input errors, bigint vs number parity, rounding behavior at every unit boundary, binary vs SI units, locale formatting, signed output, and fixed-width padding edge cases. Type safety is enforced two ways: a hand-authored index.d.ts with JSDoc-documented options, and index.test-d.ts running tsd type-level assertions against it. Error handling is explicit — invalid numeric input and invalid fixedWidth values throw descriptive TypeErrors rather than failing silently. GitHub Actions CI (.github/workflows) runs the xo && ava && tsd script on each change.

API Design The public surface is a single function with sensible defaults (unlabeled call prettyBytes(1337) just works), and every non-default behavior is opt-in through a flat options object — signed, bits, binary, locale, minimumFractionDigits, maximumFractionDigits, space, nonBreakingSpace, fixedWidth. This keeps the common case a one-line call while still covering less common needs like bitrate display, table alignment, and internationalization without requiring a second API or configuration object. Documentation in the README and type declarations pairs every option with a runnable example, which keeps the learning curve low despite the fairly broad option surface.

Used by 14 apps in this directory

TypeScript
99%
Other

Activepieces

Automation · AI Assistants

24,298

Open-source AI automation platform that converts 280+ workflow integrations into MCP servers for LLMs, with no-code builders and TypeScript extensibility.

View details
92
Repo Health
85
Technical
64
Dependency
Built with
TypeScript99%
Updated today
Rust
67%
MIT

Bun

Developer Tools

95,895

An all-in-one JavaScript and TypeScript toolkit — one Rust-and-JavaScriptCore binary that replaces Node.js, npm, a bundler, and a test runner with faster equivalents.

View details
92
Repo Health
91
Technical
64
Dependency
Built with
Rust67%
C++19%
Updated yesterday
TypeScript
98%
AGPL 3.0

Checkmate

Devops · Analytics · Monitoring

10,794

Self-hosted uptime and infrastructure monitoring with multi-protocol checks, global geo-coverage, and beautiful real-time dashboards.

View details
91
Repo Health
82
Technical
68
Dependency
Built with
TypeScript98%
Updated yesterday
TypeScript
98%
Apache 2.0

Cline

AI Code Assistants

67,585

An open-source AI coding agent that lives in your editor and terminal — reads and edits your codebase, runs commands, browses the web, and requires human approval for every action by default.

View details
89
Repo Health
74
Technical
65
Dependency
Built with
TypeScript98%
Updated 2 days ago
Go
75%
AGPL 3.0

Coder

Devops · Developer Tools · Code Editors

14,385

Self-hosted cloud development environments and AI coding agents — defined in Terraform, connected via WireGuard, automatically shut down when idle.

View details
93
Repo Health
90
Technical
68
Dependency
Built with
Go75%
TypeScript23%
Updated today
Svelte
46%
MIT

Cryptgeon

File Storage · Security

1,517

Self-destructing encrypted notes and files that vanish after viewing — the server never sees your keys.

View details
75
Repo Health
80
Technical
74
Dependency
Built with
Svelte46%
TypeScript30%
Rust14%
Updated yesterday
JavaScript
99%
GPL 3.0

homepage

Monitoring · Productivity

32,445

A fast, fully static, and secure self-hosted startpage with Docker service discovery and integrations for over 160 services.

View details
91
Repo Health
86
Technical
72
Dependency
Built with
JavaScript99%
Updated today
TypeScript
76%
Other

Joplin

Note Taking

56,257

The privacy-first, open-source note-taking app with end-to-end encrypted sync, AI assistance, and a powerful plugin ecosystem across every platform.

View details
93
Repo Health
87
Technical
61
Dependency
Built with
TypeScript76%
JavaScript14%
Updated yesterday
TypeScript
95%
Other

LLM Gateway

AI Development · Devops

1,611

One API endpoint for 25+ LLM providers — route, track costs, enforce compliance, and switch models without changing your code.

View details
85
Repo Health
80
Technical
71
Dependency
Built with
TypeScript95%
Updated yesterday

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search