-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathutils.js
34 lines (31 loc) · 868 Bytes
/
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
function isSame(a, b) {
if (a.length != b.length) return false;
if (a.filter(function (i) { return a.indexOf(i) < 0; }).length > 0)
return false;
if (b.filter(function (i) { return a.indexOf(i) < 0; }).length > 0)
return false;
return true;
};
function substract(a, b) {
var r = {};
for (var key in b) {
if (Array.isArray(b[key])) {
if (!a[key]) a[key] = [];
if (!isSame(a[key], b[key]))
r[key] = a[key];
} else if (typeof (b[key]) == 'object') {
if (!a[key]) a[key] = {};
r[key] = substract(a[key], b[key]);
if (Object.keys(r[key]).length == 0)
delete r[key];
} else {
if (b[key] != a[key]) {
r[key] = a[key];
}
}
}
return r;
}
export {
substract
}