Skip to content

fix: accept Infinity for maximumDepth and maximumBreadth - #85

Merged
BridgeAR merged 1 commit into
BridgeAR:mainfrom
bardrop-oss:fix-infinity-depth-breadth
Nov 18, 2026
Merged

BridgeAR merged 1 commit into
BridgeAR:mainfrom
bardrop-oss:fix-infinity-depth-breadth

Conversation

@bardrop

@bardrop bardrop commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

The readme lists Infinity as the default for maximumDepth and maximumBreadth, but passing it explicitly throws:

const { configure } = require('safe-stable-stringify')

configure({ maximumDepth: Infinity })
// TypeError: The "maximumDepth" argument must be an integer

This bites code that forwards an optional limit with the default as fallback, e.g. configure({ maximumDepth: options.depth ?? Infinity }).

The fix: getPositiveIntegerOption also accepts Infinity, which gives the same result as leaving the option out. -Infinity, NaN, non-integers and values below 1 still throw as before.

Tests: a new test checks that Infinity gives the same output as the default for both options (also with indentation), and that -Infinity / NaN still throw. It fails without the change. npm test (standard + tap, 100% coverage) and npm run tsc pass.

Infinity is the documented default of both options, but passing it
explicitly threw "must be an integer". Code that forwards an optional
limit with a fallback, like `maximumDepth: depth ?? Infinity`, broke
on configure().

@BridgeAR BridgeAR left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you

@BridgeAR
BridgeAR merged commit 5e175e3 into BridgeAR:main Nov 18, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants