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
16 changes: 8 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ function configure (options) {
}
const tmp = stringifyFnReplacer(String(i), value, stack, replacer, spacer, indentation)
res += tmp !== undefined ? tmp : 'null'
if (value.length - 1 > maximumBreadth) {
const removedKeys = value.length - maximumBreadth - 1
if (value.length > maximumBreadth) {
const removedKeys = value.length - maximumBreadth
res += `${join}"... ${getItemCount(removedKeys)} not stringified"`
}
if (spacer !== '') {
Expand Down Expand Up @@ -354,8 +354,8 @@ function configure (options) {
}
const tmp = stringifyArrayReplacer(String(i), value[i], stack, replacer, spacer, indentation)
res += tmp !== undefined ? tmp : 'null'
if (value.length - 1 > maximumBreadth) {
const removedKeys = value.length - maximumBreadth - 1
if (value.length > maximumBreadth) {
const removedKeys = value.length - maximumBreadth
res += `${join}"... ${getItemCount(removedKeys)} not stringified"`
}
if (spacer !== '') {
Expand Down Expand Up @@ -444,8 +444,8 @@ function configure (options) {
}
const tmp = stringifyIndent(String(i), value[i], stack, spacer, indentation)
res += tmp !== undefined ? tmp : 'null'
if (value.length - 1 > maximumBreadth) {
const removedKeys = value.length - maximumBreadth - 1
if (value.length > maximumBreadth) {
const removedKeys = value.length - maximumBreadth
res += `${join}"... ${getItemCount(removedKeys)} not stringified"`
}
res += `\n${originalIndentation}`
Expand Down Expand Up @@ -553,8 +553,8 @@ function configure (options) {
}
const tmp = stringifySimple(String(i), value[i], stack)
res += tmp !== undefined ? tmp : 'null'
if (value.length - 1 > maximumBreadth) {
const removedKeys = value.length - maximumBreadth - 1
if (value.length > maximumBreadth) {
const removedKeys = value.length - maximumBreadth
res += `,"... ${getItemCount(removedKeys)} not stringified"`
}
stack.pop()
Expand Down
11 changes: 7 additions & 4 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -911,18 +911,18 @@ test('maximumBreadth config', function (assert) {
})

const result = serialize(obj, (key, val) => val)
assert.equal(result, '{"a":["a","b","c","... 1 item not stringified"]}')
assert.equal(result, '{"a":["a","b","c","... 2 items not stringified"]}')

const res2 = serialize(obj, ['a', 'b'])
assert.equal(res2, '{"a":["a","b","c","... 1 item not stringified"]}')
assert.equal(res2, '{"a":["a","b","c","... 2 items not stringified"]}')

const res3 = serialize(obj, null, 2)
assert.equal(res3, `{
"a": [
"a",
"b",
"c",
"... 1 item not stringified"
"... 2 items not stringified"
]
}`)

Expand All @@ -936,6 +936,9 @@ test('maximumBreadth config', function (assert) {
}
}`)

const res5 = serialize(['a', 'b', 'c', 'd'])
assert.equal(res5, '["a","b","c","... 1 item not stringified"]')

assert.end()
})
test('limit number of keys with array replacer', function (assert) {
Expand Down Expand Up @@ -976,7 +979,7 @@ test('limit number of keys in array', (assert) => {
arr.push(i)
}
const res = serialize(arr)
const expected = '[0,1,2,"... 96 items not stringified"]'
const expected = '[0,1,2,"... 97 items not stringified"]'
assert.equal(res, expected)
assert.end()
})
Expand Down
Loading