(key, value, stack, spacer, indentation)
| 482 | * @param {string} indentation |
| 483 | */ |
| 484 | let stringifyIndent = function (key, value, stack, spacer, indentation) { |
| 485 | if (value === null) { |
| 486 | return 'null' |
| 487 | } |
| 488 | if (typeof /** @type {ToJSON} */ (value).toJSON === 'function') { |
| 489 | if (typeof key === 'number') key = String(key) |
| 490 | const jsonValue = safe ? callSafe(/** @type {ToJSON} */ (value).toJSON, value, key) : /** @type {ToJSON} */ (value).toJSON(key) |
| 491 | if (typeof jsonValue !== 'object') { |
| 492 | return stringifyPrimitive(jsonValue) |
| 493 | } |
| 494 | if (jsonValue === null) { |
| 495 | return 'null' |
| 496 | } |
| 497 | value = jsonValue |
| 498 | } |
| 499 | const circularIndex = stack.indexOf(value) |
| 500 | if (circularIndex !== -1) { |
| 501 | return typeof circularValue === 'function' ? circularValue(circularIndex) : circularValue |
| 502 | } |
| 503 | const originalIndentation = indentation |
| 504 | |
| 505 | if (Array.isArray(value)) { |
| 506 | if (value.length === 0) { |
| 507 | return '[]' |
| 508 | } |
| 509 | if (maximumDepth < stack.length + 1) { |
| 510 | return '"[Array]"' |
| 511 | } |
| 512 | stack.push(value) |
| 513 | indentation += spacer |
| 514 | let res = `\n${indentation}` |
| 515 | const join = `,\n${indentation}` |
| 516 | const maximumValuesToStringify = Math.min(value.length, maximumBreadth) |
| 517 | let i = 0 |
| 518 | for (; i < maximumValuesToStringify - 1; i++) { |
| 519 | const item = value[i] |
| 520 | const tmp = typeof item === 'object' ? stringifyIndent(i, item, stack, spacer, indentation) : stringifyPrimitive(item) |
| 521 | res += tmp !== undefined ? tmp : 'null' |
| 522 | res += join |
| 523 | } |
| 524 | const item = value[i] |
| 525 | const tmp = typeof item === 'object' ? stringifyIndent(i, item, stack, spacer, indentation) : stringifyPrimitive(item) |
| 526 | res += tmp !== undefined ? tmp : 'null' |
| 527 | if (value.length > maximumBreadth) { |
| 528 | const removedKeys = value.length - maximumBreadth |
| 529 | res += `${join}"... ${getItemCount(removedKeys)} not stringified"` |
| 530 | } |
| 531 | res += `\n${originalIndentation}` |
| 532 | stack.pop() |
| 533 | return `[${res}]` |
| 534 | } |
| 535 | |
| 536 | let keys = Object.keys(value) |
| 537 | const keyLength = keys.length |
| 538 | if (keyLength === 0) { |
| 539 | return '{}' |
| 540 | } |
| 541 | if (maximumDepth < stack.length + 1) { |
no test coverage detected