Question
What edge cases (negative, NaN, Infinity) are tested?
About sindresorhus/pretty-bytes · 2 messages · last activity 5/18/2026
What edge cases (negative, NaN, Infinity) are tested?
The repository tests several edge cases for invalid inputs and numeric edge cases:
Invalid inputs that throw errors [test.js:L1-L40]:
prettyBytes(''), prettyBytes('1'))Number.NaNtrue)Number.POSITIVE_INFINITY and Number.NEGATIVE_INFINITYnullfixedWidth values (e.g., -1, -5)fixedWidth values (e.g., 1.5, 3.5)fixedWidth types (e.g., strings like '10')fixedWidth values exceeding Number.MAX_SAFE_INTEGERNegative 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'bigint variants like -999n, -1001nSpecial 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:
signed option for positive numbers?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.