1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | export function equals(o1: any, o2: any): boolean {
|
16 | if (o1 === o2) return true;
|
17 | if (o1 === null || o2 === null) return false;
|
18 | if (o1 !== o1 && o2 !== o2) return true;
|
19 | let t1 = typeof o1, t2 = typeof o2, length: number, key: any, keySet: any;
|
20 | if (t1 == t2 && t1 == 'object') {
|
21 | if (Array.isArray(o1)) {
|
22 | if (!Array.isArray(o2)) return false;
|
23 | if ((length = o1.length) == o2.length) {
|
24 | for (key = 0; key < length; key++) {
|
25 | if (!equals(o1[key], o2[key])) return false;
|
26 | }
|
27 | return true;
|
28 | }
|
29 | } else {
|
30 | if (Array.isArray(o2)) {
|
31 | return false;
|
32 | }
|
33 | keySet = Object.create(null);
|
34 | for (key in o1) {
|
35 | if (!equals(o1[key], o2[key])) {
|
36 | return false;
|
37 | }
|
38 | keySet[key] = true;
|
39 | }
|
40 | for (key in o2) {
|
41 | if (!(key in keySet) && typeof o2[key] !== 'undefined') {
|
42 | return false;
|
43 | }
|
44 | }
|
45 | return true;
|
46 | }
|
47 | }
|
48 | return false;
|
49 | }
|
50 |
|
51 |
|
52 | export function isDefined(value: any): boolean {
|
53 | return typeof value !== 'undefined' && value !== null;
|
54 | }
|
55 |
|
56 | export function isObject(item: any): boolean {
|
57 | return (item && typeof item === 'object' && !Array.isArray(item));
|
58 | }
|
59 |
|
60 | export function mergeDeep(target: any, source: any): any {
|
61 | let output = Object.assign({}, target);
|
62 | if (isObject(target) && isObject(source)) {
|
63 | Object.keys(source).forEach((key: any) => {
|
64 | if (isObject(source[key])) {
|
65 | if (!(key in target)) {
|
66 | Object.assign(output, {[key]: source[key]});
|
67 | } else {
|
68 | output[key] = mergeDeep(target[key], source[key]);
|
69 | }
|
70 | } else {
|
71 | Object.assign(output, {[key]: source[key]});
|
72 | }
|
73 | });
|
74 | }
|
75 | return output;
|
76 | }
|