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.25
1,709 stars
BSD 3-Clause License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
73 /100 Good
Development Activity 96
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

TypeScript
82%
Other

AFFiNE

Collaboration · Note Taking · Productivity

73,040

Write, draw, and plan in one infinite canvas — the open-source alternative to Notion and Miro that keeps your data yours.

View details
91
Repo Health
87
Technical
67
Dependency
Built with
TypeScript 82%
Rust 11%
Updated 1 weeks ago
TypeScript
92%
GPL 3.0

Blinko

Knowledge Management · Note Taking

11,049

A self-hosted, AI-powered card note-taking tool that lets you capture fleeting thoughts instantly and retrieve them with natural language search.

View details
75
Repo Health
69
Technical
63
Dependency
Built with
TypeScript 92%
Updated 1 months ago
JavaScript
90%
Other

CodeSandbox

Code Editors · Developer Tools

13,650

Instantly ready browser-based IDE that runs full npm dependency resolution and transpilation entirely client-side, with no server needed.

View details
67
Repo Health
76
Technical
62
Dependency
Built with
JavaScript 90%
Updated 1 months ago
TypeScript
94%
AGPL 3.0

Element Web

Collaboration · Team Chat

13,518

A polished, self-hostable Matrix client for secure, decentralized messaging and collaboration that puts your organization in full control of its data.

View details
96
Repo Health
83
Technical
65
Dependency
Built with
TypeScript 94%
Updated 1 weeks ago
TypeScript
61%
EPL-2.0

Huly Platform

Collaboration · Project Management · Team Chat

27,797

Open-source all-in-one workspace that replaces Linear, Jira, Slack, and Notion for product and engineering teams.

View details
90
Repo Health
86
Technical
62
Dependency
Built with
TypeScript 61%
Svelte 34%
Updated 1 weeks ago
TypeScript
99%
Other

NocoBase

Low Code Platforms · No Code Platforms

24,377

Open-source AI + no-code platform that lets coding agents and people collaborate to build business systems fast on proven infrastructure.

View details
94
Repo Health
81
Technical
63
Dependency
Built with
TypeScript 99%
Updated 1 weeks ago
Go
74%
Other

Notifuse

Marketing

2,223

Open-source, self-hosted alternative to Mailchimp, Brevo, and Klaviyo — send newsletters and transactional emails without per-email pricing or vendor lock-in.

View details
81
Repo Health
80
Technical
66
Dependency
Built with
Go 74%
TypeScript 23%
Updated 3 weeks ago
PHP
69%
AGPL 3.0

Pixelfed

Social Media

7,105

A decentralized, self-hosted photo sharing platform built on ActivityPub for the open Fediverse.

View details
91
Repo Health
68
Technical
65
Dependency
Built with
PHP 69%
Vue 22%
Updated 1 weeks ago
TypeScript
51%
ZLIB

Portainer

Devops

38,590

A lightweight, open-source web UI that puts Docker, Kubernetes, and Podman management within reach of any team—no CLI expertise required.

View details
92
Repo Health
79
Technical
65
Dependency
Built with
TypeScript 51%
Go 38%
Updated 2 weeks 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