2017-12-15 10:56:14 -08:00
|
|
|
'use strict';
|
|
|
|
|
2021-05-08 05:39:21 -07:00
|
|
|
// do not edit .js files directly - edit src/index.jst
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-12-15 10:56:14 -08:00
|
|
|
module.exports = function equal(a, b) {
|
|
|
|
if (a === b) return true;
|
|
|
|
|
2021-05-08 05:39:21 -07:00
|
|
|
if (a && b && typeof a == 'object' && typeof b == 'object') {
|
|
|
|
if (a.constructor !== b.constructor) return false;
|
2017-12-15 10:56:14 -08:00
|
|
|
|
2021-05-08 05:39:21 -07:00
|
|
|
var length, i, keys;
|
|
|
|
if (Array.isArray(a)) {
|
|
|
|
length = a.length;
|
|
|
|
if (length != b.length) return false;
|
|
|
|
for (i = length; i-- !== 0;)
|
|
|
|
if (!equal(a[i], b[i])) return false;
|
|
|
|
return true;
|
|
|
|
}
|
2017-12-15 10:56:14 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
2021-05-08 05:39:21 -07:00
|
|
|
if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags;
|
|
|
|
if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf();
|
|
|
|
if (a.toString !== Object.prototype.toString) return a.toString() === b.toString();
|
2017-12-15 10:56:14 -08:00
|
|
|
|
2021-05-08 05:39:21 -07:00
|
|
|
keys = Object.keys(a);
|
|
|
|
length = keys.length;
|
|
|
|
if (length !== Object.keys(b).length) return false;
|
2017-12-15 10:56:14 -08:00
|
|
|
|
2021-05-08 05:39:21 -07:00
|
|
|
for (i = length; i-- !== 0;)
|
2017-12-15 10:56:14 -08:00
|
|
|
if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
|
|
|
|
|
2021-05-08 05:39:21 -07:00
|
|
|
for (i = length; i-- !== 0;) {
|
|
|
|
var key = keys[i];
|
|
|
|
|
|
|
|
if (!equal(a[key], b[key])) return false;
|
|
|
|
}
|
2017-12-15 10:56:14 -08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-05-08 05:39:21 -07:00
|
|
|
// true if both NaN, false otherwise
|
|
|
|
return a!==a && b!==b;
|
2017-12-15 10:56:14 -08:00
|
|
|
};
|