diff --git a/index.js b/index.js index c93a915..92278fe 100644 --- a/index.js +++ b/index.js @@ -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) { diff --git a/test.js b/test.js index e05648c..ed324e1 100644 --- a/test.js +++ b/test.js @@ -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)