RepoPilot

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

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

Question

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

RepoPilot

Based on the test file, here are the edge cases tested for invalid inputs:

Invalid Input Types and Values [test.js:L1-L35]:

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

Negative Numbers: Negative numbers are actually valid inputs. The signed option tests show that negative numbers work correctly:

  • [test.js:L128-L131]: prettyBytes(-13, {signed: true}) returns '-13 B'
  • [test.js:L331]: prettyBytes(-1337, {fixedWidth: 8}) returns '-1.34 kB'

Special Cases with Zero:

  • [test.js:L132]: When signed: true and the input is exactly 0, it returns ' 0 B' (space instead of + for alignment)
  • [test.js:L280]: prettyBytes(0, {fixedWidth: 8, signed: true}) returns ' 0 B'
  • [test.js:L252]: prettyBytes(0, {signed: true, nonBreakingSpace: true}) returns ' 0\u00A0B'

Invalid fixedWidth Values [test.js:L32-L35, L309-L325]:

  • Negative values: fixedWidth: -1 and fixedWidth: -5
  • Non-integer values: fixedWidth: 1.5 and fixedWidth: 3.5
  • Non-number types: fixedWidth: '10' (string)
  • Special numbers: Number.POSITIVE_INFINITY, Number.NaN
  • Values exceeding safe integer range: Number.MAX_SAFE_INTEGER + 1

FOLLOW_UPS:

  • How does the signed option work with zero?
  • What input types does prettyBytes accept?
  • Are there locale-specific edge cases tested?

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.