diff --git a/src/helpers.js b/src/helpers.js index 89b24bb..11602f3 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -125,6 +125,7 @@ export function handleZeroValue( ? STRINGS.symbol[actualStandard].bits[0] : STRINGS.symbol[actualStandard].bytes[0]; } + const unit = symbol; // Apply symbol customization if (symbols[symbol]) { @@ -151,7 +152,7 @@ export function handleZeroValue( } if (output === OBJECT) { - return { value, symbol, exponent: 0, unit: symbol }; + return { value, symbol, exponent: 0, unit }; } return value + spacer + symbol; diff --git a/tests/unit/filesize-helpers.test.js b/tests/unit/filesize-helpers.test.js index e9d8c00..bb581fc 100644 --- a/tests/unit/filesize-helpers.test.js +++ b/tests/unit/filesize-helpers.test.js @@ -365,7 +365,7 @@ describe("handleZeroValue with fullform and custom fullforms", () => { it("should use custom fullforms for object output", () => { const result = handleZeroValue(0, "jedec", false, {}, true, ["my byte"], "object", " "); - assert.deepStrictEqual(result, { value: 0, symbol: "my byte", exponent: 0, unit: "my byte" }); + assert.deepStrictEqual(result, { value: 0, symbol: "my byte", exponent: 0, unit: "B" }); }); }); diff --git a/tests/unit/filesize.test.js b/tests/unit/filesize.test.js index 73e3390..ffe815c 100644 --- a/tests/unit/filesize.test.js +++ b/tests/unit/filesize.test.js @@ -117,6 +117,24 @@ describe("filesize", () => { const result = filesize(0, { output: "object" }); assert.deepStrictEqual(result, { value: 0, symbol: "B", exponent: 0, unit: "B" }); }); + + it("should preserve the original unit when displaying a custom zero symbol", () => { + const options = { output: "object", symbols: { B: "octets" } }; + assert.deepStrictEqual(filesize(0, options), { + value: 0, + symbol: "octets", + exponent: 0, + unit: "B", + }); + assert.deepStrictEqual(filesize(0n, options), filesize(0, options)); + }); + + it("should preserve the original bit unit in full-form zero output", () => { + assert.deepStrictEqual( + filesize(0, { output: "object", bits: true, fullform: true, fullforms: ["custom bit"] }), + { value: 0, symbol: "custom bit", exponent: 0, unit: "bit" }, + ); + }); }); describe("Standards", () => {