Question
What edge cases (negative, NaN, Infinity) are tested?
About sindresorhus/pretty-bytes · 2 messages · last activity 5/25/2026
What edge cases (negative, NaN, Infinity) are tested?
Based on the test file, here are the edge cases tested for invalid inputs:
Invalid Input Types and Values [test.js:L1-L35]:
'', '1')Number.NaNtrue)Number.POSITIVE_INFINITY and Number.NEGATIVE_INFINITYnullNegative Numbers:
Negative numbers are actually valid inputs. The signed option tests show that negative numbers work correctly:
prettyBytes(-13, {signed: true}) returns '-13 B'prettyBytes(-1337, {fixedWidth: 8}) returns '-1.34 kB'Special Cases with Zero:
signed: true and the input is exactly 0, it returns ' 0 B' (space instead of + for alignment)prettyBytes(0, {fixedWidth: 8, signed: true}) returns ' 0 B'prettyBytes(0, {signed: true, nonBreakingSpace: true}) returns ' 0\u00A0B'Invalid fixedWidth Values [test.js:L32-L35, L309-L325]:
fixedWidth: -1 and fixedWidth: -5fixedWidth: 1.5 and fixedWidth: 3.5fixedWidth: '10' (string)Number.POSITIVE_INFINITY, Number.NaNNumber.MAX_SAFE_INTEGER + 1FOLLOW_UPS:
Want to ask your own question?
Open chat for sindresorhus/pretty-bytes →Public 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.