whats-circular
v2.0.2
Published
Like what-is-circular, but returns the paths to the all circular references found, and directly to the offending key.
Downloads
2
Readme
whats-circular
Like what-is-circular
, but returns the paths to the all circular references found, and directly to the offending key.
Installation
npm install whats-circular
Usage
whatsCircular(obj)
Returns an array that contains the path to the first circular reference found, or undefined
if no circular reference is found.
Example
var whatsCircular = require('whats-circular')
var circularObj = {
foo: 1,
bar: 2
}
// qux.baz is the circular reference
circularObj.qux = {
baz: circularObj
}
whatsCircular(circularObj) // [['qux', 'baz']]
// multiple circular references
var a = {
a: false,
b: {
a: false,
c: {
a: false,
d: {
e: {
a: false
}
}
}
}
}
a.b.c.d.e = a
a.b.c.f = a.b.c
whatsCircular(a) //[['b', 'c', 'd', 'e'],['b', 'c', 'f']]
var obj = {
foo: 1,
bar: 2,
qux: 3
}
whatsCircular(obj) // undefined
License
MIT
Thanks
Thanks to @flotwig's https://github.com/flotwig/what-is-circular/
for the base project implementation.
Thanks to @tjmehta's is-circular
for providing the tests and README for this project.
Thanks to @angus-c's just-is-circular
for contributing additional tests.