MCPcopy Create free account
hub / github.com/anus-dev/ANUS / safeJsonStringify

Function safeJsonStringify

packages/core/src/utils/safeJsonStringify.ts:15–33  ·  view source on GitHub ↗
(
  obj: unknown,
  space?: string | number,
)

Source from the content-addressed store, hash-verified

13 * @returns JSON string with circular references replaced by [Circular]
14 */
15export function safeJsonStringify(
16 obj: unknown,
17 space?: string | number,
18): string {
19 const seen = new WeakSet();
20 return JSON.stringify(
21 obj,
22 (key, value) => {
23 if (typeof value === 'object' && value !== null) {
24 if (seen.has(value)) {
25 return '[Circular]';
26 }
27 seen.add(value);
28 }
29 return value;
30 },
31 space,
32 );
33}

Callers 4

logToolCallFunction · 0.85
enqueueLogEventMethod · 0.85
flushToClearcutMethod · 0.85

Calls 1

addMethod · 0.80

Tested by

no test coverage detected