Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/fast deep equal@2.0.1 #21

Merged
merged 2 commits into from
Jun 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
55 changes: 30 additions & 25 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,48 @@ var keyList = Object.keys;
var hasProp = Object.prototype.hasOwnProperty;

function equal(a, b) {
// fast-deep-equal index.js 2.0.1
if (a === b) return true;

var arrA = isArray(a)
, arrB = isArray(b)
, i
, length
, key;
if (a && b && typeof a == 'object' && typeof b == 'object') {
var arrA = isArray(a)
, arrB = isArray(b)
, i
, length
, key;

if (arrA && arrB) {
length = a.length;
if (length != b.length) return false;
for (i = 0; i < length; i++)
if (!equal(a[i], b[i])) return false;
return true;
}
if (arrA && arrB) {
length = a.length;
if (length != b.length) return false;
for (i = length; i-- !== 0;)
if (!equal(a[i], b[i])) return false;
return true;
}

if (arrA != arrB) return false;
if (arrA != arrB) return false;

var dateA = a instanceof Date
, dateB = b instanceof Date;
if (dateA != dateB) return false;
if (dateA && dateB) return a.getTime() == b.getTime();
var dateA = a instanceof Date
, dateB = b instanceof Date;
if (dateA != dateB) return false;
if (dateA && dateB) return a.getTime() == b.getTime();

var regexpA = a instanceof RegExp
, regexpB = b instanceof RegExp;
if (regexpA != regexpB) return false;
if (regexpA && regexpB) return a.toString() == b.toString();
var regexpA = a instanceof RegExp
, regexpB = b instanceof RegExp;
if (regexpA != regexpB) return false;
if (regexpA && regexpB) return a.toString() == b.toString();

if (a instanceof Object && b instanceof Object) {
var keys = keyList(a);
length = keys.length;

if (length !== keyList(b).length)
return false;

for (i = 0; i < length; i++)
for (i = length; i-- !== 0;)
if (!hasProp.call(b, keys[i])) return false;
// end fast-deep-equal

for (i = 0; i < length; i++) {
// Custom handling for React
for (i = length; i-- !== 0;) {
key = keys[i];
if (key === '_owner' && a.$$typeof && a._store) {
// React-specific: avoid traversing React elements' _owner.
Expand All @@ -57,11 +60,13 @@ function equal(a, b) {
}
}

// fast-deep-equal index.js 2.0.1
return true;
}

return false;
return a!==a && b!==b;
}
// end fast-deep-equal

module.exports = function exportedEqual(a, b) {
try {
Expand Down