MCPcopy Create free account
hub / github.com/effect-app/libs / formatJson

Function formatJson

repos/effect/packages/effect/src/Formatter.ts:297–319  ·  view source on GitHub ↗
(input: unknown, options?: {
  readonly space?: number | string | undefined
})

Source from the content-addressed store, hash-verified

295export function formatJson(input: unknown, options?: {
296 readonly space?: number | string | undefined
297}): string {
298 const ancestors: Array<object> = []
299 return JSON.stringify(
300 input,
301 function(this: unknown, _key: string, value: unknown) {
302 const redacted = redact(value)
303 if (typeof redacted !== "object" || redacted === null) {
304 return redacted
305 }
306 while (ancestors.length > 0 && ancestors[ancestors.length - 1] !== this) {
307 ancestors.pop()
308 }
309 if (ancestors.includes(redacted)) {
310 return undefined // circular reference
311 }
312 ancestors.push(redacted)
313 return redacted
314 },
315 options?.space
316 ) ?? "null"
317}

Callers 5

Formatter.test.tsFile · 0.90
toStringUnknownFunction · 0.90
encodeUnknownAsJsonFunction · 0.90
causePrettyErrorFunction · 0.90
causePrettyMessageFunction · 0.90

Calls 2

redactFunction · 0.90
pushMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…