1 |
|
2 |
|
3 |
|
4 |
|
5 | module.exports = _deepEqual;
|
6 |
|
7 | function _deepEqual(actual, expected) {
|
8 |
|
9 | if (actual === expected) {
|
10 | return true;
|
11 |
|
12 | } else if (Buffer.isBuffer(actual) && Buffer.isBuffer(expected)) {
|
13 | if (actual.length != expected.length) return false;
|
14 |
|
15 | for (var i = 0; i < actual.length; i++) {
|
16 | if (actual[i] !== expected[i]) return false;
|
17 | }
|
18 |
|
19 | return true;
|
20 |
|
21 |
|
22 |
|
23 | } else if (actual instanceof Date && expected instanceof Date) {
|
24 | return actual.getTime() === expected.getTime();
|
25 |
|
26 |
|
27 |
|
28 | } else if (typeof actual != 'object' && typeof expected != 'object') {
|
29 | return actual === expected;
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 | } else {
|
38 | return objEquiv(actual, expected);
|
39 | }
|
40 | }
|
41 |
|
42 | function isUndefinedOrNull (value) {
|
43 | return value === null || value === undefined;
|
44 | }
|
45 |
|
46 | function isArguments (object) {
|
47 | return Object.prototype.toString.call(object) == '[object Arguments]';
|
48 | }
|
49 |
|
50 | function objEquiv (a, b) {
|
51 | if (isUndefinedOrNull(a) || isUndefinedOrNull(b))
|
52 | return false;
|
53 |
|
54 | if (a.prototype !== b.prototype) return false;
|
55 |
|
56 |
|
57 | if (isArguments(a)) {
|
58 | if (!isArguments(b)) {
|
59 | return false;
|
60 | }
|
61 | a = pSlice.call(a);
|
62 | b = pSlice.call(b);
|
63 | return _deepEqual(a, b);
|
64 | }
|
65 | try{
|
66 | var ka = Object.keys(a),
|
67 | kb = Object.keys(b),
|
68 | key, i;
|
69 | } catch (e) {
|
70 | return false;
|
71 | }
|
72 |
|
73 | if (ka.length != kb.length)
|
74 | return false;
|
75 |
|
76 | ka.sort();
|
77 | kb.sort();
|
78 |
|
79 | for (i = ka.length - 1; i >= 0; i--) {
|
80 | if (ka[i] != kb[i])
|
81 | return false;
|
82 | }
|
83 |
|
84 |
|
85 | for (i = ka.length - 1; i >= 0; i--) {
|
86 | key = ka[i];
|
87 | if (!_deepEqual(a[key], b[key] ))
|
88 | return false;
|
89 | }
|
90 | return true;
|
91 | }
|