pretty-bytes
Convert byte counts into human-readable strings like 1337 → 1.34 kB, with binary, bit, and locale-aware formatting options.
Repository Health
Technical Analysis
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
numberandbigintinputs, 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-backedtoLocaleString, with explicit minimum/maximum fraction-digit control and truncation instead of rounding when digits are specified. - A
fixedWidthoption 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
Activepieces
Automation · AI Assistants
Open-source AI automation platform that converts 280+ workflow integrations into MCP servers for LLMs, with no-code builders and TypeScript extensibility.
Bun
Developer Tools
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.
Checkmate
Devops · Analytics · Monitoring
Self-hosted uptime and infrastructure monitoring with multi-protocol checks, global geo-coverage, and beautiful real-time dashboards.
Cline
AI Code Assistants
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.
Coder
Devops · Developer Tools · Code Editors
Self-hosted cloud development environments and AI coding agents — defined in Terraform, connected via WireGuard, automatically shut down when idle.
Cryptgeon
File Storage · Security
Self-destructing encrypted notes and files that vanish after viewing — the server never sees your keys.
homepage
Monitoring · Productivity
A fast, fully static, and secure self-hosted startpage with Docker service discovery and integrations for over 160 services.
Joplin
Note Taking
The privacy-first, open-source note-taking app with end-to-end encrypted sync, AI assistance, and a powerful plugin ecosystem across every platform.
LLM Gateway
AI Development · Devops
One API endpoint for 25+ LLM providers — route, track costs, enforce compliance, and switch models without changing your code.