filesize.js

Zero-dependency JavaScript utility that converts byte counts into human-readable file size strings, with SI, IEC, and JEDEC standard support.

Library
npm
v11.0.28
1,711 stars
BSD 3-Clause License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
74 /100 Good
Development Activity 100
Maintenance 52
Community 56
Maturity 60
Momentum 28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
88 /100 Excellent
Architecture 80
Code Quality 88
Innovation 82
Learning Curve 100

filesize is a zero-dependency JavaScript library that converts numeric byte counts into human-readable strings like “1.02 kB” or “1 KiB”. It supports the SI, IEC, and JEDEC unit standards, handles bits as well as bytes, and offers locale-aware number formatting through the Intl API, plus BigInt input for extremely large values.

The library ships full TypeScript type definitions and works identically in Node.js and the browser. A partial() helper lets callers pre-configure a formatter once (for example, a fixed IEC/base-2 formatter) and reuse it, avoiding repeated option objects in hot code paths such as upload progress displays, log formatting, or disk-usage reports.

What You Get

  • SI, IEC, and JEDEC unit standard support (kB vs KiB vs KB)
  • Bits-mode formatting (bits: true) for network/bandwidth values
  • Multiple output shapes — string, array, object, or exponent-only
  • Locale-aware formatting via the Intl API, plus custom separators/spacers/symbols
  • BigInt input support for values beyond Number.MAX_SAFE_INTEGER
  • A partial() factory for pre-configured, reusable formatters

Common Use Cases

  • Displaying upload/download progress in bytes transferred or bytes-per-second
  • Formatting disk usage or file sizes in admin dashboards and file browsers
  • Rendering bandwidth/network throughput in bits instead of bytes
  • Localizing file size display for international user bases

Under The Hood

Architecture

The library is a flat, purely functional module split across three files: filesize.js orchestrates a linear pipeline (validate input, resolve base configuration, calculate exponent, compute the optimized value, round, apply precision handling, resolve the unit symbol, decorate the result, format the output), helpers.js holds the individual pipeline steps as pure, independently testable functions, and constants.js centralizes lookup tables and unit-symbol strings. There is no internal state or class hierarchy; partial() is a thin closure that clones mutable option objects (via structuredClone with a JSON fallback) and returns a pre-bound formatter, keeping repeated calls free of shared-reference bugs.

Tech Stack

filesize.js is written in vanilla ES modules with zero runtime dependencies. Its dev tooling is entirely modern and Rust-accelerated: Rollup (with @rollup/plugin-terser) builds ESM and CJS/UMD bundles, oxlint and oxfmt handle linting and formatting, Husky wires up git hooks, and auto-changelog generates the changelog. Tests run on Node’s built-in node:test runner with --experimental-test-coverage, with no external test framework. GitHub Actions CI targets Node 24.x, running the build and test suite on every PR, with Dependabot auto-merge for routine dependency bumps. TypeScript consumers are served by hand-authored .d.ts declaration files rather than a TypeScript source build.

Code Quality

Three test files under tests/unit/ exercise the main API, the internal helpers, and a structuredClone fallback path specifically, and the project’s own coverage report and README badge claim 100% statement/branch/function/line coverage. Error handling is explicit rather than silent — invalid numeric input and invalid rounding methods both throw typed TypeErrors with clear messages. Every exported function carries JSDoc annotating parameters, return types, and thrown errors, naming is consistent and descriptive (calculateExponent, applyRounding, resolveSymbol), and linting/formatting are enforced in CI and via pre-commit hooks.

API Design The public surface is deliberately small: a single filesize(bytes, options) call returns a string by default, with an output option switching between string, array, object, and exponent-only shapes instead of requiring separate function calls. partial() gives a curried, pre-configured formatter for hot paths, avoiding repeated option-object allocation — a convenience many comparable byte-formatting libraries skip. Deep customization (custom symbols, separators, spacers, full-form pluralization, forced exponent, rounding method) lives behind one options object with sensible defaults, so the zero-config call filesize(1024) works out of the box while every knob remains reachable for advanced use.

Used by 15 apps in this directory

Rust
72%
Apache 2.0

Rivet

AI Agents · Developer Tools

6,326

Stateful actors as a primitive for AI agents, real-time collaboration, and durable execution — with in-memory state, WebSockets, queues, and scheduling built in.

View details
87
Repo Health
81
Technical
64
Dependency
Built with
Rust 72%
TypeScript 25%
Updated 2 days ago
TypeScript
97%
Other

Rocket.Chat

Team Chat

46,304

The secure, self-hosted team communications platform for organizations that cannot compromise on data sovereignty.

View details
96
Repo Health
79
Technical
63
Dependency
Built with
TypeScript 97%
Updated 2 days ago
TypeScript
99%
Other

Teable

Databases · No Code Platforms

21,920

A no-code PostgreSQL database with spreadsheet UX, real-time collaboration, and native AI agents — built for teams that outgrow Airtable.

View details
78
Repo Health
76
Technical
62
Dependency
Built with
TypeScript 99%
Updated 3 days ago
TypeScript
98%
Apache 2.0

Tianji

Analytics · Monitoring

3,119

Replace Google Analytics, UptimeKuma, and Prometheus with one self-hosted platform that tracks websites, monitors uptime, and reports server health.

View details
86
Repo Health
76
Technical
64
Dependency
Built with
TypeScript 98%
Updated 3 days ago
JavaScript
74%
AGPL 3.0

Twake Drive

Collaboration · File Storage

989

Open-source, self-hosted file manager with collaborative drives, AI-powered summarization, and OnlyOffice document editing for teams who want full data sovereignty.

View details
91
Repo Health
78
Technical
71
Dependency
Built with
JavaScript 74%
TypeScript 25%
Updated 3 days ago
TypeScript
41%
AGPL 3.0

Wiki.js

Collaboration · Knowledge Management

29,081

A modern, self-hosted wiki platform built on Node.js with a rich plugin ecosystem for authentication, search, storage, and rendering that adapts to any team's infrastructure.

View details
95
Repo Health
67
Technical
60
Dependency
Built with
TypeScript 41%
Vue 39%
JavaScript 16%
Updated 2 days ago

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