(value: unknown, seen: WeakSet<object>, keyHint?: string)
| 11 | } |
| 12 | |
| 13 | function redactValue(value: unknown, seen: WeakSet<object>, keyHint?: string): unknown { |
| 14 | if (value === null || value === undefined) return value; |
| 15 | if (typeof value === 'string') return redactString(value, keyHint); |
| 16 | if (typeof value !== 'object') return value; |
| 17 | |
| 18 | if (seen.has(value as object)) return '[Circular]'; |
| 19 | seen.add(value as object); |
| 20 | |
| 21 | if (Array.isArray(value)) { |
| 22 | return value.map((entry) => redactValue(entry, seen)); |
| 23 | } |
| 24 | |
| 25 | const output: Record<string, unknown> = {}; |
| 26 | for (const [key, entry] of Object.entries(value as Record<string, unknown>)) { |
| 27 | if (SENSITIVE_KEY_RE.test(key)) { |
| 28 | output[key] = '[REDACTED]'; |
| 29 | continue; |
| 30 | } |
| 31 | output[key] = redactValue(entry, seen, key); |
| 32 | } |
| 33 | return output; |
| 34 | } |
| 35 | |
| 36 | function redactString(value: string, keyHint?: string): string { |
| 37 | const trimmed = value.trim(); |
no test coverage detected