@ipld/is-circular
Advanced tools
Comparing version 1.0.3 to 2.0.0
21
index.js
@@ -7,10 +7,11 @@ var Node = require('./lib/node') | ||
* checks whether the object is circular | ||
* @param {object} obj - object to check circularity for | ||
* @param {object} obj - object to check circularity for | ||
* @param {Object<string, true>} ignore - dictionary who's keys will be ignored | ||
* @return {Boolean} true if obj is circular, false if it is not | ||
*/ | ||
function isCircular (CID, obj) { | ||
function isCircular (obj, ignore={}) { | ||
if (!(obj instanceof Object)) { | ||
throw new TypeError('"obj" must be an object (or inherit from it)') | ||
} | ||
return _isCircular(CID, obj) | ||
return _isCircular(obj, ignore) | ||
} | ||
@@ -21,7 +22,8 @@ | ||
* checks whether the object is circular | ||
* @param {object} obj - object to check circularity for | ||
* @param {Node} parentList - linked-list that contains all the object's parents | ||
* @param {object} obj - object to check circularity for | ||
* @param {Object<string, true>} ignore - dictionary who's keys will be ignored | ||
* @param {Node} parentList - linked-list that contains all the object's parents | ||
* @return {Boolean} true if obj is circular, false if it is not | ||
*/ | ||
function _isCircular (CID, obj, parentList) { | ||
function _isCircular (obj, ignore, parentList) { | ||
parentList = new Node(obj, parentList) | ||
@@ -31,6 +33,9 @@ | ||
for (var key in obj) { | ||
if (ignore[key]) { | ||
continue | ||
} | ||
var val = obj[key] | ||
if (CID.asCID(val)) continue | ||
if (val instanceof Object) { | ||
if (parentList.contains(val) || _isCircular(CID, val, parentList)) { | ||
if (parentList.contains(val) || _isCircular(val, ignore, parentList)) { | ||
return true | ||
@@ -37,0 +42,0 @@ } |
{ | ||
"name": "@ipld/is-circular", | ||
"version": "1.0.3", | ||
"version": "2.0.0", | ||
"description": "high-performance, zero-dependency circular reference check for objects (or arrays)", | ||
@@ -11,6 +11,5 @@ "main": "index.js", | ||
"is-circular": "github:tjmehta/is-circular#v1.0.1", | ||
"jest": "^26.1.0", | ||
"jest": "^23.2.0", | ||
"matcha": "^0.7.0", | ||
"multiformats": "^2.0.1", | ||
"standard": "^14.3.4" | ||
"standard": "^11.0.1" | ||
}, | ||
@@ -17,0 +16,0 @@ "scripts": { |
/* eslint-env jest */ | ||
const { CID } = require('multiformats').create() | ||
const _isCircular = require('../') | ||
const isCircular = (...args) => _isCircular(CID, ...args) | ||
var isCircular = require('../') | ||
@@ -7,0 +5,0 @@ describe('is-circular', function () { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7729
4
131