-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
91 lines (91 loc) · 3.04 KB
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
Object.defineProperty(exports, "__esModule", { value: true });
exports.myConsole = Object.create(console, {
assert: {
value: function assert(assertion, message) {
var args = [];
for (var _i = 2; _i < arguments.length; _i++) {
args[_i - 2] = arguments[_i];
}
if (typeof window === "undefined") {
try {
console.assert.apply(console, [assertion, message].concat(args));
}
catch (err) {
console.error(err.stack);
}
}
else {
console.assert.apply(console, [assertion, message].concat(args));
}
},
configurable: true,
enumerable: true,
writable: true,
},
});
exports.equals = function (a, b) {
var reference_equals = function (a, b) {
var object_references = [];
return (reference_equals = _reference_equals)(a, b);
function _reference_equals(a, b) {
var l = object_references.length;
while (l--)
if (object_references[l--] === b)
return object_references[l] === a;
object_references.push(a, b);
return null;
}
};
var _equals = function (a, b) {
var s, l, p, x, y;
if ((s = toString.call(a)) !== toString.call(b))
return false;
switch (s) {
default:
return a.valueOf() === b.valueOf();
case "[object Number]":
a = +a;
b = +b;
return a ?
a === b
:
a === a ?
1 / a === 1 / b
: b !== b;
case "[object RegExp]":
return a.source === b.source
&& a.global === b.global
&& a.ignoreCase === b.ignoreCase
&& a.multiline === b.multiline
&& a.lastIndex === b.lastIndex;
case "[object Function]":
return false;
case "[object Array]":
if ((l = a.length) !== b.length)
return false;
while (l--) {
if ((x = a[l]) === (y = b[l]) && x !== 0 || _equals(x, y))
continue;
return false;
}
return true;
case "[object Object]":
l = 0;
for (p in a) {
if (a.hasOwnProperty(p)) {
++l;
if ((x = a[p]) === (y = b[p]) && x !== 0 || _equals(x, y))
continue;
return false;
}
}
for (p in b)
if (b.hasOwnProperty(p) && --l < 0)
return false;
return true;
}
};
return a === b
&& a !== 0
|| _equals(a, b);
};