Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ function getPositiveIntegerOption (options, key) {
if (typeof value !== 'number') {
throw new TypeError(`The "${key}" argument must be of type number`)
}
if (!Number.isInteger(value)) {
// Infinity is the documented default, so it is accepted as well.
if (!Number.isInteger(value) && value !== Infinity) {
throw new TypeError(`The "${key}" argument must be an integer`)
}
if (value < 1) {
Expand Down
13 changes: 13 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1676,6 +1676,19 @@ test('should throw when maximumBreadth receives malformed input', (assert) => {
assert.end()
})

test('maximumDepth and maximumBreadth accept the default Infinity', (assert) => {
const input = { a: [1, 2, 3, { b: { c: [4, 5] } }], d: 6 }
const expected = stringify.configure({})(input)
assert.equal(stringify.configure({ maximumDepth: Infinity })(input), expected)
assert.equal(stringify.configure({ maximumBreadth: Infinity })(input), expected)
assert.equal(stringify.configure({ maximumDepth: Infinity, maximumBreadth: Infinity })(input, null, 2), stringify(input, null, 2))
for (const value of [-Infinity, NaN]) {
assert.throws(() => stringify.configure({ maximumDepth: value }))
assert.throws(() => stringify.configure({ maximumBreadth: value }))
}
assert.end()
})

test('check that all single characters are identical to JSON.stringify', (assert) => {
for (let i = 0; i < 2 ** 16; i++) {
const string = String.fromCharCode(i)
Expand Down
Loading