1 | export function isEqual(value, other) {
|
2 | if (value === other) return true;
|
3 | if (value === null || value === undefined) return false;
|
4 | if (typeof value === 'number' && isNaN(value)) return typeof other === 'number' && isNaN(other);
|
5 |
|
6 |
|
7 | if (Array.isArray(value)) {
|
8 | if (!Array.isArray(other)) return false;
|
9 | if (value.length !== other.length) return false;
|
10 |
|
11 | while (value.length) {
|
12 | const index = other.findIndex(_other => isEqual(value[0], _other));
|
13 | if (index === -1) return false;
|
14 |
|
15 | value.splice(0, 1);
|
16 | other.splice(index, 1);
|
17 | }
|
18 |
|
19 | return true;
|
20 | }
|
21 |
|
22 |
|
23 | if (typeof value === 'object') {
|
24 | if (typeof other !== 'object' || Array.isArray(other)) return false;
|
25 | if (Object.keys(value).length !== Object.keys(other).length) return false;
|
26 |
|
27 | let isTrue = true;
|
28 | Object.keys(value).forEach((key) => {
|
29 | isTrue = isTrue && isEqual(value[key], other[key]);
|
30 | });
|
31 |
|
32 | return isTrue;
|
33 | }
|
34 |
|
35 | return false;
|
36 | }
|
37 |
|
38 | export function noop() {}
|