(options)
| 267 | } |
| 268 | |
| 269 | function configure (options) { |
| 270 | options = { ...options } |
| 271 | const fail = getStrictOption(options) |
| 272 | if (fail) { |
| 273 | if (options.bigint === undefined) { |
| 274 | options.bigint = false |
| 275 | } |
| 276 | if (!('circularValue' in options)) { |
| 277 | options.circularValue = Error |
| 278 | } |
| 279 | } |
| 280 | const circularValue = getCircularValueOption(options) |
| 281 | const bigint = getBigIntOption(options) |
| 282 | const deterministic = getDeterministicOption(options) |
| 283 | const comparator = typeof deterministic === 'function' ? deterministic : undefined |
| 284 | const maximumDepth = getPositiveIntegerOption(options, 'maximumDepth') |
| 285 | const maximumBreadth = getPositiveIntegerOption(options, 'maximumBreadth') |
| 286 | const safe = getBooleanOption(options, 'safe', false) |
| 287 | const failTypedArray = safe && fail ? makeSafe(fail) : fail |
| 288 | |
| 289 | let stringifyFnReplacer = function (key, parent, stack, replacer, spacer, indentation) { |
| 290 | let value = parent[key] |
| 291 | |
| 292 | if (typeof value === 'object' && value !== null && typeof value.toJSON === 'function') { |
| 293 | value = safe ? callSafe(value.toJSON, value, key) : value.toJSON(key) |
| 294 | } |
| 295 | value = replacer.call(parent, key, value) |
| 296 | |
| 297 | if (typeof value === 'object') { |
| 298 | if (value === null) { |
| 299 | return 'null' |
| 300 | } |
| 301 | const circularIndex = stack.indexOf(value) |
| 302 | if (circularIndex !== -1) { |
| 303 | return typeof circularValue === 'function' ? circularValue(circularIndex) : circularValue |
| 304 | } |
| 305 | |
| 306 | let res = '' |
| 307 | let join = ',' |
| 308 | const originalIndentation = indentation |
| 309 | |
| 310 | if (Array.isArray(value)) { |
| 311 | if (value.length === 0) { |
| 312 | return '[]' |
| 313 | } |
| 314 | if (maximumDepth < stack.length + 1) { |
| 315 | return '"[Array]"' |
| 316 | } |
| 317 | stack.push(value) |
| 318 | if (spacer !== '') { |
| 319 | indentation += spacer |
| 320 | res += `\n${indentation}` |
| 321 | join = `,\n${indentation}` |
| 322 | } |
| 323 | const maximumValuesToStringify = Math.min(value.length, maximumBreadth) |
| 324 | let i = 0 |
| 325 | for (; i < maximumValuesToStringify - 1; i++) { |
| 326 | const tmp = stringifyFnReplacer(String(i), value, stack, replacer, spacer, indentation) |
no test coverage detected