Question
What edge cases (negative, NaN, Infinity) are tested?
About sindresorhus/pretty-bytes · 2 messages · last activity 7/20/2026
What edge cases (negative, NaN, Infinity) are tested?
Based on the test suite, here are the edge cases tested:
Invalid Input Cases [test.js:L1-L40]:
'')'1')Number.NaNtrue)Number.POSITIVE_INFINITYNumber.NEGATIVE_INFINITYnullAll of these throw errors when passed to prettyBytes().
Negative Numbers:
prettyBytes(-0.4), prettyBytes(-13), prettyBytes(-1337) are tested in various contexts [test.js:L106-L127, L331]signed option: prettyBytes(-13, {signed: true}) → '-13 B' [test.js:L124]fixedWidth: prettyBytes(-1337, {fixedWidth: 8}) → '-1.34 kB' [test.js:L331]Zero Edge Cases:
signed option produces a space prefix for alignment: prettyBytes(0, {signed: true}) → ' 0 B' [test.js:L125]signed and fixedWidth: prettyBytes(0, {fixedWidth: 8, signed: true}) → ' 0 B' [test.js:L281]nonBreakingSpace and signed: prettyBytes(0, {signed: true, nonBreakingSpace: true}) → ' 0\u00A0B' [test.js:L256]Small Fractional Numbers:
prettyBytes(0.4), prettyBytes(0.5), prettyBytes(0.7) are tested across different options [test.js:L108, L114, L328]The main validation occurs in the main function [index.js:L125-L127], which throws a TypeError for non-finite numbers and non-bigint types.
FOLLOW_UPS:
Want to ask your own question?
Open chat for sindresorhus/pretty-bytesPublic Q&A. Generated by RepoPilot from the actual source of sindresorhus/pretty-bytes. AI answers can be incomplete or stale — verify before relying on them.