RepoPilot

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

About sindresorhus/pretty-bytes · 2 messages · last activity 5/18/2026

Question

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

RepoPilot

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

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

  • Empty strings and non-numeric strings (prettyBytes(''), prettyBytes('1'))
  • Number.NaN
  • Boolean values (true)
  • Number.POSITIVE_INFINITY and Number.NEGATIVE_INFINITY
  • null
  • Negative fixedWidth values (e.g., -1, -5)
  • Non-integer fixedWidth values (e.g., 1.5, 3.5)
  • Invalid fixedWidth types (e.g., strings like '10')
  • fixedWidth values exceeding Number.MAX_SAFE_INTEGER

Negative numbers (valid, no error) [test.js:L55-L61]:

  • prettyBytes(-0.4)'-0.4 B'
  • prettyBytes(-0.7)'-0.7 B'
  • prettyBytes(-10.1)'-10.1 B'
  • prettyBytes(-999)'-999 B'
  • prettyBytes(-1001)'-1 kB'
  • Also tested with bigint variants like -999n, -1001n

Special zero case with signed option [test.js:L281]:

  • prettyBytes(0, {fixedWidth: 8, signed: true})' 0 B' (space prefix instead of plus sign for alignment)

The main validation occurs in [index.js:L124-L127], which throws a TypeError if the input is not a finite number or bigint.

FOLLOW_UPS:

  • How does prettyBytes handle the signed option for positive numbers?
  • What are the different unit systems (BYTE_UNITS, BIT_UNITS, etc.)?
  • How does the locale option affect output formatting?

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.