Check circular reference or mutable variable. Print its reference attribute chain.
npm install check-circular-reference
npm install check-circular-reference --save
`Usage
$3
`
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
}
`
$3
`
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 screenshotWarning
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 installtest
npm run test
``