fast-equals
Advanced tools
Comparing version 1.5.1 to 1.5.2
# fast-equals CHANGELOG | ||
## 1.5.2 | ||
* Improve speed of object comparison through custom `hasKey` method | ||
## 1.5.1 | ||
* Add support for `unicode` and `sticky` RegExp flag checks | ||
* Fix lack of support for `unicode` and `sticky` RegExp flag checks | ||
@@ -7,0 +11,0 @@ ## 1.5.0 |
@@ -24,3 +24,3 @@ (function (global, factory) { | ||
var hasOwnProperty = Object.prototype.hasOwnProperty; | ||
var keys = Object.keys; | ||
@@ -42,2 +42,22 @@ /** | ||
/** | ||
* @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 | ||
@@ -228,5 +248,6 @@ * | ||
var areObjectsEqual = function areObjectsEqual(objectA, objectB, isEqual, meta) { | ||
var keysA = Object.keys(objectA); | ||
var keysA = keys(objectA); | ||
var keysB = keys(objectB); | ||
if (keysA.length !== Object.keys(objectB).length) { | ||
if (keysA.length !== keysB.length) { | ||
return false; | ||
@@ -240,3 +261,3 @@ } | ||
if (!hasOwnProperty.call(objectB, key)) { | ||
if (!hasKey(keysB, key)) { | ||
return false; | ||
@@ -243,0 +264,0 @@ } |
@@ -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 b="function"==typeof Map,k="function"==typeof Set,o="function"==typeof WeakSet,a=Object.prototype.hasOwnProperty,f=function(e,n){return e&&"object"==typeof e&&n.add(e)},m=function(e,n){return e===n||e!=e&&n!=n},j=function(e){return e.constructor===Object},w=function(e){return"function"==typeof e.then},c=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:(f(e,t),f(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)}},E=function(e,n,t,r){var u=Object.keys(e);if(u.length!==Object.keys(n).length)return!1;for(var i=void 0,o=0;o<u.length;o++){if(i=u[o],!a.call(n,i))return!1;if(("_owner"!==i||!c(e)||!c(n))&&!t(e[i],n[i],r))return!1}return!0},x=Array.isArray,O=t(!0),S=t(!1),r=function(e){var h="function"==typeof e?e(g):g;function g(e,n,t){if(m(e,n))return!0;var r=typeof e;if(r!==typeof n||"object"!==r||!e||!n)return!1;if(j(e)&&j(n))return E(e,n,h,t);var u=x(e),i=x(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&&m(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(b){var p=e instanceof Map,v=n instanceof Map;if(p||v)return p===v&&O(e,n,g,t)}if(k){var y=e instanceof Set,d=n instanceof Set;if(y||d)return y===d&&S(e,n,g,t)}return E(e,n,h,t)}return g},u=r(n()),s=r(n(m)),l=r(),p=r(function(){return m}),v={circularDeep:u,circularShallow:s,createCustom:r,deep:l,sameValueZero:m,shallow:p};e.createCustomEqual=r,e.sameValueZeroEqual=m,e.circularDeepEqual=u,e.circularShallowEqual=s,e.deepEqual=l,e.shallowEqual=p,e.default=v,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 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})}); |
// constants | ||
import { HAS_WEAKSET_SUPPORT } from './constants'; | ||
var hasOwnProperty = Object.prototype.hasOwnProperty; | ||
var keys = Object.keys; | ||
@@ -21,2 +21,22 @@ /** | ||
/** | ||
* @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 | ||
*/ | ||
export var hasKey = function hasKey(keys, key) { | ||
for (var index = 0; index < keys.length; index++) { | ||
if (keys[index] === key) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
}; | ||
/** | ||
* @function sameValueZeroEqual | ||
@@ -207,5 +227,6 @@ * | ||
export var areObjectsEqual = function areObjectsEqual(objectA, objectB, isEqual, meta) { | ||
var keysA = Object.keys(objectA); | ||
var keysA = keys(objectA); | ||
var keysB = keys(objectB); | ||
if (keysA.length !== Object.keys(objectB).length) { | ||
if (keysA.length !== keysB.length) { | ||
return false; | ||
@@ -219,3 +240,3 @@ } | ||
if (!hasOwnProperty.call(objectB, key)) { | ||
if (!hasKey(keysB, key)) { | ||
return false; | ||
@@ -222,0 +243,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.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.hasKey = exports.addObjectToCache = undefined; | ||
var _constants = require('./constants'); | ||
var hasOwnProperty = Object.prototype.hasOwnProperty; | ||
var keys = Object.keys; | ||
@@ -26,2 +26,22 @@ /** | ||
/** | ||
* @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 = exports.hasKey = function hasKey(keys, key) { | ||
for (var index = 0; index < keys.length; index++) { | ||
if (keys[index] === key) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
}; | ||
/** | ||
* @function sameValueZeroEqual | ||
@@ -212,5 +232,6 @@ * | ||
var areObjectsEqual = exports.areObjectsEqual = function areObjectsEqual(objectA, objectB, isEqual, meta) { | ||
var keysA = Object.keys(objectA); | ||
var keysA = keys(objectA); | ||
var keysB = keys(objectB); | ||
if (keysA.length !== Object.keys(objectB).length) { | ||
if (keysA.length !== keysB.length) { | ||
return false; | ||
@@ -224,3 +245,3 @@ } | ||
if (!hasOwnProperty.call(objectB, key)) { | ||
if (!hasKey(keysB, key)) { | ||
return false; | ||
@@ -227,0 +248,0 @@ } |
@@ -96,3 +96,3 @@ { | ||
}, | ||
"version": "1.5.1" | ||
"version": "1.5.2" | ||
} |
@@ -197,13 +197,13 @@ # fast-equals | ||
| -------------------------- | ------------------- | ------------------------ | | ||
| **fast-equals** | **137,723** | **0.72%** | | ||
| nano-equal | 105,151 | 0.89% | | ||
| shallow-equal-fuzzy | 101,882 | 0.88% | | ||
| react-fast-compare | 98,816 | 0.88% | | ||
| fast-deep-equal | 92,431 | 0.81% | | ||
| underscore.isEqual | 61,933 | 0.74% | | ||
| **fast-equals (circular)** | **55,108** | **0.83%** | | ||
| deep-equal | 30,677 | 0.49% | | ||
| lodash.isEqual | 26,706 | 0.63% | | ||
| deep-eql | 16,651 | 0.50% | | ||
| assert.deepStrictEqual | 1,551 | 0.86% | | ||
| **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% | | ||
@@ -210,0 +210,0 @@ Caveats that impact the benchmark (and accuracy of comparison): |
Sorry, the diff of this file is not supported yet
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
376896
1087