🚀 Launch Week Day 3:Introducing Supply Chain Attack Campaigns Tracking.Learn More →
Socket
Book a DemoInstallSign in
Socket

decircular

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

decircular

Remove circular references from objects

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

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.

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

Keywords

circular

FAQs

Package last updated on 10 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts