Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/fast-deep-equal/index.js')
-rw-r--r--node_modules/fast-deep-equal/index.js59
1 files changed, 25 insertions, 34 deletions
diff --git a/node_modules/fast-deep-equal/index.js b/node_modules/fast-deep-equal/index.js
index 7aaaba3f6..30dd1ba78 100644
--- a/node_modules/fast-deep-equal/index.js
+++ b/node_modules/fast-deep-equal/index.js
@@ -1,55 +1,46 @@
'use strict';
-var isArray = Array.isArray;
-var keyList = Object.keys;
-var hasProp = Object.prototype.hasOwnProperty;
+// do not edit .js files directly - edit src/index.jst
+
+
module.exports = function equal(a, b) {
if (a === b) return true;
- 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 (a && b && typeof a == 'object' && typeof b == 'object') {
+ if (a.constructor !== b.constructor) return false;
+
+ 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;
+ }
- 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 regexpA = a instanceof RegExp
- , regexpB = b instanceof RegExp;
- if (regexpA != regexpB) return false;
- if (regexpA && regexpB) return a.toString() == b.toString();
+ 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();
- if (a instanceof Object && b instanceof Object) {
- var keys = keyList(a);
+ keys = Object.keys(a);
length = keys.length;
+ if (length !== Object.keys(b).length) return false;
- if (length !== keyList(b).length)
- return false;
+ for (i = length; i-- !== 0;)
+ if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
- for (i = 0; i < length; i++)
- if (!hasProp.call(b, keys[i])) return false;
+ for (i = length; i-- !== 0;) {
+ var key = keys[i];
- for (i = 0; i < length; i++) {
- key = keys[i];
if (!equal(a[key], b[key])) return false;
}
return true;
}
- return false;
+ // true if both NaN, false otherwise
+ return a!==a && b!==b;
};