Decircular
Remove circular references from objects
Install / Use
/learn @sindresorhus/DecircularREADME
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
Related Skills
node-connect
351.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
110.6kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
351.2kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
351.2kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
