https://github.com/flotwig/what-is-circular
Like is-circular, but returns the path to the first circular reference found.
https://github.com/flotwig/what-is-circular
Last synced: 6 months ago
JSON representation
Like is-circular, but returns the path to the first circular reference found.
- Host: GitHub
- URL: https://github.com/flotwig/what-is-circular
- Owner: flotwig
- Created: 2019-06-12T16:56:17.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-06-14T16:21:08.000Z (about 7 years ago)
- Last Synced: 2025-11-27T12:17:23.894Z (8 months ago)
- Language: JavaScript
- Size: 4.88 KB
- Stars: 1
- Watchers: 0
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# what-is-circular [](https://travis-ci.org/flotwig/what-is-circular)
Like [`is-circular`](https://github.com/tjmehta/is-circular/), but returns the path to the first circular reference found.
# Installation
`npm install what-is-circular`
# Usage
## `whatIsCircular(obj)`
Returns an array that contains the path to the first circular reference found, or `undefined` if no circular reference is found.
# Example
```js
var whatIsCircular = require('what-is-circular')
var circularObj = {
foo: 1,
bar: 2
}
// qux.baz is the circular reference
circularObj.qux = {
baz: circularObj
}
whatIsCircular(circularObj) // ['qux', 'baz']
var obj = {
foo: 1,
bar: 2,
qux: 3
}
whatIsCircular(obj) // undefined
```
# License
MIT
# Thanks
Thanks to @tjmehta's [`is-circular`](https://github.com/tjmehta/is-circular/) for providing the tests and README for this project.
Thanks to @angus-c's [`just-is-circular`](https://github.com/angus-c/just/) for contributing additional tests.