UNPKG

916 BPlain TextView Raw
1import _each from '@antv/util/lib/each';
2import _isArray from '@antv/util/lib/is-array';
3import _isObject from '@antv/util/lib/is-object';
4
5function is(x, y) {
6 if (x === y) {
7 return x !== 0 || y !== 0 || 1 / x === 1 / y;
8 }
9 return x !== x && y !== y; // NaN == NaN
10}
11
12function length(obj) {
13 if (_isArray(obj)) {
14 return obj.length;
15 }
16 if (_isObject(obj)) {
17 return Object.keys(obj).length;
18 }
19 return 0;
20}
21
22export default function(objA, objB) {
23 if (is(objA, objB)) {
24 return true;
25 }
26
27 if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
28 return false;
29 }
30
31 if (_isArray(objA) !== _isArray(objB)) {
32 return false;
33 }
34
35 if (length(objA) !== length(objB)) {
36 return false;
37 }
38
39 let ret = true;
40
41 _each(objA, (v, k) => {
42 if (!is(v, objB[k])) {
43 ret = false;
44 return ret;
45 }
46 return true;
47 });
48
49 return ret;
50}