Skip to content
Functionutilsv0.10.0

filterCirculars

Creates a clean, JSON safe copy of a value and replaces circular references with a marker.

In json mode it behaves like stringify then parse with a replacer that handles cycles and BigInt. In decycle mode it first clones without using toJSON, then you can stringify the result later.

filterCirculars<ObjType, Marker>(
    value: ObjType,
    options?: FilterCircularsOptions<Marker>
): JsonifyWithCirculars<ObjType, Marker> | UnserializableValue
interface Test {
  name: string;
  self?: Test;
}

const obj: Test = { name: 'seedcord' };
obj.self = obj;

const clean = filterCirculars(obj);
//     ^? { name: string; self?: "[Circular]" | { ... } }
console.log(clean.self); // "[Circular]"

ObjType

Type of the input value.

ObjType

Type of the input value.

Marker

Marker string used for circular references.

Marker

Marker string used for circular references.

value

value: ObjType

The value to clone safely.