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

fast-equals

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fast-equals - npm Package Compare versions

Comparing version 1.5.2 to 1.5.3

4

CHANGELOG.md
# fast-equals CHANGELOG
## 1.5.3
* Fix `Map` / `Set` comparison to not require order to match to be equal
## 1.5.2

@@ -4,0 +8,0 @@

386

dist/fast-equals.js

@@ -7,388 +7,10 @@ (function (global, factory) {

/**
* @constant {boolean} HAS_MAP_SUPPORT
*/
var HAS_MAP_SUPPORT = typeof Map === 'function';
var HAS_MAP_SUPPORT='function'==typeof Map;var HAS_SET_SUPPORT='function'==typeof Set;var HAS_WEAKSET_SUPPORT='function'==typeof WeakSet;
/**
* @constant {boolean} HAS_SET_SUPPORT
*/
var HAS_SET_SUPPORT = typeof Set === 'function';
var keys=Object.keys;var addObjectToCache=function(a,b){return a&&'object'==typeof a&&b.add(a)};var hasItem=function(a,b,c,d){for(var e=0;e<a.length;e++)if(c(a[e],b,d))return !0;return !1};var hasItems=function(a,b,c,d){if(a.length!==b.length)return !1;for(var e=0;e<a.length;e++)if(!hasItem(b,a[e],c,d))return !1;return !0};var sameValueZeroEqual=function(a,b){return a===b||a!==a&&b!==b};var isPlainObject=function(a){return a.constructor===Object};var isPromiseLike=function(a){return 'function'==typeof a.then};var isReactElement=function(a){return !!(a.$$typeof&&a._store)};var getNewCache=function(){return HAS_WEAKSET_SUPPORT?new WeakSet:Object.create({_values:[],add:function b(a){this._values.push(a);},has:function b(a){return !!~this._values.indexOf(a)}})};var createCircularEqual=function(a){return function(b){return function(c,d){var e=2<arguments.length&&void 0!==arguments[2]?arguments[2]:getNewCache(),f=e.has(c),g=e.has(d);return f||g?f&&g:(addObjectToCache(c,e),addObjectToCache(d,e),(a||b)(c,d,e))}}};var toPairs=function(a){var b={keys:[],values:[]};return a.forEach(function(a,c){return b.keys.push(c)&&b.values.push(a)}),b};var areArraysEqual=function(a,b,c,d){if(a.length!==b.length)return !1;for(var e=0;e<a.length;e++)if(!c(a[e],b[e],d))return !1;return !0};var createAreIterablesEqual=function(a){var b=a?function(a,b,c,d){return hasItems(a.keys,b.keys,c,d)&&hasItems(a.values,b.values,c,d)}:function(a,b,c,d){return hasItems(a.values,b.values,c,d)};return function(a,c,d,e){return b(toPairs(a),toPairs(c),d,e)}};var areObjectsEqual=function(a,b,c,d){var e=keys(a),f=keys(b);if(e.length!==f.length)return !1;for(var g=void 0,h=0;h<e.length;h++){if(g=e[h],!hasItem(f,g,sameValueZeroEqual))return !1;if(!('_owner'===g&&isReactElement(a)&&isReactElement(b))&&!c(a[g],b[g],d))return !1}return !0};var areRegExpsEqual=function(a,b){return a.source===b.source&&a.global===b.global&&a.ignoreCase===b.ignoreCase&&a.multiline===b.multiline&&a.unicode===b.unicode&&a.sticky===b.sticky&&a.lastIndex===b.lastIndex};
/**
* @constant {boolean} HAS_WEAKSET_SUPPORT
*/
var HAS_WEAKSET_SUPPORT = typeof WeakSet === 'function';
var isArray=Array.isArray,areMapsEqual=createAreIterablesEqual(!0),areSetsEqual=createAreIterablesEqual(!1),createComparator=function(a){function b(a,b,d){if(sameValueZeroEqual(a,b))return !0;var e=typeof a;if(e!=typeof b||'object'!=e||!a||!b)return !1;if(isPlainObject(a)&&isPlainObject(b))return areObjectsEqual(a,b,c,d);var f=isArray(a),g=isArray(b);if(f||g)return f===g&&areArraysEqual(a,b,c,d);var h=a instanceof Date,i=b instanceof Date;if(h||i)return h==i&&sameValueZeroEqual(a.getTime(),b.getTime());var j=a instanceof RegExp,k=b instanceof RegExp;if(j||k)return j==k&&areRegExpsEqual(a,b);if(isPromiseLike(a)||isPromiseLike(b))return a===b;if(HAS_MAP_SUPPORT){var l=a instanceof Map,m=b instanceof Map;if(l||m)return l==m&&areMapsEqual(a,b,c,d)}if(HAS_SET_SUPPORT){var n=a instanceof Set,o=b instanceof Set;if(n||o)return n==o&&areSetsEqual(a,b,c,d)}return areObjectsEqual(a,b,c,d)}var c='function'==typeof a?a(b):b;return b};
// constants
var circularDeepEqual=createComparator(createCircularEqual());var circularShallowEqual=createComparator(createCircularEqual(sameValueZeroEqual));var deepEqual=createComparator();var shallowEqual=createComparator(function(){return sameValueZeroEqual});var index = {circularDeep:circularDeepEqual,circularShallow:circularShallowEqual,createCustom:createComparator,deep:deepEqual,sameValueZero:sameValueZeroEqual,shallow:shallowEqual};
var keys = Object.keys;
/**
* @function addObjectToCache
*
* @description
* add object to cache if it is indeed an object
*
* @param {any} object the object to potentially add to the cache
* @param {Object|WeakSet} cache the cache to add to
* @returns {void}
*/
var addObjectToCache = function addObjectToCache(object, cache) {
return object && typeof object === 'object' && cache.add(object);
};
/**
* @function hasKey
*
* @description
* does the array of keys include the key passed
*
* @param {Array<string>} keys the keys to check in
* @param {string} key the key to locate
* @returns {boolean} does the key exist in the keys
*/
var hasKey = function hasKey(keys, key) {
for (var index = 0; index < keys.length; index++) {
if (keys[index] === key) {
return true;
}
}
return false;
};
/**
* @function sameValueZeroEqual
*
* @description
* are the objects passed strictly equal or both NaN
*
* @param {any} objectA the object to compare against
* @param {any} objectB the object to test
* @returns {boolean} are the objects equal by the SameValueZero principle
*/
var sameValueZeroEqual = function sameValueZeroEqual(objectA, objectB) {
return objectA === objectB || objectA !== objectA && objectB !== objectB;
};
/**
* @function isPlainObject
*
* @description
* is the object a plain object
*
* @param {any} object the object to test
* @returns {boolean} is the object a plain object
*/
var isPlainObject = function isPlainObject(object) {
return object.constructor === Object;
};
/**
* @function isPromiseLike
*
* @description
* is the object promise-like (thenable)
*
* @param {any} object the object to test
* @returns {boolean} is the object promise-like
*/
var isPromiseLike = function isPromiseLike(object) {
return typeof object.then === 'function';
};
/**
* @function isReactElement
*
* @description
* is the object passed a react element
*
* @param {any} object the object to test
* @returns {boolean} is the object a react element
*/
var isReactElement = function isReactElement(object) {
return !!(object.$$typeof && object._store);
};
/**
* @function getNewCache
*
* @description
* get a new cache object to prevent circular references
*
* @returns {Object|Weakset} the new cache object
*/
var getNewCache = function getNewCache() {
return HAS_WEAKSET_SUPPORT ? new WeakSet() : Object.create({
_values: [],
add: function add(value) {
this._values.push(value);
},
has: function has(value) {
return !!~this._values.indexOf(value);
}
});
};
/**
* @function createCircularEqual
*
* @description
* create a custom isEqual handler specific to circular objects
*
* @param {funtion} [isEqual] the isEqual comparator to use instead of isDeepEqual
* @returns {function(any, any): boolean}
*/
var createCircularEqual = function createCircularEqual(isEqual) {
return function (isDeepEqual) {
var comparator = isEqual || isDeepEqual;
return function (objectA, objectB) {
var cache = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : getNewCache();
var cacheHasA = cache.has(objectA);
var cacheHasB = cache.has(objectB);
if (cacheHasA || cacheHasB) {
return cacheHasA && cacheHasB;
}
addObjectToCache(objectA, cache);
addObjectToCache(objectB, cache);
return comparator(objectA, objectB, cache);
};
};
};
/**
* @function toPairs
*
* @param {Map|Set} iterable the iterable to convert to [key, value] pairs (entries)
* @returns {{keys: Array<*>, values: Array<*>}} the [key, value] pairs
*/
var toPairs = function toPairs(iterable) {
var pairs = { keys: new Array(iterable.size), values: new Array(iterable.size) };
var index = 0;
iterable.forEach(function (value, key) {
pairs.keys[index] = key;
pairs.values[index++] = value;
});
return pairs;
};
/**
* @function areArraysEqual
*
* @description
* are the arrays equal in value
*
* @param {Array<any>} arrayA the array to test
* @param {Array<any>} arrayB the array to test against
* @param {function} isEqual the comparator to determine equality
* @param {any} meta the meta object to pass through
* @returns {boolean} are the arrays equal
*/
var areArraysEqual = function areArraysEqual(arrayA, arrayB, isEqual, meta) {
if (arrayA.length !== arrayB.length) {
return false;
}
for (var index = 0; index < arrayA.length; index++) {
if (!isEqual(arrayA[index], arrayB[index], meta)) {
return false;
}
}
return true;
};
var createAreIterablesEqual = function createAreIterablesEqual(shouldCompareKeys) {
/**
* @function areIterablesEqual
*
* @description
* determine if the iterables are equivalent in value
*
* @param {Array<Array<any>>} pairsA the pairs to test
* @param {Array<Array<any>>} pairsB the pairs to test against
* @param {function} isEqual the comparator to determine equality
* @param {any} meta the cache possibly being used
* @returns {boolean} are the objects equal in value
*/
var areIterablesEqual = shouldCompareKeys ? function (pairsA, pairsB, isEqual, meta) {
return isEqual(pairsA.keys, pairsB.keys) && isEqual(pairsA.values, pairsB.values, meta);
} : function (pairsA, pairsB, isEqual, meta) {
return isEqual(pairsA.values, pairsB.values, meta);
};
return function (iterableA, iterableB, isEqual, meta) {
return iterableA.size === iterableB.size && areIterablesEqual(toPairs(iterableA), toPairs(iterableB), isEqual, meta);
};
};
/**
* @function areArraysEqual
*
* @description
* are the objects equal in value
*
* @param {Array<any>} objectA the object to test
* @param {Array<any>} objectB the object to test against
* @param {function} isEqual the comparator to determine equality
* @param {any} meta the meta object to pass through
* @returns {boolean} are the objects equal
*/
var areObjectsEqual = function areObjectsEqual(objectA, objectB, isEqual, meta) {
var keysA = keys(objectA);
var keysB = keys(objectB);
if (keysA.length !== keysB.length) {
return false;
}
var key = void 0;
for (var index = 0; index < keysA.length; index++) {
key = keysA[index];
if (!hasKey(keysB, key)) {
return false;
}
// if a react element, ignore the "_owner" key because its not necessary for equality comparisons
if (key === '_owner' && isReactElement(objectA) && isReactElement(objectB)) {
continue;
}
if (!isEqual(objectA[key], objectB[key], meta)) {
return false;
}
}
return true;
};
/**
* @function areRegExpsEqual
*
* @description
* are the regExps equal in value
*
* @param {RegExp} regExpA the regExp to test
* @param {RegExp} regExpB the regExp to test agains
* @returns {boolean} are the regExps equal
*/
var areRegExpsEqual = function areRegExpsEqual(regExpA, regExpB) {
return regExpA.source === regExpB.source && regExpA.global === regExpB.global && regExpA.ignoreCase === regExpB.ignoreCase && regExpA.multiline === regExpB.multiline && regExpA.unicode === regExpB.unicode && regExpA.sticky === regExpB.sticky && regExpA.lastIndex === regExpB.lastIndex;
};
// constants
var isArray = Array.isArray;
var areMapsEqual = createAreIterablesEqual(true);
var areSetsEqual = createAreIterablesEqual(false);
var createComparator = function createComparator(createIsEqual) {
// eslint-disable-next-line no-use-before-define
var isEqual = typeof createIsEqual === 'function' ? createIsEqual(comparator) : comparator;
/**
* @function comparator
*
* @description
* compare the value of the two objects and return true if they are equivalent in values
*
* @param {any} objectA the object to test against
* @param {any} objectB the object to test
* @param {any} [meta] an optional meta object that is passed through to all equality test calls
* @returns {boolean} are objectA and objectB equivalent in value
*/
function comparator(objectA, objectB, meta) {
if (sameValueZeroEqual(objectA, objectB)) {
return true;
}
var typeOfA = typeof objectA;
if (typeOfA !== typeof objectB || typeOfA !== 'object' || !objectA || !objectB) {
return false;
}
if (isPlainObject(objectA) && isPlainObject(objectB)) {
return areObjectsEqual(objectA, objectB, isEqual, meta);
}
var arrayA = isArray(objectA);
var arrayB = isArray(objectB);
if (arrayA || arrayB) {
return arrayA === arrayB && areArraysEqual(objectA, objectB, isEqual, meta);
}
var dateA = objectA instanceof Date;
var dateB = objectB instanceof Date;
if (dateA || dateB) {
return dateA === dateB && sameValueZeroEqual(objectA.getTime(), objectB.getTime());
}
var regexpA = objectA instanceof RegExp;
var regexpB = objectB instanceof RegExp;
if (regexpA || regexpB) {
return regexpA === regexpB && areRegExpsEqual(objectA, objectB);
}
if (isPromiseLike(objectA) || isPromiseLike(objectB)) {
return objectA === objectB;
}
if (HAS_MAP_SUPPORT) {
var mapA = objectA instanceof Map;
var mapB = objectB instanceof Map;
if (mapA || mapB) {
return mapA === mapB && areMapsEqual(objectA, objectB, comparator, meta);
}
}
if (HAS_SET_SUPPORT) {
var setA = objectA instanceof Set;
var setB = objectB instanceof Set;
if (setA || setB) {
return setA === setB && areSetsEqual(objectA, objectB, comparator, meta);
}
}
return areObjectsEqual(objectA, objectB, isEqual, meta);
}
return comparator;
};
// comparator
var circularDeepEqual = createComparator(createCircularEqual());
var circularShallowEqual = createComparator(createCircularEqual(sameValueZeroEqual));
var deepEqual = createComparator();
var shallowEqual = createComparator(function () {
return sameValueZeroEqual;
});
var index = {
circularDeep: circularDeepEqual,
circularShallow: circularShallowEqual,
createCustom: createComparator,
deep: deepEqual,
sameValueZero: sameValueZeroEqual,
shallow: shallowEqual
};
exports.createCustomEqual = createComparator;

@@ -395,0 +17,0 @@ exports.sameValueZeroEqual = sameValueZeroEqual;

@@ -1,1 +0,1 @@

!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(e.fe={})}(this,function(e){"use strict";var m="function"==typeof Map,b="function"==typeof Set,o="function"==typeof WeakSet,f=Object.keys,a=function(e,n){return e&&"object"==typeof e&&n.add(e)},c=function(e,n){for(var t=0;t<e.length;t++)if(e[t]===n)return!0;return!1},k=function(e,n){return e===n||e!=e&&n!=n},E=function(e){return e.constructor===Object},w=function(e){return"function"==typeof e.then},s=function(e){return!(!e.$$typeof||!e._store)},n=function(n){return function(e){var i=n||e;return function(e,n){var t=2<arguments.length&&void 0!==arguments[2]?arguments[2]:o?new WeakSet:Object.create({_values:[],add:function(e){this._values.push(e)},has:function(e){return!!~this._values.indexOf(e)}}),r=t.has(e),u=t.has(n);return r||u?r&&u:(a(e,t),a(n,t),i(e,n,t))}}},i=function(e){var t={keys:new Array(e.size),values:new Array(e.size)},r=0;return e.forEach(function(e,n){t.keys[r]=n,t.values[r++]=e}),t},t=function(e){var u=e?function(e,n,t,r){return t(e.keys,n.keys)&&t(e.values,n.values,r)}:function(e,n,t,r){return t(e.values,n.values,r)};return function(e,n,t,r){return e.size===n.size&&u(i(e),i(n),t,r)}},x=function(e,n,t,r){var u=f(e),i=f(n);if(u.length!==i.length)return!1;for(var o=void 0,a=0;a<u.length;a++){if(o=u[a],!c(i,o))return!1;if(("_owner"!==o||!s(e)||!s(n))&&!t(e[o],n[o],r))return!1}return!0},j=Array.isArray,S=t(!0),_=t(!1),r=function(e){var h="function"==typeof e?e(g):g;function g(e,n,t){if(k(e,n))return!0;var r=typeof e;if(r!==typeof n||"object"!==r||!e||!n)return!1;if(E(e)&&E(n))return x(e,n,h,t);var u=j(e),i=j(n);if(u||i)return u===i&&function(e,n,t,r){if(e.length!==n.length)return!1;for(var u=0;u<e.length;u++)if(!t(e[u],n[u],r))return!1;return!0}(e,n,h,t);var o=e instanceof Date,a=n instanceof Date;if(o||a)return o===a&&k(e.getTime(),n.getTime());var f,c,s=e instanceof RegExp,l=n instanceof RegExp;if(s||l)return s===l&&(c=n,(f=e).source===c.source&&f.global===c.global&&f.ignoreCase===c.ignoreCase&&f.multiline===c.multiline&&f.unicode===c.unicode&&f.sticky===c.sticky&&f.lastIndex===c.lastIndex);if(w(e)||w(n))return e===n;if(m){var v=e instanceof Map,p=n instanceof Map;if(v||p)return v===p&&S(e,n,g,t)}if(b){var y=e instanceof Set,d=n instanceof Set;if(y||d)return y===d&&_(e,n,g,t)}return x(e,n,h,t)}return g},u=r(n()),l=r(n(k)),v=r(),p=r(function(){return k}),y={circularDeep:u,circularShallow:l,createCustom:r,deep:v,sameValueZero:k,shallow:p};e.createCustomEqual=r,e.sameValueZeroEqual=k,e.circularDeepEqual=u,e.circularShallowEqual=l,e.deepEqual=v,e.shallowEqual=p,e.default=y,Object.defineProperty(e,"__esModule",{value:!0})});
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(e.fe={})}(this,function(e){"use strict";var g="function"==typeof Map,m="function"==typeof Set,f="function"==typeof WeakSet,a=Object.keys,c=function(e,n){return e&&"object"==typeof e&&n.add(e)},l=function(e,n,t,r){for(var u=0;u<e.length;u++)if(t(e[u],n,r))return!0;return!1},i=function(e,n,t,r){if(e.length!==n.length)return!1;for(var u=0;u<e.length;u++)if(!l(n,e[u],t,r))return!1;return!0},b=function(e,n){return e===n||e!=e&&n!=n},k=function(e){return e.constructor===Object},E=function(e){return"function"==typeof e.then},s=function(e){return!(!e.$$typeof||!e._store)},n=function(o){return function(i){return function(e,n){var t=2<arguments.length&&void 0!==arguments[2]?arguments[2]:f?new WeakSet:Object.create({_values:[],add:function(e){this._values.push(e)},has:function(e){return!!~this._values.indexOf(e)}}),r=t.has(e),u=t.has(n);return r||u?r&&u:(c(e,t),c(n,t),(o||i)(e,n,t))}}},o=function(e){var t={keys:[],values:[]};return e.forEach(function(e,n){return t.keys.push(n)&&t.values.push(e)}),t},t=function(e){var u=e?function(e,n,t,r){return i(e.keys,n.keys,t,r)&&i(e.values,n.values,t,r)}:function(e,n,t,r){return i(e.values,n.values,t,r)};return function(e,n,t,r){return u(o(e),o(n),t,r)}},x=function(e,n,t,r){var u=a(e),i=a(n);if(u.length!==i.length)return!1;for(var o=void 0,f=0;f<u.length;f++){if(o=u[f],!l(i,o,b))return!1;if(!("_owner"===o&&s(e)&&s(n)||t(e[o],n[o],r)))return!1}return!0},j=Array.isArray,S=t(!0),_=t(!1),r=function(e){function n(e,n,t){if(b(e,n))return!0;var r=typeof e;if(r!=typeof n||"object"!=r||!e||!n)return!1;if(k(e)&&k(n))return x(e,n,y,t);var u=j(e),i=j(n);if(u||i)return u===i&&function(e,n,t,r){if(e.length!==n.length)return!1;for(var u=0;u<e.length;u++)if(!t(e[u],n[u],r))return!1;return!0}(e,n,y,t);var o=e instanceof Date,f=n instanceof Date;if(o||f)return o==f&&b(e.getTime(),n.getTime());var a,c,l=e instanceof RegExp,s=n instanceof RegExp;if(l||s)return l==s&&(c=n,(a=e).source===c.source&&a.global===c.global&&a.ignoreCase===c.ignoreCase&&a.multiline===c.multiline&&a.unicode===c.unicode&&a.sticky===c.sticky&&a.lastIndex===c.lastIndex);if(E(e)||E(n))return e===n;if(g){var p=e instanceof Map,v=n instanceof Map;if(p||v)return p==v&&S(e,n,y,t)}if(m){var h=e instanceof Set,d=n instanceof Set;if(h||d)return h==d&&_(e,n,y,t)}return x(e,n,y,t)}var y="function"==typeof e?e(n):n;return n},u=r(n()),p=r(n(b)),v=r(),h=r(function(){return b}),d={circularDeep:u,circularShallow:p,createCustom:r,deep:v,sameValueZero:b,shallow:h};e.createCustomEqual=r,e.sameValueZeroEqual=b,e.circularDeepEqual=u,e.circularShallowEqual=p,e.deepEqual=v,e.shallowEqual=h,e.default=d,Object.defineProperty(e,"__esModule",{value:!0})});

@@ -72,3 +72,3 @@ // constants

if (mapA || mapB) {
return mapA === mapB && areMapsEqual(objectA, objectB, comparator, meta);
return mapA === mapB && areMapsEqual(objectA, objectB, isEqual, meta);
}

@@ -82,3 +82,3 @@ }

if (setA || setB) {
return setA === setB && areSetsEqual(objectA, objectB, comparator, meta);
return setA === setB && areSetsEqual(objectA, objectB, isEqual, meta);
}

@@ -85,0 +85,0 @@ }

@@ -21,14 +21,16 @@ // constants

/**
* @function hasKey
* @function hasItem
*
* @description
* does the array of keys include the key passed
* does the array include the item passed
*
* @param {Array<string>} keys the keys to check in
* @param {string} key the key to locate
* @returns {boolean} does the key exist in the keys
* @param {Array<any>} array the array to check in
* @param {any} item the item to locate
* @param {function} isEqual the equality comparator
* @param {any} meta the meta item to pass through
* @returns {boolean} does the item exist in the array
*/
export var hasKey = function hasKey(keys, key) {
for (var index = 0; index < keys.length; index++) {
if (keys[index] === key) {
export var hasItem = function hasItem(array, item, isEqual, meta) {
for (var index = 0; index < array.length; index++) {
if (isEqual(array[index], item, meta)) {
return true;

@@ -42,2 +44,28 @@ }

/**
* @function hasItems
*
* @description
* are the arrays equal in value, despite being in different order
*
* @param {Array<any>} arrayA the first array to test
* @param {Array<any>} arrayB the second array to test
* @param {function} isEqual the equality comparator
* @param {any} meta the meta item to pass through
* @returns {boolean} are the arrays equal absent order
*/
export var hasItems = function hasItems(arrayA, arrayB, isEqual, meta) {
if (arrayA.length !== arrayB.length) {
return false;
}
for (var index = 0; index < arrayA.length; index++) {
if (!hasItem(arrayB, arrayA[index], isEqual, meta)) {
return false;
}
}
return true;
};
/**
* @function sameValueZeroEqual

@@ -153,9 +181,6 @@ *

export var toPairs = function toPairs(iterable) {
var pairs = { keys: new Array(iterable.size), values: new Array(iterable.size) };
var pairs = { keys: [], values: [] };
var index = 0;
iterable.forEach(function (value, key) {
pairs.keys[index] = key;
pairs.values[index++] = value;
return pairs.keys.push(key) && pairs.values.push(value);
});

@@ -206,9 +231,9 @@

var areIterablesEqual = shouldCompareKeys ? function (pairsA, pairsB, isEqual, meta) {
return isEqual(pairsA.keys, pairsB.keys) && isEqual(pairsA.values, pairsB.values, meta);
return hasItems(pairsA.keys, pairsB.keys, isEqual, meta) && hasItems(pairsA.values, pairsB.values, isEqual, meta);
} : function (pairsA, pairsB, isEqual, meta) {
return isEqual(pairsA.values, pairsB.values, meta);
return hasItems(pairsA.values, pairsB.values, isEqual, meta);
};
return function (iterableA, iterableB, isEqual, meta) {
return iterableA.size === iterableB.size && areIterablesEqual(toPairs(iterableA), toPairs(iterableB), isEqual, meta);
return areIterablesEqual(toPairs(iterableA), toPairs(iterableB), isEqual, meta);
};

@@ -242,3 +267,3 @@ };

if (!hasKey(keysB, key)) {
if (!hasItem(keysB, key, sameValueZeroEqual)) {
return false;

@@ -245,0 +270,0 @@ }

@@ -78,3 +78,3 @@ 'use strict';

if (mapA || mapB) {
return mapA === mapB && areMapsEqual(objectA, objectB, comparator, meta);
return mapA === mapB && areMapsEqual(objectA, objectB, isEqual, meta);
}

@@ -88,3 +88,3 @@ }

if (setA || setB) {
return setA === setB && areSetsEqual(objectA, objectB, comparator, meta);
return setA === setB && areSetsEqual(objectA, objectB, isEqual, meta);
}

@@ -91,0 +91,0 @@ }

'use strict';
exports.__esModule = true;
exports.areRegExpsEqual = exports.areObjectsEqual = exports.createAreIterablesEqual = exports.areArraysEqual = exports.toPairs = exports.createCircularEqual = exports.getNewCache = exports.isReactElement = exports.isPromiseLike = exports.isPlainObject = exports.sameValueZeroEqual = exports.hasKey = exports.addObjectToCache = undefined;
exports.areRegExpsEqual = exports.areObjectsEqual = exports.createAreIterablesEqual = exports.areArraysEqual = exports.toPairs = exports.createCircularEqual = exports.getNewCache = exports.isReactElement = exports.isPromiseLike = exports.isPlainObject = exports.sameValueZeroEqual = exports.hasItems = exports.hasItem = exports.addObjectToCache = undefined;

@@ -26,14 +26,16 @@ var _constants = require('./constants');

/**
* @function hasKey
* @function hasItem
*
* @description
* does the array of keys include the key passed
* does the array include the item passed
*
* @param {Array<string>} keys the keys to check in
* @param {string} key the key to locate
* @returns {boolean} does the key exist in the keys
* @param {Array<any>} array the array to check in
* @param {any} item the item to locate
* @param {function} isEqual the equality comparator
* @param {any} meta the meta item to pass through
* @returns {boolean} does the item exist in the array
*/
var hasKey = exports.hasKey = function hasKey(keys, key) {
for (var index = 0; index < keys.length; index++) {
if (keys[index] === key) {
var hasItem = exports.hasItem = function hasItem(array, item, isEqual, meta) {
for (var index = 0; index < array.length; index++) {
if (isEqual(array[index], item, meta)) {
return true;

@@ -47,2 +49,28 @@ }

/**
* @function hasItems
*
* @description
* are the arrays equal in value, despite being in different order
*
* @param {Array<any>} arrayA the first array to test
* @param {Array<any>} arrayB the second array to test
* @param {function} isEqual the equality comparator
* @param {any} meta the meta item to pass through
* @returns {boolean} are the arrays equal absent order
*/
var hasItems = exports.hasItems = function hasItems(arrayA, arrayB, isEqual, meta) {
if (arrayA.length !== arrayB.length) {
return false;
}
for (var index = 0; index < arrayA.length; index++) {
if (!hasItem(arrayB, arrayA[index], isEqual, meta)) {
return false;
}
}
return true;
};
/**
* @function sameValueZeroEqual

@@ -158,9 +186,6 @@ *

var toPairs = exports.toPairs = function toPairs(iterable) {
var pairs = { keys: new Array(iterable.size), values: new Array(iterable.size) };
var pairs = { keys: [], values: [] };
var index = 0;
iterable.forEach(function (value, key) {
pairs.keys[index] = key;
pairs.values[index++] = value;
return pairs.keys.push(key) && pairs.values.push(value);
});

@@ -211,9 +236,9 @@

var areIterablesEqual = shouldCompareKeys ? function (pairsA, pairsB, isEqual, meta) {
return isEqual(pairsA.keys, pairsB.keys) && isEqual(pairsA.values, pairsB.values, meta);
return hasItems(pairsA.keys, pairsB.keys, isEqual, meta) && hasItems(pairsA.values, pairsB.values, isEqual, meta);
} : function (pairsA, pairsB, isEqual, meta) {
return isEqual(pairsA.values, pairsB.values, meta);
return hasItems(pairsA.values, pairsB.values, isEqual, meta);
};
return function (iterableA, iterableB, isEqual, meta) {
return iterableA.size === iterableB.size && areIterablesEqual(toPairs(iterableA), toPairs(iterableB), isEqual, meta);
return areIterablesEqual(toPairs(iterableA), toPairs(iterableB), isEqual, meta);
};

@@ -247,3 +272,3 @@ };

if (!hasKey(keysB, key)) {
if (!hasItem(keysB, key, sameValueZeroEqual)) {
return false;

@@ -250,0 +275,0 @@ }

@@ -27,2 +27,3 @@ {

"babel-preset-env": "^1.7.0",
"babel-preset-minify": "^0.4.3",
"babel-preset-react": "^6.24.1",

@@ -97,3 +98,3 @@ "babel-preset-stage-2": "^6.24.1",

},
"version": "1.5.2"
"version": "1.5.3"
}

@@ -197,13 +197,13 @@ # fast-equals

| -------------------------- | ------------------- | ------------------------ |
| **fast-equals** | **149,272** | **0.74%** |
| nano-equal | 106,185 | 0.81% |
| fast-deep-equal | 104,921 | 0.88% |
| shallow-equal-fuzzy | 103,181 | 0.93% |
| react-fast-compare | 101,807 | 1.06% |
| underscore.isEqual | 67,655 | 0.63% |
| **fast-equals (circular)** | **58,042** | **0.85%** |
| deep-equal | 30,282 | 0.65% |
| lodash.isEqual | 27,741 | 0.68% |
| deep-eql | 16,785 | 1.03% |
| assert.deepStrictEqual | 1,559 | 0.97% |
| **fast-equals** | **130,726** | **0.79%** |
| nano-equal | 103,950 | 0.85% |
| shallow-equal-fuzzy | 101,535 | 0.60% |
| react-fast-compare | 94,724 | 0.82% |
| fast-deep-equal | 92,172 | 0.85% |
| underscore.isEqual | 63,431 | 0.88% |
| **fast-equals (circular)** | **53,778** | **0.85%** |
| deep-equal | 29,739 | 0.54% |
| lodash.isEqual | 26,201 | 0.70% |
| deep-eql | 16,496 | 0.60% |
| assert.deepStrictEqual | 1,565 | 1.04% |

@@ -244,3 +244,3 @@ Caveats that impact the benchmark (and accuracy of comparison):

* test:watch => run same script as `test` but keep persistent watcher
* transpile:es => run Babel on all files in `src` folder (transpiled to `es` folder without transpilation of ES2015 export syntax)
* transpile:es => run Babel on all files, in `src` folder (transpiled to `es` folder without transpilation of ES2015 export syntax)
* transpile:lib => run Babel on all files in `src` folder (transpiled to `lib` folder)

Sorry, the diff of this file is not supported yet

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