Skip to content

Commit e66f5d4

Browse files
committed
fix: correct overflow info for arrays with maximumBreadth
1 parent bafd93d commit e66f5d4

2 files changed

Lines changed: 19 additions & 12 deletions

File tree

index.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,8 @@ function configure (options) {
246246
}
247247
const tmp = stringifyFnReplacer(String(i), value, stack, replacer, spacer, indentation)
248248
res += tmp !== undefined ? tmp : 'null'
249-
if (value.length - 1 > maximumBreadth) {
250-
const removedKeys = value.length - maximumBreadth - 1
249+
if (value.length > maximumBreadth) {
250+
const removedKeys = value.length - maximumBreadth
251251
res += `${join}"... ${getItemCount(removedKeys)} not stringified"`
252252
}
253253
if (spacer !== '') {
@@ -354,10 +354,12 @@ function configure (options) {
354354
}
355355
const tmp = stringifyArrayReplacer(String(i), value[i], stack, replacer, spacer, indentation)
356356
res += tmp !== undefined ? tmp : 'null'
357-
if (value.length - 1 > maximumBreadth) {
358-
const removedKeys = value.length - maximumBreadth - 1
357+
358+
if (value.length > maximumBreadth) {
359+
const removedKeys = value.length - maximumBreadth
359360
res += `${join}"... ${getItemCount(removedKeys)} not stringified"`
360361
}
362+
361363
if (spacer !== '') {
362364
res += `\n${originalIndentation}`
363365
}
@@ -444,10 +446,12 @@ function configure (options) {
444446
}
445447
const tmp = stringifyIndent(String(i), value[i], stack, spacer, indentation)
446448
res += tmp !== undefined ? tmp : 'null'
447-
if (value.length - 1 > maximumBreadth) {
448-
const removedKeys = value.length - maximumBreadth - 1
449+
450+
if (value.length > maximumBreadth) {
451+
const removedKeys = value.length - maximumBreadth
449452
res += `${join}"... ${getItemCount(removedKeys)} not stringified"`
450453
}
454+
451455
res += `\n${originalIndentation}`
452456
stack.pop()
453457
return `[${res}]`
@@ -553,8 +557,8 @@ function configure (options) {
553557
}
554558
const tmp = stringifySimple(String(i), value[i], stack)
555559
res += tmp !== undefined ? tmp : 'null'
556-
if (value.length - 1 > maximumBreadth) {
557-
const removedKeys = value.length - maximumBreadth - 1
560+
if (value.length > maximumBreadth) {
561+
const removedKeys = value.length - maximumBreadth
558562
res += `,"... ${getItemCount(removedKeys)} not stringified"`
559563
}
560564
stack.pop()

test.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -911,18 +911,18 @@ test('maximumBreadth config', function (assert) {
911911
})
912912

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

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

919919
const res3 = serialize(obj, null, 2)
920920
assert.equal(res3, `{
921921
"a": [
922922
"a",
923923
"b",
924924
"c",
925-
"... 1 item not stringified"
925+
"... 2 items not stringified"
926926
]
927927
}`)
928928

@@ -936,6 +936,9 @@ test('maximumBreadth config', function (assert) {
936936
}
937937
}`)
938938

939+
const res5 = serialize(['a', 'b', 'c', 'd'])
940+
assert.equal(res5, '["a","b","c","... 1 item not stringified"]')
941+
939942
assert.end()
940943
})
941944
test('limit number of keys with array replacer', function (assert) {
@@ -976,7 +979,7 @@ test('limit number of keys in array', (assert) => {
976979
arr.push(i)
977980
}
978981
const res = serialize(arr)
979-
const expected = '[0,1,2,"... 96 items not stringified"]'
982+
const expected = '[0,1,2,"... 97 items not stringified"]'
980983
assert.equal(res, expected)
981984
assert.end()
982985
})

0 commit comments

Comments
 (0)