RepoPilot

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

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

Question

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

RepoPilot

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

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

  • Empty strings and non-numeric strings
  • Number.NaN
  • Booleans (true)
  • Number.POSITIVE_INFINITY and Number.NEGATIVE_INFINITY
  • null
  • Invalid fixedWidth values (negative numbers, non-integers, non-numeric types)

Negative numbers [test.js:L59-L66]: The function supports negative numbers and formats them with a minus sign:

  • prettyBytes(-0.4)'-0.4 B'
  • prettyBytes(-10.1)'-10.1 B'
  • prettyBytes(-1001)'-1 kB'
  • Works with both regular numbers and bigint

Special zero handling with signed option [test.js:L281]: When using the signed option with zero, a space character is prepended instead of a plus sign for alignment:

  • prettyBytes(0, {fixedWidth: 8, signed: true})' 0 B'
  • prettyBytes(0, {signed: true, nonBreakingSpace: true})' 0\u00A0B'

Invalid fixedWidth cases [test.js:L316-L340]:

  • Negative numbers: fixedWidth: -5
  • Infinity and NaN
  • Fractional numbers: fixedWidth: 3.5
  • Wrong types: fixedWidth: '10' (string instead of number)
  • Values exceeding Number.MAX_SAFE_INTEGER

FOLLOW_UPS:

  • How does the function handle very large numbers?
  • What localization options does the library support?
  • How does the fixedWidth padding alignment work?

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.