Socket
Socket
Sign inDemoInstall

samsam

Package Overview
Dependencies
Maintainers
4
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

samsam - npm Package Compare versions

Comparing version 1.1.3 to 1.2.0

appveyor.yml

52

lib/samsam.js

@@ -122,3 +122,30 @@ ((typeof define === "function" && define.amd && function (m) { define("samsam", m); }) ||

function isSet(val) {
if (typeof Set !== 'undefined' && val instanceof Set) {
return true;
}
}
function isSubset(s1, s2, compare) {
var values1 = Array.from(s1);
var values2 = Array.from(s2);
for (var i = 0; i < values1.length; i++) {
var includes = false;
for (var j = 0; j < values2.length; j++) {
if (compare(values1[i], values2[j])) {
includes = true;
break;
}
}
if (!includes) {
return false;
}
}
return true;
}
/**

@@ -233,2 +260,10 @@ * @name samsam.deepEqual

if (isSet(obj1) || isSet(obj2)) {
if (!isSet(obj1) || !isSet(obj2) || obj1.size !== obj2.size) {
return false;
}
return isSubset(obj1, obj2, deepEqual);
}
var key, i, l,

@@ -306,11 +341,10 @@ // following vars are used for the cyclic logic

var match;
function arrayContains(array, subset) {
function arrayContains(array, subset, compare) {
if (subset.length === 0) { return true; }
var i, l, j, k;
for (i = 0, l = array.length; i < l; ++i) {
if (match(array[i], subset[0])) {
if (compare(array[i], subset[0])) {
for (j = 0, k = subset.length; j < k; ++j) {
if (!match(array[i + j], subset[j])) { return false; }
if ((i + j) >= l) { return false; }
if (!compare(array[i + j], subset[j])) { return false; }
}

@@ -330,3 +364,3 @@ return true;

*/
match = function match(object, matcher) {
function match(object, matcher) {
if (matcher && typeof matcher.test === "function") {

@@ -363,4 +397,8 @@ return matcher.test(object);

if (isSet(object)) {
return isSubset(matcher, object, match);
}
if (getClass(object) === "Array" && getClass(matcher) === "Array") {
return arrayContains(object, matcher);
return arrayContains(object, matcher, match);
}

@@ -367,0 +405,0 @@

2

package.json
{
"name": "samsam",
"version": "1.1.3",
"version": "1.2.0",
"description": "Value identification and comparison functions",

@@ -5,0 +5,0 @@ "homepage": "http://docs.busterjs.org/en/latest/modules/samsam/",

@@ -174,2 +174,7 @@ if (typeof module === "object" && typeof require === "function") {

arrayLike, gather(1, 2, {}, []));
if (typeof Set !== "undefined") {
pass("sets with the same content", new Set([1, 2, 3]), new Set([2, 1, 3]));
fail("sets with different content", new Set([1, 2, 3]), new Set([2, 5, 3]));
}
});

@@ -344,2 +349,3 @@

fail("mis-ordered array 'subset'", [1, 2, 3], [1, 3]);
fail("mis-ordered, but similar arrays of objects", [{a: 'a'}, {a: 'aa'}], [{a: 'aa'}, {a: 'a'}]);
pass("empty arrays", [], []);

@@ -379,2 +385,10 @@ pass("objects with empty arrays", { xs: [] }, { xs: [] });

if (typeof Set !== 'undefined') {
pass("sets with same content", new Set([1, 2, 3]), new Set([2, 3, 1]));
pass("subset", new Set([1, 2, 3]), new Set([3, 1]));
pass("subset complex types", new Set([1, {id: 42}, 3]), new Set([{id: 42}]));
fail("sets with dissimilar content", new Set([1, 2, 3]), new Set([2, 5, 1]));
fail("sets with different complex member", new Set([{id: 42}]), new Set([{id: 13}]));
}
});

@@ -381,0 +395,0 @@

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