RepoPilot

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

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

Question

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

RepoPilot

The repository tests several important edge cases for invalid and special numeric inputs:

Invalid inputs that throw errors [test.js:L1-L40]:

  • Empty strings and string values ('', '1')
  • Number.NaN
  • Boolean values (true)
  • Number.POSITIVE_INFINITY
  • Number.NEGATIVE_INFINITY
  • null

Negative number support [test.js:L56-L62]: The library supports negative numbers and converts them correctly:

  • prettyBytes(-0.4)'-0.4 B'
  • prettyBytes(-999)'-999 B'
  • prettyBytes(-1001)'-1 kB'
  • prettyBytes(-1001n)'-1 kB' (with BigInt)

Edge cases with fixedWidth and signed options [test.js:L281-L340]:

  • Signed zero: prettyBytes(0, {fixedWidth: 8, signed: true})' 0 B' (space instead of + for alignment)
  • Negative numbers with fixedWidth: prettyBytes(-1337, {fixedWidth: 8})'-1.34 kB'
  • Very small decimals: prettyBytes(0.5, {fixedWidth: 8})' 0.5 B'

Input validation for fixedWidth [test.js:L303-L320]:

  • Negative values throw: fixedWidth: -5
  • Non-integer values throw: fixedWidth: 3.5
  • Number.POSITIVE_INFINITY throws
  • Number.NaN throws
  • String values throw: fixedWidth: '10'
  • Values exceeding Number.MAX_SAFE_INTEGER throw

The main validation logic is in [index.js:L124-L127], which ensures the input is a finite number or BigInt.

FOLLOW_UPS:

  • How does the signed option affect output formatting?
  • What locales are supported for output?
  • How does the binary option differ from default behavior?

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.