/**
 * JSON.stringify wrapper that handles circular structures.
 * @param obj Object to stringify.
 * @returns Stringified object.
 */
const safeStringify = (obj) => {
    const seen = new WeakMap();
    let idx = 0;
    return JSON.stringify(obj, (_, value) => {
        if (typeof value !== 'object' || !value)
            return value;
        if (seen.has(value))
            return `[Circular #${seen.get(value)}]`;
        idx += 1;
        seen.set(value, idx);
        return value;
    });
};
export default safeStringify;
//# sourceMappingURL=safeStringify.js.map