PHPackages                             avoidwork/filesize.js - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. avoidwork/filesize.js

ActiveLibrary[File &amp; Storage](/categories/file-storage)

avoidwork/filesize.js
=====================

JavaScript library to generate a human readable String describing the file size

6.2.1(5y ago)1.7k38698BSD-3-ClauseJavaScriptCI passing

Since Jan 4Pushed 2w ago14 watchersCompare

[ Source](https://github.com/avoidwork/filesize.js)[ Packagist](https://packagist.org/packages/avoidwork/filesize.js)[ Docs](http://filesizejs.com)[ GitHub Sponsors](https://github.com/avoidwork)[ RSS](/packages/avoidwork-filesizejs/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (46)Used By (0)

filesize
========

[](#filesize)

[![npm version](https://camo.githubusercontent.com/cd91e9e58f9ac52c99873a100e4112c5ed06f05fc55ffbaa82578865fed33188/68747470733a2f2f62616467652e667572792e696f2f6a732f66696c6573697a652e737667)](https://www.npmjs.com/package/filesize)[![Node.js Version](https://camo.githubusercontent.com/1a716e5ec9b40770f43ca70e9b63b13104c7fbbb45379ceb854ae2d96a908ad1/68747470733a2f2f696d672e736869656c64732e696f2f6e6f64652f762f66696c6573697a652e737667)](https://nodejs.org/)[![License](https://camo.githubusercontent.com/b3775a2de17853a90995faa104f941eef3ad3c40cc89e34b8b1eaea014614d4e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d425344253230332d2d436c617573652d626c75652e737667)](https://opensource.org/licenses/BSD-3-Clause)[![Build Status](https://github.com/avoidwork/filesize.js/actions/workflows/ci.yml/badge.svg)](https://github.com/avoidwork/filesize.js/actions)

A lightweight, high-performance file size utility that converts bytes to human-readable strings. Zero dependencies. 100% test coverage.

Why filesize?
-------------

[](#why-filesize)

- **Zero dependencies** - Pure JavaScript, no external packages
- **100% test coverage** - Reliable, well-tested codebase
- **TypeScript ready** - Full type definitions included
- **Multiple standards** - SI, IEC, and JEDEC support
- **Localization** - Intl API for international formatting
- **BigInt support** - Handle extremely large file sizes
- **Functional API** - Partial application for reusable formatters
- **Browser &amp; Node.js** - Works everywhere

Installation
------------

[](#installation)

```
npm install filesize
```

TypeScript
----------

[](#typescript)

Fully typed with TypeScript definitions included:

```
import { filesize, partial } from 'filesize';

const result: string = filesize(1024);
const formatted: { value: number; symbol: string; exponent: number; unit: string } = filesize(1024, { output: 'object' });

const formatter: (arg: number | bigint) => string = partial({ standard: 'iec' });
```

Usage
-----

[](#usage)

```
import {filesize, partial} from "filesize";

filesize(1024); // "1.02 kB"
filesize(265318); // "265.32 kB"
filesize(1024, {standard: "iec"}); // "1 KiB"
filesize(1024, {bits: true}); // "8.19 kbit"
```

### Partial Application

[](#partial-application)

```
import {partial} from "filesize";

const formatBinary = partial({standard: "iec"});
formatBinary(1024); // "1 KiB"
formatBinary(1048576); // "1 MiB"
```

Options
-------

[](#options)

OptionTypeDefaultDescription`bits`boolean`false`Calculate bits instead of bytes`base`number`-1`Number base (2 for binary, 10 for decimal, -1 for auto)`round`number`2`Decimal places to round`locale`string|boolean`""`Locale for formatting, `true` for system locale`localeOptions`Object`{}`Additional locale options`separator`string`""`Custom decimal separator`spacer`string`" "`Value-unit separator`symbols`Object`{}`Custom unit symbols`standard`string`""`Unit standard (`si`, `iec`, `jedec`)`output`string`"string"`Output format (`string`, `array`, `object`, `exponent`)`fullform`boolean`false`Use full unit names`fullforms`Array`[]`Custom full unit names`exponent`number`-1`Force specific exponent (-1 for auto)`roundingMethod`string`"round"`Math method (`round`, `floor`, `ceil`)`precision`number`0`Significant digits (0 for auto)`pad`boolean`false`Pad decimal placesOutput Formats
--------------

[](#output-formats)

```
// String (default)
filesize(1536); // "1.54 kB"

// Array
filesize(1536, {output: "array"}); // [1.54, "kB"]

// Object
filesize(1536, {output: "object"});
// {value: 1.54, symbol: "kB", exponent: 1, unit: "kB"}

// Exponent
filesize(1536, {output: "exponent"}); // 1
```

Standards
---------

[](#standards)

```
// SI (default, base 10)
filesize(1000); // "1 kB"

// IEC (binary, requires base: 2)
filesize(1024, {base: 2, standard: "iec"}); // "1 KiB"

// JEDEC (binary calculation, traditional symbols)
filesize(1024, {standard: "jedec"}); // "1 KB"
```

Examples
--------

[](#examples)

```
// Bits
filesize(1024, {bits: true}); // "8.19 kbit"
filesize(1024, {bits: true, base: 2}); // "8 Kibit"

// Full form
filesize(1024, {fullform: true}); // "1.02 kilobytes"
filesize(1024, {base: 2, fullform: true}); // "1 kibibyte"

// Custom separator
filesize(265318, {separator: ","}); // "265,32 kB"

// Padding
filesize(1536, {round: 3, pad: true}); // "1.536 kB"

// Precision
filesize(1536, {precision: 3}); // "1.54 kB"

// Locale
filesize(265318, {locale: "de"}); // "265,32 kB"

// Custom symbols
filesize(1, {symbols: {B: "Б"}}); // "1 Б"

// BigInt support
filesize(BigInt(1024)); // "1.02 kB"

// Negative numbers
filesize(-1024); // "-1.02 kB"
```

Error Handling
--------------

[](#error-handling)

```
try {
  filesize("invalid");
} catch (error) {
  // TypeError: "Invalid number"
}

try {
  filesize(1024, {roundingMethod: "invalid"});
} catch (error) {
  // TypeError: "Invalid rounding method"
}
```

Testing
-------

[](#testing)

```
npm test              # Run all tests (lint + node:test)
npm run test:watch    # Live test watching
```

**100% test coverage** with 149 tests:

```
--------------|---------|----------|---------|---------|-------------------
File          | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
--------------|---------|----------|---------|---------|-------------------
All files     |     100 |      100 |     100 |     100 |
 constants.js |     100 |      100 |     100 |     100 |
 filesize.js  |     100 |      100 |     100 |     100 |
 helpers.js   |     100 |      100 |     100 |     100 |
--------------|---------|----------|---------|---------|-------------------

```

Development
-----------

[](#development)

```
npm install         # Install dependencies
npm run dev         # Development mode with live reload
npm run build       # Build distributions
npm run lint        # Check code style
npm run lint:fix    # Auto-fix linting issues
```

### Project Structure

[](#project-structure)

```
filesize.js/
├── src/
│   ├── filesize.js      # Main implementation (285 lines)
│   ├── helpers.js       # Helper functions (215 lines)
│   └── constants.js     # Constants (81 lines)
├── tests/
│   └── unit/
├── dist/                # Built distributions
└── types/               # TypeScript definitions

```

Performance
-----------

[](#performance)

- **Basic conversions**: ~16-27M ops/sec
- **With options**: ~5-13M ops/sec
- **Locale formatting**: ~91K ops/sec (use sparingly)

**Optimization tips:**

1. Cache `partial()` formatters for reuse
2. Avoid locale formatting in performance-critical code
3. Use `object` output for fastest structured data access

Contributing
------------

[](#contributing)

We welcome contributions! Please see our [Contributing Guidelines](https://github.com/avoidwork/filesize.js/blob/master/CONTRIBUTING.md) for details.

Changelog
---------

[](#changelog)

See [CHANGELOG.md](https://github.com/avoidwork/filesize.js/blob/master/CHANGELOG.md) for a history of changes.

License
-------

[](#license)

Copyright (c) 2026 Jason Mulligan
Licensed under the BSD-3 license.

###  Health Score

55

—

FairBetter than 97% of packages

Maintenance63

Regular maintenance activity

Popularity40

Moderate usage in the ecosystem

Community31

Small or concentrated contributor base

Maturity76

Established project with proven stability

 Bus Factor1

Top contributor holds 78.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~51 days

Recently: every ~132 days

Total

46

Last Release

1907d ago

Major Versions

3.6.1 → 4.0.02019-01-12

4.2.1 → 5.0.02019-10-01

5.0.3 → 6.0.02019-10-31

### Community

Maintainers

![](https://www.gravatar.com/avatar/c57b31c04075b96bd716ae6b0c43f874d8c67c088d0adf722ddec6feefa76508?d=identicon)[avoidwork](/maintainers/avoidwork)

---

Top Contributors

[![avoidwork](https://avatars.githubusercontent.com/u/369698?v=4)](https://github.com/avoidwork "avoidwork (435 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (84 commits)")[![realityking](https://avatars.githubusercontent.com/u/628508?v=4)](https://github.com/realityking "realityking (7 commits)")[![christopherscott](https://avatars.githubusercontent.com/u/125866?v=4)](https://github.com/christopherscott "christopherscott (3 commits)")[![tomoto](https://avatars.githubusercontent.com/u/552888?v=4)](https://github.com/tomoto "tomoto (2 commits)")[![getsnoopy](https://avatars.githubusercontent.com/u/2997884?v=4)](https://github.com/getsnoopy "getsnoopy (2 commits)")[![abaltuta](https://avatars.githubusercontent.com/u/37699890?v=4)](https://github.com/abaltuta "abaltuta (2 commits)")[![gitter-badger](https://avatars.githubusercontent.com/u/8518239?v=4)](https://github.com/gitter-badger "gitter-badger (1 commits)")[![gurpreetbaidwan](https://avatars.githubusercontent.com/u/4227224?v=4)](https://github.com/gurpreetbaidwan "gurpreetbaidwan (1 commits)")[![laughinghan](https://avatars.githubusercontent.com/u/225809?v=4)](https://github.com/laughinghan "laughinghan (1 commits)")[![litvinok](https://avatars.githubusercontent.com/u/1155664?v=4)](https://github.com/litvinok "litvinok (1 commits)")[![lngsx](https://avatars.githubusercontent.com/u/1572632?v=4)](https://github.com/lngsx "lngsx (1 commits)")[![pdehaan](https://avatars.githubusercontent.com/u/557895?v=4)](https://github.com/pdehaan "pdehaan (1 commits)")[![rnike](https://avatars.githubusercontent.com/u/48589760?v=4)](https://github.com/rnike "rnike (1 commits)")[![ryanramage](https://avatars.githubusercontent.com/u/795834?v=4)](https://github.com/ryanramage "ryanramage (1 commits)")[![ryanrhee](https://avatars.githubusercontent.com/u/242548?v=4)](https://github.com/ryanrhee "ryanrhee (1 commits)")[![starius](https://avatars.githubusercontent.com/u/920155?v=4)](https://github.com/starius "starius (1 commits)")[![tomoto-hitachi](https://avatars.githubusercontent.com/u/57977241?v=4)](https://github.com/tomoto-hitachi "tomoto-hitachi (1 commits)")[![vitormil](https://avatars.githubusercontent.com/u/391209?v=4)](https://github.com/vitormil "vitormil (1 commits)")[![wangxingkai](https://avatars.githubusercontent.com/u/6101654?v=4)](https://github.com/wangxingkai "wangxingkai (1 commits)")

---

Tags

bitsbytesfilefilesizefilesystemiecjedecsimplesizesize-calculationfilereadablefile systemsizefilesize

### Embed Badge

![Health badge](/badges/avoidwork-filesizejs/health.svg)

```
[![Health](https://phpackages.com/badges/avoidwork-filesizejs/health.svg)](https://phpackages.com/packages/avoidwork-filesizejs)
```

###  Alternatives

[league/flysystem

File storage abstraction for PHP

13.6k679.9M2.5k](/packages/league-flysystem)[league/flysystem-aws-s3-v3

AWS S3 filesystem adapter for Flysystem.

1.7k285.7M1.0k](/packages/league-flysystem-aws-s3-v3)[knplabs/gaufrette

PHP library that provides a filesystem abstraction layer

2.5k41.5M133](/packages/knplabs-gaufrette)[knplabs/knp-gaufrette-bundle

Allows to easily use the Gaufrette library in a Symfony project

72430.0M102](/packages/knplabs-knp-gaufrette-bundle)[league/flysystem-local

Local filesystem adapter for Flysystem.

225267.1M89](/packages/league-flysystem-local)[league/flysystem-memory

In-memory filesystem adapter for Flysystem.

8737.3M276](/packages/league-flysystem-memory)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
