Skip to content

Commit 67076e9

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

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

index.js

Lines changed: 8 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,8 +354,8 @@ 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+
if (value.length > maximumBreadth) {
358+
const removedKeys = value.length - maximumBreadth
359359
res += `${join}"... ${getItemCount(removedKeys)} not stringified"`
360360
}
361361
if (spacer !== '') {
@@ -444,8 +444,8 @@ function configure (options) {
444444
}
445445
const tmp = stringifyIndent(String(i), value[i], stack, spacer, indentation)
446446
res += tmp !== undefined ? tmp : 'null'
447-
if (value.length - 1 > maximumBreadth) {
448-
const removedKeys = value.length - maximumBreadth - 1
447+
if (value.length > maximumBreadth) {
448+
const removedKeys = value.length - maximumBreadth
449449
res += `${join}"... ${getItemCount(removedKeys)} not stringified"`
450450
}
451451
res += `\n${originalIndentation}`
@@ -553,8 +553,8 @@ function configure (options) {
553553
}
554554
const tmp = stringifySimple(String(i), value[i], stack)
555555
res += tmp !== undefined ? tmp : 'null'
556-
if (value.length - 1 > maximumBreadth) {
557-
const removedKeys = value.length - maximumBreadth - 1
556+
if (value.length > maximumBreadth) {
557+
const removedKeys = value.length - maximumBreadth
558558
res += `,"... ${getItemCount(removedKeys)} not stringified"`
559559
}
560560
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)