Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

strategy:
matrix:
node-version: [20.x, 22.x]
node-version: [24.x]

steps:
- name: Checkout Repository
Expand Down
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,34 @@ All notable changes to this project will be documented in this file. Dates are d

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### [11.0.4](https://github.com/avoidwork/filesize.js/compare/11.0.3...11.0.4)

- Fixing how 'precision' adjusts the exponent if there's digits [`#202`](https://github.com/avoidwork/filesize.js/pull/202)

#### [11.0.3](https://github.com/avoidwork/filesize.js/compare/11.0.2...11.0.3)

> 19 September 2025

- Fixing the output when supplying 'precision' [`#201`](https://github.com/avoidwork/filesize.js/pull/201)
- Bump rollup from 4.50.1 to 4.50.2 [`#199`](https://github.com/avoidwork/filesize.js/pull/199)
- Bump actions/setup-node from 4 to 5 [`#198`](https://github.com/avoidwork/filesize.js/pull/198)
- Bump rollup from 4.50.0 to 4.50.1 [`#197`](https://github.com/avoidwork/filesize.js/pull/197)
- Bump eslint from 9.34.0 to 9.35.0 [`#196`](https://github.com/avoidwork/filesize.js/pull/196)
- Bump mocha from 11.7.1 to 11.7.2 [`#195`](https://github.com/avoidwork/filesize.js/pull/195)
- Bump rollup from 4.49.0 to 4.50.0 [`#194`](https://github.com/avoidwork/filesize.js/pull/194)
- Bump rollup from 4.44.2 to 4.49.0 [`#193`](https://github.com/avoidwork/filesize.js/pull/193)
- Bump eslint from 9.30.1 to 9.34.0 [`#192`](https://github.com/avoidwork/filesize.js/pull/192)
- Bump actions/checkout from 4 to 5 [`#191`](https://github.com/avoidwork/filesize.js/pull/191)
- Updating tests [`017e5b1`](https://github.com/avoidwork/filesize.js/commit/017e5b1fe328b0624f067d5790f55c6694d95a78)
- Adding 'Mathematical Foundation' section to 'TECHNICAL_DOCUMENTATION.md' [`ec20636`](https://github.com/avoidwork/filesize.js/commit/ec206366285c6c6b4c29ccc87f6e5450ca128c79)
- Updating documentation [`ef70bf8`](https://github.com/avoidwork/filesize.js/commit/ef70bf8e7889e7f86bee32841ad0ec48faadc82a)

#### [11.0.2](https://github.com/avoidwork/filesize.js/compare/11.0.1...11.0.2)

> 16 July 2025

- Returning 'bigint' to 'filesize.d.ts' & fixing docblock [`#190`](https://github.com/avoidwork/filesize.js/pull/190)
- Updating CHANGELOG.md [`d9909d9`](https://github.com/avoidwork/filesize.js/commit/d9909d94113244c21f636ab6e049a56bf39be3e1)

#### [11.0.1](https://github.com/avoidwork/filesize.js/compare/11.0.0...11.0.1)

Expand Down
30 changes: 22 additions & 8 deletions dist/filesize.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* @copyright 2025 Jason Mulligan <jason.mulligan@avoidwork.com>
* @license BSD-3-Clause
* @version 11.0.2
* @version 11.0.4
*/
'use strict';

Expand Down Expand Up @@ -35,6 +35,7 @@ const EXPONENT = "exponent";
const ROUND = "round";

// Special Characters and Values
const E = "e";
const EMPTY = "";
const PERIOD = ".";
const S = "s";
Expand Down Expand Up @@ -166,9 +167,15 @@ function filesize (arg, {
// Zero is now a special case because bytes divide by 1
if (num === 0) {
result[0] = 0;

if (precision > 0) {
result[0] = result[0].toPrecision(precision);
}

u = result[1] = STRINGS.symbol[standard][bits ? BITS : BYTES][e];
} else {
val = num / (base === 2 ? Math.pow(2, e * 10) : Math.pow(1000, e));
let d = base === 2 ? Math.pow(2, e * 10) : Math.pow(1000, e);
val = num / d;

if (bits) {
val = val * 8;
Expand All @@ -179,14 +186,26 @@ function filesize (arg, {
}
}

const p = Math.pow(10, e > 0 ? round : 0);
let p = Math.pow(10, e > 0 ? round : 0);
result[0] = roundingFunc(val * p) / p;

if (result[0] === ceil && e < 8 && exponent === -1) {
result[0] = 1;
e++;
}

// Setting optional precision
if (precision > 0) {
result[0] = result[0].toPrecision(precision);

if (result[0].includes(E)) {
e++;
d = base === 2 ? Math.pow(2, e * 10) : Math.pow(1000, e);
val = num / d;
result[0] = roundingFunc(val * p) / p;
}
}

u = result[1] = base === 10 && e === 1 ? bits ? SI_KBIT : SI_KBYTE : STRINGS.symbol[standard][bits ? BITS : BYTES][e];
}

Expand All @@ -195,11 +214,6 @@ function filesize (arg, {
result[0] = -result[0];
}

// Setting optional precision
if (precision > 0) {
result[0] = result[0].toPrecision(precision);
}

// Applying custom symbol
result[1] = symbols[result[1]] || result[1];

Expand Down
30 changes: 22 additions & 8 deletions dist/filesize.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* @copyright 2025 Jason Mulligan <jason.mulligan@avoidwork.com>
* @license BSD-3-Clause
* @version 11.0.2
* @version 11.0.4
*/
// Error Messages
const INVALID_NUMBER = "Invalid number";
Expand Down Expand Up @@ -33,6 +33,7 @@ const EXPONENT = "exponent";
const ROUND = "round";

// Special Characters and Values
const E = "e";
const EMPTY = "";
const PERIOD = ".";
const S = "s";
Expand Down Expand Up @@ -162,9 +163,15 @@ function filesize (arg, {
// Zero is now a special case because bytes divide by 1
if (num === 0) {
result[0] = 0;

if (precision > 0) {
result[0] = result[0].toPrecision(precision);
}

u = result[1] = STRINGS.symbol[standard][bits ? BITS : BYTES][e];
} else {
val = num / (base === 2 ? Math.pow(2, e * 10) : Math.pow(1000, e));
let d = base === 2 ? Math.pow(2, e * 10) : Math.pow(1000, e);
val = num / d;

if (bits) {
val = val * 8;
Expand All @@ -175,14 +182,26 @@ function filesize (arg, {
}
}

const p = Math.pow(10, e > 0 ? round : 0);
let p = Math.pow(10, e > 0 ? round : 0);
result[0] = roundingFunc(val * p) / p;

if (result[0] === ceil && e < 8 && exponent === -1) {
result[0] = 1;
e++;
}

// Setting optional precision
if (precision > 0) {
result[0] = result[0].toPrecision(precision);

if (result[0].includes(E)) {
e++;
d = base === 2 ? Math.pow(2, e * 10) : Math.pow(1000, e);
val = num / d;
result[0] = roundingFunc(val * p) / p;
}
}

u = result[1] = base === 10 && e === 1 ? bits ? SI_KBIT : SI_KBYTE : STRINGS.symbol[standard][bits ? BITS : BYTES][e];
}

Expand All @@ -191,11 +210,6 @@ function filesize (arg, {
result[0] = -result[0];
}

// Setting optional precision
if (precision > 0) {
result[0] = result[0].toPrecision(precision);
}

// Applying custom symbol
result[1] = symbols[result[1]] || result[1];

Expand Down
4 changes: 2 additions & 2 deletions dist/filesize.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading