Question
What edge cases (negative, NaN, Infinity) are tested?
About sindresorhus/pretty-bytes · 2 messages · last activity 7/13/2026
What edge cases (negative, NaN, Infinity) are tested?
The repository has comprehensive edge case testing for invalid inputs and special numeric values:
Invalid Input Types [test.js:L1-L40]:
null, and boolean true all throw errorsNumber.NaN, Number.POSITIVE_INFINITY, and Number.NEGATIVE_INFINITY all throw errorsNegative Numbers [test.js:L51-L60]:
-0.4, -0.7, -10.1-999, -1001-999n, -1001nSpecial Cases with Options:
prettyBytes(0, {signed: true}) returns ' 0 B' (space instead of plus sign for alignment)prettyBytes(-1337, {fixedWidth: 8}) returns '-1.34 kB' (no padding when output exceeds width)prettyBytes(0.5, {fixedWidth: 8}) returns ' 0.5 B'Invalid fixedWidth Values [test.js:L307-L325]:
-5 throws errorNumber.POSITIVE_INFINITY throws errorNumber.NaN throws error3.5 throws error'10' throws errorNumber.MAX_SAFE_INTEGER throw errorThe tests ensure the function rejects invalid inputs but handles legitimate negative numbers and decimal values gracefully.
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.