RepoPilot

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

About sindresorhus/pretty-bytes · 2 messages · last activity 7/20/2026

Question

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

RepoPilot

Based on the test suite, here are the edge cases tested:

Invalid Input Cases [test.js:L1-L40]:

  • Empty string ('')
  • String input ('1')
  • Number.NaN
  • Boolean (true)
  • Number.POSITIVE_INFINITY
  • Number.NEGATIVE_INFINITY
  • null

All of these throw errors when passed to prettyBytes().

Negative Numbers:

  • Negative regular numbers: prettyBytes(-0.4), prettyBytes(-13), prettyBytes(-1337) are tested in various contexts [test.js:L106-L127, L331]
  • Negative with signed option: prettyBytes(-13, {signed: true})'-13 B' [test.js:L124]
  • Negative with fixedWidth: prettyBytes(-1337, {fixedWidth: 8})'-1.34 kB' [test.js:L331]

Zero Edge Cases:

  • Zero with signed option produces a space prefix for alignment: prettyBytes(0, {signed: true})' 0 B' [test.js:L125]
  • Zero with signed and fixedWidth: prettyBytes(0, {fixedWidth: 8, signed: true})' 0 B' [test.js:L281]
  • Zero with nonBreakingSpace and signed: prettyBytes(0, {signed: true, nonBreakingSpace: true})' 0\u00A0B' [test.js:L256]

Small Fractional Numbers:

  • prettyBytes(0.4), prettyBytes(0.5), prettyBytes(0.7) are tested across different options [test.js:L108, L114, L328]

The main validation occurs in the main function [index.js:L125-L127], which throws a TypeError for non-finite numbers and non-bigint types.

FOLLOW_UPS:

  • How does the function handle bigint negative numbers?
  • What's the purpose of the space prefix for signed zero?
  • Are there tests for very large numbers beyond Yottabytes?

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.