feat: handle incorrect sizes
This commit is contained in:
parent
2bd495cec1
commit
7b6f56ef61
|
@ -7,6 +7,10 @@
|
||||||
const SizeFormatHelpers = exports;
|
const SizeFormatHelpers = exports;
|
||||||
|
|
||||||
SizeFormatHelpers.formatSize = size => {
|
SizeFormatHelpers.formatSize = size => {
|
||||||
|
if (typeof size !== "number" || Number.isNaN(size) === true) {
|
||||||
|
return "unknown size";
|
||||||
|
}
|
||||||
|
|
||||||
if (size <= 0) {
|
if (size <= 0) {
|
||||||
return "0 bytes";
|
return "0 bytes";
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,5 +43,10 @@ describe("SizeFormatHelpers", () => {
|
||||||
"1.2 GiB"
|
"1.2 GiB"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should handle undefined/NaN", () => {
|
||||||
|
should(SizeFormatHelpers.formatSize(undefined)).be.eql("unknown size");
|
||||||
|
should(SizeFormatHelpers.formatSize(NaN)).be.eql("unknown size");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue