({
from,
seen,
to,
forceEnumerable,
maxDepth,
depth,
useToJSON,
serialize,
})
| 83 | |
| 84 | // eslint-disable-next-line complexity |
| 85 | const destroyCircular = ({ |
| 86 | from, |
| 87 | seen, |
| 88 | to, |
| 89 | forceEnumerable, |
| 90 | maxDepth, |
| 91 | depth, |
| 92 | useToJSON, |
| 93 | serialize, |
| 94 | }) => { |
| 95 | if (!to) { |
| 96 | if (Array.isArray(from)) { |
| 97 | to = []; |
| 98 | } else if (!serialize && isErrorLike(from)) { |
| 99 | const Error = getErrorConstructor(from.name); |
| 100 | to = new Error(); |
| 101 | } else { |
| 102 | to = {}; |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | seen.push(from); |
| 107 | |
| 108 | if (depth >= maxDepth) { |
| 109 | return to; |
| 110 | } |
| 111 | |
| 112 | if ( |
| 113 | useToJSON && |
| 114 | typeof from.toJSON === "function" && |
| 115 | !toJsonWasCalled.has(from) |
| 116 | ) { |
| 117 | return toJSON(from); |
| 118 | } |
| 119 | |
| 120 | const continueDestroyCircular = (value) => |
| 121 | destroyCircular({ |
| 122 | from: value, |
| 123 | seen: [...seen], |
| 124 | forceEnumerable, |
| 125 | maxDepth, |
| 126 | depth, |
| 127 | useToJSON, |
| 128 | serialize, |
| 129 | }); |
| 130 | |
| 131 | for (const [key, value] of Object.entries(from)) { |
| 132 | // eslint-disable-next-line node/prefer-global/buffer |
| 133 | if (typeof Buffer === "function" && Buffer.isBuffer(value)) { |
| 134 | to[key] = "[object Buffer]"; |
| 135 | continue; |
| 136 | } |
| 137 | |
| 138 | // TODO: Use `stream.isReadable()` when targeting Node.js 18. |
| 139 | if ( |
| 140 | value !== null && |
| 141 | typeof value === "object" && |
| 142 | typeof value.pipe === "function" |
no test coverage detected