(input: unknown, options?: {
readonly space?: number | string | undefined
})
| 282 | * @since 4.0.0 |
| 283 | */ |
| 284 | export function formatJson(input: unknown, options?: { |
| 285 | readonly space?: number | string | undefined |
| 286 | }): string { |
| 287 | const ancestors: Array<object> = [] |
| 288 | return JSON.stringify( |
| 289 | input, |
| 290 | function(this: object, key: string, value: unknown) { |
| 291 | const original = Object.getOwnPropertyDescriptor(this, key)?.value |
| 292 | const redacted = Predicate.hasProperty(original, symbolRedactable) |
| 293 | ? redact(original) |
| 294 | : redact(value) |
| 295 | if (typeof redacted === "bigint") { |
| 296 | return format(redacted) |
| 297 | } |
| 298 | if (typeof redacted !== "object" || redacted === null) { |
| 299 | return redacted |
| 300 | } |
| 301 | while (ancestors.length > 0 && ancestors[ancestors.length - 1] !== this) { |
| 302 | ancestors.pop() |
| 303 | } |
| 304 | if (ancestors.includes(redacted)) { |
| 305 | return undefined // circular reference |
| 306 | } |
| 307 | ancestors.push(redacted) |
| 308 | return redacted |
| 309 | }, |
| 310 | options?.space |
| 311 | ) ?? "null" |
| 312 | } |
no test coverage detected