Comparing version 1.1.3 to 1.2.0
@@ -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 @@ |
{ | ||
"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 @@ |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
39544
12
786
0