(key, value, stack, spacer, indentation)
| 388 | } |
| 389 | |
| 390 | function stringifyIndent (key, value, stack, spacer, indentation) { |
| 391 | switch (typeof value) { |
| 392 | case 'string': |
| 393 | return strEscape(value) |
| 394 | case 'object': { |
| 395 | if (value === null) { |
| 396 | return 'null' |
| 397 | } |
| 398 | if (typeof value.toJSON === 'function') { |
| 399 | value = value.toJSON(key) |
| 400 | // Prevent calling `toJSON` again. |
| 401 | if (typeof value !== 'object') { |
| 402 | return stringifyIndent(key, value, stack, spacer, indentation) |
| 403 | } |
| 404 | if (value === null) { |
| 405 | return 'null' |
| 406 | } |
| 407 | } |
| 408 | if (stack.indexOf(value) !== -1) { |
| 409 | return circularValue |
| 410 | } |
| 411 | const originalIndentation = indentation |
| 412 | |
| 413 | if (Array.isArray(value)) { |
| 414 | if (value.length === 0) { |
| 415 | return '[]' |
| 416 | } |
| 417 | if (maximumDepth < stack.length + 1) { |
| 418 | return '"[Array]"' |
| 419 | } |
| 420 | stack.push(value) |
| 421 | indentation += spacer |
| 422 | let res = `\n${indentation}` |
| 423 | const join = `,\n${indentation}` |
| 424 | const maximumValuesToStringify = Math.min(value.length, maximumBreadth) |
| 425 | let i = 0 |
| 426 | for (; i < maximumValuesToStringify - 1; i++) { |
| 427 | const tmp = stringifyIndent(String(i), value[i], stack, spacer, indentation) |
| 428 | res += tmp !== undefined ? tmp : 'null' |
| 429 | res += join |
| 430 | } |
| 431 | const tmp = stringifyIndent(String(i), value[i], stack, spacer, indentation) |
| 432 | res += tmp !== undefined ? tmp : 'null' |
| 433 | if (value.length - 1 > maximumBreadth) { |
| 434 | const removedKeys = value.length - maximumBreadth - 1 |
| 435 | res += `${join}"... ${getItemCount(removedKeys)} not stringified"` |
| 436 | } |
| 437 | res += `\n${originalIndentation}` |
| 438 | stack.pop() |
| 439 | return `[${res}]` |
| 440 | } |
| 441 | |
| 442 | let keys = Object.keys(value) |
| 443 | const keyLength = keys.length |
| 444 | if (keyLength === 0) { |
| 445 | return '{}' |
| 446 | } |
| 447 | if (maximumDepth < stack.length + 1) { |
no test coverage detected
searching dependent graphs…