abstract-syntax-tree
Advanced tools
Comparing version 2.6.1 to 2.6.2
{ | ||
"name": "abstract-syntax-tree", | ||
"version": "2.6.1", | ||
"version": "2.6.2", | ||
"description": "abstract syntax tree", | ||
@@ -40,3 +40,2 @@ "main": "index.js", | ||
"astring": "^1.3.0", | ||
"comparify": "^0.2.0", | ||
"esquery": "^1.0.1", | ||
@@ -43,0 +42,0 @@ "estemplate": "^0.5.1", |
@@ -1,5 +0,44 @@ | ||
const comparify = require('comparify') | ||
function getKey (object, key) { | ||
if (typeof object[key] !== 'undefined') return object[key] | ||
module.exports = function equal (node1, node2) { | ||
return comparify(node1, node2) | ||
key = ('' + key).split('.') | ||
for (let i = 0; i < key.length; i++) { | ||
object = object[key[i]] | ||
if (typeof object === 'undefined') return | ||
} | ||
return object | ||
}; | ||
function isPlainObject (object) { | ||
return Object.prototype.toString.call(object) === '[object Object]' | ||
} | ||
function compare (node, criterias) { | ||
for (const key in criterias) { | ||
if (Object.prototype.hasOwnProperty.call(criterias, key)) { | ||
const value1 = getKey(node, key) | ||
const value2 = getKey(criterias, key) | ||
if ({}.toString.call(value2) === '[object RegExp]') { | ||
if (!value2.test(value1)) return false | ||
} else if (isPlainObject(value2)) { | ||
if (!compare(value1, value2)) return false | ||
} else if (Array.isArray(value2) && Array.isArray(value1)) { | ||
for (let i = value2.length - 1; i >= 0; i--) { | ||
if (value1.indexOf(value2[i]) < 0) return false | ||
} | ||
} else if (Array.isArray(value2)) { | ||
return false | ||
} else if (Array.isArray(value1)) { | ||
if (value1.indexOf(value2) < 0) return false | ||
} else { | ||
if (value1 !== value2) return false | ||
} | ||
} | ||
} | ||
return true | ||
}; | ||
module.exports = function equal (node, criterias) { | ||
return compare(node, criterias) | ||
} |
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
27790
7
420
- Removedcomparify@^0.2.0
- Removedcomparify@0.2.0(transitive)