RepoPilot

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

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

Question

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

RepoPilot

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

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

  • Empty strings and string inputs throw errors
  • Number.NaN throws a TypeError
  • Boolean values (true) throw errors
  • Number.POSITIVE_INFINITY and Number.NEGATIVE_INFINITY throw errors
  • null throws errors

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

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

The main function validates input in [index.js:L124-L126]:

if (typeof number !== 'bigint' && !Number.isFinite(number)) {
	throw new TypeError(`Expected a finite number, got ${typeof number}: ${number}`);
}

This check ensures that only finite numbers (or bigint) are accepted, explicitly rejecting NaN, Infinity, and -Infinity.

Fixed Width with Negatives [test.js:L328]: The library also tests negative numbers with fixedWidth enabled:

  • prettyBytes(-1337, {fixedWidth: 8})'-1.34 kB'

Signed Zero [index.js:L145-L149]: There's special handling for zero with the signed option, which prepends a space instead of a plus sign for alignment purposes.

FOLLOW_UPS:

  • How does the signed option handle positive vs negative values?
  • What happens with very large numbers and bigint?
  • 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.