What edge cases (negative, NaN, Infinity) are tested?
What edge cases (negative, NaN, Infinity) are tested?
About sindresorhus/pretty-bytes · 2 messages · last activity 7/27/2026
The test suite covers several edge cases related to invalid inputs and special numeric values:
Invalid inputs that throw:
- Empty strings and non-numeric strings [test.js:L4-L9]
Number.NaN[test.js:L11-L13]- Booleans (
true) [test.js:L15-L17] Number.POSITIVE_INFINITYandNumber.NEGATIVE_INFINITY[test.js:L19-L26]null[test.js:L28-L30]
Invalid fixedWidth values that throw:
- Negative
fixedWidth(e.g.,-1,-5) [test.js:L32-L34 and L316-L319] - Non-integer
fixedWidth(e.g.,1.5,3.5) [test.js:L36-L38 and L327-L329] Number.POSITIVE_INFINITYforfixedWidth[test.js:L321-L324]Number.NaNforfixedWidth[test.js:L325-L328]- Non-number types like strings for
fixedWidth[test.js:L330-L333]
Negative numbers (valid):
The function supports negative inputs: prettyBytes(-0.4) returns '-0.4 B', prettyBytes(-999) returns '-999 B', and prettyBytes(-1001) returns '-1 kB' [test.js:L55-L61].
Zero and near-zero:
The function handles 0, 0.4, 0.7 correctly [test.js:L47-L50], and also has special handling for signed zero with padding [test.js:L280].
FOLLOW_UPS:
- How does the signed option affect output formatting?
- What locales are supported by the library?
- How are precision and rounding determined?
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.