Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including check-circular-reference with all npm packages installed. Try it out:

var checkCircularReference = require("check-circular-reference")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

check-circular-reference v1.0.11

Check circular reference or mutable variable. Print its reference attribute chain.

Check Circular Reference · GitHub license npm version

Check circular reference or mutable variable. Print its reference attribute chain.

Installation

npm install check-circular-reference --save

Usage

Node

let check = require('check-circular-reference');

// the obj is a variable  that you will check
let checkResult = check(obj);
if (checkResult.length === 0) {
    // do not exist circular reference or mutable variable    
} else {
    // exist circular reference or mutable variable    
}

ES6

import check from 'check-circular-reference';

// the obj is a variable  that you will check
let checkResult = check(obj);
if (checkResult.length === 0) {
    // do not exist circular reference or mutable variable    
} else {
    // exist circular reference or mutable variable    
}

Example

let check = require('check-circular-reference');
let menu = [
    {
        label: 'Home',
        children: [
            {
                label: 'Product'
            }
        ],
    }
];
menu[0].children[0].parent = menu[0];
check(menu);

circular reference example screenshot

Warning

I do not recommend you to use this node module on your released code, it just helps you optimize your code or find error easier, during developing.

// just check variable on development environment
let check = require('check-circular-reference');
let isReleased = true;

if (!isReleased) {
    // the below code will be executed on unreleased environment
    // the obj is a variable  that you will check
    check(obj)
}

Contribution

# install
npm install

# test
npm run test

About Circular Error

Understanding The Error ‘Converting circular structure to JSON’

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free