Skip to content
Open
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
3 changes: 2 additions & 1 deletion src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/filesize-helpers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" });
});
});

Expand Down
18 changes: 18 additions & 0 deletions tests/unit/filesize.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down