Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

object-lib

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

object-lib - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

74

lib/core/contains.js
"use strict";
const contains = (haystack, needle) => {
const needleType = typeof needle;
const haystackType = typeof haystack;
const objectScan = require('object-scan');
if (needleType !== haystackType) {
return false;
}
const scanner = objectScan(['**'], {
rtn: 'context',
abort: true,
breakFn: ({
isLeaf,
isMatch,
property,
value,
context
}) => {
const {
stack
} = context;
const last = stack[stack.length - 1];
if (needleType === 'object') {
const needleIsArray = Array.isArray(needle);
const haystackIsArray = Array.isArray(haystack);
if (isMatch && !(property in last)) {
context.result = false;
return true;
}
if (needleIsArray !== haystackIsArray) {
return false;
} // exact match for arrays
const current = isMatch ? last[property] : last;
if (needleIsArray) {
if (needle.length !== haystack.length) {
return false;
if (isLeaf) {
if (value !== current) {
context.result = false;
return true;
}
} else if (value instanceof Object !== current instanceof Object || Array.isArray(value) !== Array.isArray(current) || Array.isArray(value) && value.length !== current.length) {
context.result = false;
return true;
}
return needle.every((e, idx) => contains(haystack[idx], e));
} // subset match for object
stack.push(current);
return false;
},
filterFn: ({
context
}) => {
context.stack.pop();
return context.result !== true;
}
});
return Object.keys(needle).every(key => contains(haystack[key], needle[key]));
} // default comparison
return haystack === needle;
};
module.exports = contains;
module.exports = (tree, subtree) => {
const {
result
} = scanner(subtree, {
stack: [tree],
result: true
});
return result;
};
{
"name": "object-lib",
"version": "2.0.0",
"version": "2.0.1",
"main": "lib/index.js",

@@ -5,0 +5,0 @@ "repository": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc