(value: unknown, seen: unknown[])
| 119 | } |
| 120 | |
| 121 | const staticTextOf = (value: unknown, seen: unknown[]): string => { |
| 122 | if ( |
| 123 | value === null || |
| 124 | (typeof value !== "object" && typeof value !== "function") |
| 125 | ) { |
| 126 | return ( |
| 127 | typeof value === "string" ? JSON.stringify(value) |
| 128 | : typeof value === "bigint" ? `${value}n` |
| 129 | : Object.is(value, -0) ? "-0" |
| 130 | : String(value) |
| 131 | ) |
| 132 | } |
| 133 | // a repeated object is named by its first visit |
| 134 | const index = seen.indexOf(value) |
| 135 | if (index !== -1) return `#${index}` |
| 136 | seen.push(value) |
| 137 | if (typeof value === "function") return "function" |
| 138 | const tag = Object.prototype.toString.call(value) |
| 139 | const builtins = [ |
| 140 | null, |
| 141 | Object.prototype, |
| 142 | Array.prototype, |
| 143 | Date.prototype, |
| 144 | RegExp.prototype |
| 145 | ] |
| 146 | // inherited enumerable keys count too |
| 147 | const enumerable: PropertyKey[] = [] |
| 148 | for (const k in value) enumerable.push(k) |
| 149 | let entries = "" |
| 150 | for (const k of new Set([...enumerable, ...Reflect.ownKeys(value)])) { |
| 151 | entries += `${enumerable.includes(k) ? "" : "~"}${JSON.stringify( |
| 152 | // a symbol key prints as its registered name |
| 153 | typeof k === "symbol" ? [Symbol.keyFor(k)] : k |
| 154 | )}:${staticTextOf((value as Record<PropertyKey, unknown>)[k], seen)},` |
| 155 | } |
| 156 | // the prototype, since Symbol.toStringTag can fake the tag |
| 157 | return `${tag}${builtins.indexOf(Object.getPrototypeOf(value))}${ |
| 158 | tag === "[object Date]" ? Number(value) |
| 159 | : tag === "[object RegExp]" ? `${value}` |
| 160 | : "" |
| 161 | }{${entries}}` |
| 162 | } |
| 163 | |
| 164 | // satisfies keeps the parens prettier would drop |
| 165 | export const fixConfig = ((): void => { |
no test coverage detected