RepoPilot

What edge cases (negative, NaN, Infinity) are tested?

About sindresorhus/pretty-bytes · 2 messages · last activity 6/1/2026

Question

What edge cases (negative, NaN, Infinity) are tested?

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) and prettyBytes(Number.NEGATIVE_INFINITY) both throw [test.js:L19-L23]
  • null and 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 fixedWidth option: 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: -1 or -5 [test.js:L33, L306]
  • Non-integers: fixedWidth: 1.5 or 3.5 [test.js:L36, L315]
  • Infinity and NaN [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.