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
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,17 @@ 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.21](https://github.com/avoidwork/filesize.js/compare/11.0.20...11.0.21)

- fix: honor the pad option for zero values [`#308`](https://github.com/avoidwork/filesize.js/pull/308)
- fix: return the final exponent from output 'exponent' [`#307`](https://github.com/avoidwork/filesize.js/pull/307)
- chore: update dependencies [`#310`](https://github.com/avoidwork/filesize.js/pull/310)

#### [11.0.20](https://github.com/avoidwork/filesize.js/compare/11.0.19...11.0.20)

> 9 July 2026

- chore: release v11.0.20 [`#309`](https://github.com/avoidwork/filesize.js/pull/309)
- fix(helpers): clamp negative forced exponent to 0 [`#304`](https://github.com/avoidwork/filesize.js/pull/304)
- chore(deps-dev): bump oxlint from 1.72.0 to 1.73.0 [`#306`](https://github.com/avoidwork/filesize.js/pull/306)
- chore(deps-dev): bump oxlint from 1.71.0 to 1.72.0 [`#303`](https://github.com/avoidwork/filesize.js/pull/303)
Expand Down
21 changes: 16 additions & 5 deletions dist/filesize.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* @copyright 2026 Jason Mulligan <jason.mulligan@avoidwork.com>
* @license BSD-3-Clause
* @version 11.0.20
* @version 11.0.21
*/
'use strict';

Expand Down Expand Up @@ -127,6 +127,8 @@ function getBaseConfiguration(standard, base) {
* @param {Array} fullforms - Custom full forms
* @param {string} output - Output format
* @param {string} spacer - Spacer character
* @param {boolean} pad - Whether to pad decimal places
* @param {number} round - Number of decimal places for padding
* @param {string} [symbol] - Symbol to use (defaults based on bits/standard)
* @returns {string|Array|Object|number} Formatted result
*/
Expand All @@ -139,11 +141,15 @@ function handleZeroValue(
fullforms,
output,
spacer,
pad,
round,
symbol,
) {
let value;
if (precision > 0) {
value = (0).toPrecision(precision);
} else if (pad && round > 0) {
value = (0).toFixed(round);
} else {
value = 0;
}
Expand Down Expand Up @@ -632,6 +638,8 @@ function filesize(
fullforms,
output,
spacer,
pad,
round,
);
}

Expand All @@ -646,10 +654,6 @@ function filesize(
e = calculatedE;
const autoExponent = exponent === -1 || isNaN(exponent);

if (output === EXPONENT) {
return e;
}

const { result: valueResult, e: valueExponent } = calculateOptimizedValue(
num,
e,
Expand Down Expand Up @@ -684,6 +688,13 @@ function filesize(
e = precisionResult.e;
}

// Return the exponent only after every adjustment that other output
// modes apply (bits auto-increment, rounding overflow, precision), so
// it always matches the exponent reported by object output.
if (output === EXPONENT) {
return e;
}

u = resolveSymbol(actualStandard, bits, e, isDecimal);
result[1] = u;

Expand Down
21 changes: 16 additions & 5 deletions dist/filesize.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* @copyright 2026 Jason Mulligan <jason.mulligan@avoidwork.com>
* @license BSD-3-Clause
* @version 11.0.20
* @version 11.0.21
*/
// Error Messages
const INVALID_NUMBER = "Invalid number";
Expand Down Expand Up @@ -123,6 +123,8 @@ function getBaseConfiguration(standard, base) {
* @param {Array} fullforms - Custom full forms
* @param {string} output - Output format
* @param {string} spacer - Spacer character
* @param {boolean} pad - Whether to pad decimal places
* @param {number} round - Number of decimal places for padding
* @param {string} [symbol] - Symbol to use (defaults based on bits/standard)
* @returns {string|Array|Object|number} Formatted result
*/
Expand All @@ -135,11 +137,15 @@ function handleZeroValue(
fullforms,
output,
spacer,
pad,
round,
symbol,
) {
let value;
if (precision > 0) {
value = (0).toPrecision(precision);
} else if (pad && round > 0) {
value = (0).toFixed(round);
} else {
value = 0;
}
Expand Down Expand Up @@ -626,6 +632,8 @@ function filesize(
fullforms,
output,
spacer,
pad,
round,
);
}

Expand All @@ -640,10 +648,6 @@ function filesize(
e = calculatedE;
const autoExponent = exponent === -1 || isNaN(exponent);

if (output === EXPONENT) {
return e;
}

const { result: valueResult, e: valueExponent } = calculateOptimizedValue(
num,
e,
Expand Down Expand Up @@ -678,6 +682,13 @@ function filesize(
e = precisionResult.e;
}

// Return the exponent only after every adjustment that other output
// modes apply (bits auto-increment, rounding overflow, precision), so
// it always matches the exponent reported by object output.
if (output === EXPONENT) {
return e;
}

u = resolveSymbol(actualStandard, bits, e, isDecimal);
result[1] = u;

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.

2 changes: 1 addition & 1 deletion dist/filesize.min.js.map

Large diffs are not rendered by default.

21 changes: 16 additions & 5 deletions dist/filesize.umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* @copyright 2026 Jason Mulligan <jason.mulligan@avoidwork.com>
* @license BSD-3-Clause
* @version 11.0.20
* @version 11.0.21
*/
(function(g,f){typeof exports==='object'&&typeof module!=='undefined'?f(exports):typeof define==='function'&&define.amd?define(['exports'],f):(g=typeof globalThis!=='undefined'?globalThis:g||self,f(g.filesize={}));})(this,(function(exports){'use strict';// Error Messages
const INVALID_NUMBER = "Invalid number";
Expand Down Expand Up @@ -123,6 +123,8 @@ function getBaseConfiguration(standard, base) {
* @param {Array} fullforms - Custom full forms
* @param {string} output - Output format
* @param {string} spacer - Spacer character
* @param {boolean} pad - Whether to pad decimal places
* @param {number} round - Number of decimal places for padding
* @param {string} [symbol] - Symbol to use (defaults based on bits/standard)
* @returns {string|Array|Object|number} Formatted result
*/
Expand All @@ -135,11 +137,15 @@ function handleZeroValue(
fullforms,
output,
spacer,
pad,
round,
symbol,
) {
let value;
if (precision > 0) {
value = (0).toPrecision(precision);
} else if (pad && round > 0) {
value = (0).toFixed(round);
} else {
value = 0;
}
Expand Down Expand Up @@ -626,6 +632,8 @@ function filesize(
fullforms,
output,
spacer,
pad,
round,
);
}

Expand All @@ -640,10 +648,6 @@ function filesize(
e = calculatedE;
const autoExponent = exponent === -1 || isNaN(exponent);

if (output === EXPONENT) {
return e;
}

const { result: valueResult, e: valueExponent } = calculateOptimizedValue(
num,
e,
Expand Down Expand Up @@ -678,6 +682,13 @@ function filesize(
e = precisionResult.e;
}

// Return the exponent only after every adjustment that other output
// modes apply (bits auto-increment, rounding overflow, precision), so
// it always matches the exponent reported by object output.
if (output === EXPONENT) {
return e;
}

u = resolveSymbol(actualStandard, bits, e, isDecimal);
result[1] = u;

Expand Down
Loading
Loading