Skip to content
Open
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: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,9 @@ function configure (options) {
stack.pop()
return `[${res}]`
}
if (maximumDepth < stack.length + 1) {
return '"[Object]"'
}
stack.push(value)
let whitespace = ''
if (spacer !== '') {
Expand Down
8 changes: 7 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -910,11 +910,17 @@ test('maximumDepth config', function (assert) {
assert.equal(result, '{"a":{"a":"[Array]","b":"[Object]"}}')

const res2 = serialize(obj, ['a', 'b'])
assert.equal(res2, '{"a":{"a":"[Array]","b":{}}}')
assert.equal(res2, '{"a":{"a":"[Array]","b":"[Object]"}}')

const json = JSON.stringify(obj, ['a', 'b'])
assert.equal(json, '{"a":{"a":[1,2,3],"b":{}}}')

const serializeDepth1 = stringify.configure({
maximumDepth: 1
})
const resDepth1 = serializeDepth1(obj, ['a', 'b'])
assert.equal(resDepth1, '{"a":"[Object]"}')

const res3 = serialize(obj, null, 2)
assert.equal(res3, `{
"a": {
Expand Down