[6a3a178] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | // do not edit .js files directly - edit src/index.jst
|
---|
| 4 |
|
---|
| 5 |
|
---|
| 6 | var envHasBigInt64Array = typeof BigInt64Array !== 'undefined';
|
---|
| 7 |
|
---|
| 8 |
|
---|
| 9 | module.exports = function equal(a, b) {
|
---|
| 10 | if (a === b) return true;
|
---|
| 11 |
|
---|
| 12 | if (a && b && typeof a == 'object' && typeof b == 'object') {
|
---|
| 13 | if (a.constructor !== b.constructor) return false;
|
---|
| 14 |
|
---|
| 15 | var length, i, keys;
|
---|
| 16 | if (Array.isArray(a)) {
|
---|
| 17 | length = a.length;
|
---|
| 18 | if (length != b.length) return false;
|
---|
| 19 | for (i = length; i-- !== 0;)
|
---|
| 20 | if (!equal(a[i], b[i])) return false;
|
---|
| 21 | return true;
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 |
|
---|
| 25 | if ((a instanceof Map) && (b instanceof Map)) {
|
---|
| 26 | if (a.size !== b.size) return false;
|
---|
| 27 | for (i of a.entries())
|
---|
| 28 | if (!b.has(i[0])) return false;
|
---|
| 29 | for (i of a.entries())
|
---|
| 30 | if (!equal(i[1], b.get(i[0]))) return false;
|
---|
| 31 | return true;
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | if ((a instanceof Set) && (b instanceof Set)) {
|
---|
| 35 | if (a.size !== b.size) return false;
|
---|
| 36 | for (i of a.entries())
|
---|
| 37 | if (!b.has(i[0])) return false;
|
---|
| 38 | return true;
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | if (ArrayBuffer.isView(a) && ArrayBuffer.isView(b)) {
|
---|
| 42 | length = a.length;
|
---|
| 43 | if (length != b.length) return false;
|
---|
| 44 | for (i = length; i-- !== 0;)
|
---|
| 45 | if (a[i] !== b[i]) return false;
|
---|
| 46 | return true;
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 |
|
---|
| 50 | if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags;
|
---|
| 51 | if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf();
|
---|
| 52 | if (a.toString !== Object.prototype.toString) return a.toString() === b.toString();
|
---|
| 53 |
|
---|
| 54 | keys = Object.keys(a);
|
---|
| 55 | length = keys.length;
|
---|
| 56 | if (length !== Object.keys(b).length) return false;
|
---|
| 57 |
|
---|
| 58 | for (i = length; i-- !== 0;)
|
---|
| 59 | if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
|
---|
| 60 |
|
---|
| 61 | for (i = length; i-- !== 0;) {
|
---|
| 62 | var key = keys[i];
|
---|
| 63 |
|
---|
| 64 | if (!equal(a[key], b[key])) return false;
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | return true;
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | // true if both NaN, false otherwise
|
---|
| 71 | return a!==a && b!==b;
|
---|
| 72 | };
|
---|