MCPcopy Index your code
hub / github.com/callstack/agent-device / redactValue

Function redactValue

src/kernel/redaction.ts:13–34  ·  view source on GitHub ↗
(value: unknown, seen: WeakSet<object>, keyHint?: string)

Source from the content-addressed store, hash-verified

11}
12
13function 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
36function redactString(value: string, keyHint?: string): string {
37 const trimmed = value.trim();

Callers 1

redactDiagnosticDataFunction · 0.70

Calls 1

redactStringFunction · 0.85

Tested by

no test coverage detected