decircular
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

decircular

Remove circular references from objects

Circular references occur in JavaScript when an object references itself or creates a loop of references involving other objects. This can lead to issues like infinite loops and errors during serialization (e.g., with JSON.stringify). This package replaces circular references in objects or arrays with clear path notations (e.g., [Circular *a.1.b]). Ideal for data serialization, debugging, and logging.

Install

npm install decircular

Usage

import decircular from 'decircular';

const object = {
	a: 1,
	b: {
		c: 2
	}
};

object.b.d = object.b; // Creates a circular reference

console.log(decircular(object));
/*
{
	a: 1,
	b: {
		c: 2,
		d: '[Circular *b]'
	}
}
*/

API

decircular(object)

Returns a deep copy of the given object or array with circular references removed.

Related

  • safe-stringify - Serialize objects to JSON with handling for circular references

Dependencies (0)

    Dev Dependencies (3)

    Package Sidebar

    Install

    npm i decircular

    Weekly Downloads

    1,225

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    4.14 kB

    Total Files

    5

    Last publish

    Collaborators

    • sindresorhus