What edge cases (negative, NaN, Infinity) are tested?
What edge cases (negative, NaN, Infinity) are tested?
About sindresorhus/pretty-bytes · 2 messages · last activity 6/1/2026
Question
RepoPilot
The repository tests several important edge cases:
Invalid inputs that throw errors:
NaN:prettyBytes(Number.NaN)throws [test.js:L14]Infinity:prettyBytes(Number.POSITIVE_INFINITY)andprettyBytes(Number.NEGATIVE_INFINITY)both throw [test.js:L19-L23]nulland non-numeric types [test.js:L26]
Negative numbers (valid): The library supports negative numbers without throwing. Test cases include:
prettyBytes(-0.4)→'-0.4 B'[test.js:L58]prettyBytes(-999)→'-999 B'[test.js:L60]prettyBytes(-1001)→'-1 kB'[test.js:L61]- Negative numbers with
fixedWidthoption:prettyBytes(-1337, {fixedWidth: 8})→'-1.34 kB'[test.js:L329]
Signed zero handling:
When using the signed option with zero, it prepends a space for alignment rather than a plus sign:
prettyBytes(0, {fixedWidth: 8, signed: true})→' 0 B'[test.js:L278]
Invalid fixedWidth values (throw errors):
- Negative:
fixedWidth: -1or-5[test.js:L33, L306] - Non-integers:
fixedWidth: 1.5or3.5[test.js:L36, L315] InfinityandNaN[test.js:L310-L314]- Wrong type (string):
fixedWidth: '10'[test.js:L317]
The main validation logic is in [index.js:L98-L101], which ensures fixedWidth is a safe integer and non-negative.
FOLLOW_UPS:
- How does signed zero differ from regular zero?
- What types besides number and bigint are rejected?
- Does fixedWidth pad all results equally?
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.