Captain is currently in ALPHA. We are happy to get your feedback
Core API
Object

Module: object

Table of contents

Functions

Functions

getCircularReplacer

getCircularReplacer(): (key: string, value: unknown) => unknown

Creates a replacer function for JSON.stringify to safely handle circular references. The replacer function can be used as a second argument to JSON.stringify to prevent it from throwing errors on circular references within the object being stringified.

Returns

fn

A replacer function that safely serializes objects containing circular references.

▸ (key, value): unknown

Parameters
NameType
keystring
valueunknown
Returns

unknown

Defined in

src/shared/object.ts:9 (opens in a new tab)


jsonStringify

jsonStringify(object_): string

Serializes a given object into a JSON string while safely handling circular references. This function uses a custom replacer to manage circular dependencies encountered during stringification, preventing JSON.stringify from throwing errors.

Parameters

NameTypeDescription
object_unknown[] | Record<string, unknown>The object to be serialized to JSON. This must be a record with string keys and values of unknown types.

Returns

string

A JSON string representation of the object, with circular references handled gracefully.

Defined in

src/shared/object.ts:34 (opens in a new tab)