@hpcc-js/util 3.5.4 → 3.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/hashSum.ts CHANGED
@@ -1,55 +1,55 @@
1
- // Ported to TypeScript from: https://github.com/bevacqua/hash-sum
2
-
3
- function pad(hash: string, len: number): string {
4
- while (hash.length < len) {
5
- hash = "0" + hash;
6
- }
7
- return hash;
8
- }
9
-
10
- function fold(hash: number, text: string): number {
11
- if (text.length === 0) {
12
- return hash;
13
- }
14
- for (let i = 0; i < text.length; ++i) {
15
- const chr = text.charCodeAt(i);
16
- hash = ((hash << 5) - hash) + chr;
17
- hash |= 0;
18
- }
19
- return hash < 0 ? hash * -2 : hash;
20
- }
21
-
22
- function foldObject(hash: number, o: any, seen: any[]): number {
23
- if (typeof o.hashSum === "function") {
24
- return o.hashSum();
25
- }
26
- return Object.keys(o).sort().reduce((input: any, key: string) => {
27
- return foldValue(input, o[key], key, seen);
28
- }, hash);
29
- }
30
-
31
- function foldValue(input: number, value: any, key: string, seen: any[]): number {
32
- const hash = fold(fold(fold(input, key), toString(value)), typeof value);
33
- if (value === null) {
34
- return fold(hash, "null");
35
- }
36
- if (value === undefined) {
37
- return fold(hash, "undefined");
38
- }
39
- if (typeof value === "object") {
40
- if (seen.indexOf(value) !== -1) {
41
- return fold(hash, "[Circular]" + key);
42
- }
43
- seen.push(value);
44
- return foldObject(hash, value, seen);
45
- }
46
- return fold(hash, value.toString());
47
- }
48
-
49
- function toString(o: any): string {
50
- return Object.prototype.toString.call(o);
51
- }
52
-
53
- export function hashSum(o: any): string {
54
- return pad(foldValue(0, o, "", []).toString(16), 8);
55
- }
1
+ // Ported to TypeScript from: https://github.com/bevacqua/hash-sum
2
+
3
+ function pad(hash: string, len: number): string {
4
+ while (hash.length < len) {
5
+ hash = "0" + hash;
6
+ }
7
+ return hash;
8
+ }
9
+
10
+ function fold(hash: number, text: string): number {
11
+ if (text.length === 0) {
12
+ return hash;
13
+ }
14
+ for (let i = 0; i < text.length; ++i) {
15
+ const chr = text.charCodeAt(i);
16
+ hash = ((hash << 5) - hash) + chr;
17
+ hash |= 0;
18
+ }
19
+ return hash < 0 ? hash * -2 : hash;
20
+ }
21
+
22
+ function foldObject(hash: number, o: any, seen: any[]): number {
23
+ if (typeof o.hashSum === "function") {
24
+ return o.hashSum();
25
+ }
26
+ return Object.keys(o).sort().reduce((input: any, key: string) => {
27
+ return foldValue(input, o[key], key, seen);
28
+ }, hash);
29
+ }
30
+
31
+ function foldValue(input: number, value: any, key: string, seen: any[]): number {
32
+ const hash = fold(fold(fold(input, key), toString(value)), typeof value);
33
+ if (value === null) {
34
+ return fold(hash, "null");
35
+ }
36
+ if (value === undefined) {
37
+ return fold(hash, "undefined");
38
+ }
39
+ if (typeof value === "object") {
40
+ if (seen.indexOf(value) !== -1) {
41
+ return fold(hash, "[Circular]" + key);
42
+ }
43
+ seen.push(value);
44
+ return foldObject(hash, value, seen);
45
+ }
46
+ return fold(hash, value.toString());
47
+ }
48
+
49
+ function toString(o: any): string {
50
+ return Object.prototype.toString.call(o);
51
+ }
52
+
53
+ export function hashSum(o: any): string {
54
+ return pad(foldValue(0, o, "", []).toString(16), 8);
55
+ }
package/src/immutable.ts CHANGED
@@ -1,156 +1,156 @@
1
- const isArray = Array.isArray;
2
- const keyList = Object.keys;
3
- const hasProp = Object.prototype.hasOwnProperty;
4
-
5
- export function verboseDeepEquals(a: any, b: any, functionRefCompare: boolean = false) {
6
- if (a === b) return true;
7
-
8
- if (a && b) {
9
- if (typeof a === "object" && typeof b === "object") {
10
- const arrA = isArray(a);
11
- const arrB = isArray(b);
12
- let i;
13
- let length;
14
- let key;
15
-
16
- if (arrA && arrB) {
17
- length = a.length;
18
- if (length !== b.length) {
19
- console.warn(`lengths not equal: ${length} !== ${b.length}`);
20
- return false;
21
- }
22
- for (i = length; i-- !== 0;)
23
- if (!verboseDeepEquals(a[i], b[i], functionRefCompare)) {
24
- return false;
25
- }
26
- return true;
27
- }
28
-
29
- if (arrA !== arrB) {
30
- console.warn(`arrays not equal: ${arrA} !== ${arrB}`);
31
- return false;
32
- }
33
-
34
- const dateA = a instanceof Date;
35
- const dateB = b instanceof Date;
36
- if (dateA !== dateB) {
37
- console.warn(`dates not equal: ${dateA} !== ${dateB}`);
38
- return false;
39
- }
40
- if (dateA && dateB) {
41
- const retVal = a.getTime() === b.getTime();
42
- if (!retVal) {
43
- console.warn(`dates not equal: ${a.getTime()} !== ${b.getTime()}`);
44
- }
45
- return retVal;
46
- }
47
-
48
- const regexpA = a instanceof RegExp;
49
- const regexpB = b instanceof RegExp;
50
- if (regexpA !== regexpB) {
51
- console.warn(`regexps not equal: ${regexpA} !== ${regexpB}`);
52
- return false;
53
- }
54
- if (regexpA && regexpB) {
55
- const retVal = a.toString() === b.toString();
56
- if (!retVal) {
57
- console.warn(`regexps not equal: ${a.toString()} !== ${b.toString()}`);
58
- }
59
- return retVal;
60
- }
61
-
62
- const keys = keyList(a);
63
- length = keys.length;
64
-
65
- if (length !== keyList(b).length) {
66
- console.warn(`key lengths not equal: ${length} !== ${keyList(b).length}`);
67
- return false;
68
- }
69
-
70
- for (i = length; i-- !== 0;)
71
- if (!hasProp.call(b, keys[i])) {
72
- console.warn(`${keys[i]} in a but not b`);
73
- return false;
74
- }
75
-
76
- for (i = length; i-- !== 0;) {
77
- key = keys[i];
78
- if (!verboseDeepEquals(a[key], b[key], functionRefCompare)) {
79
- return false;
80
- }
81
- }
82
-
83
- return true;
84
- } else if (!functionRefCompare && typeof a === "function" && typeof b === "function") {
85
- const retVal = a.toString() === b.toString();
86
- if (!retVal) {
87
- console.warn(`functions not equal: ${a.toString()} !== ${b.toString()}`);
88
- }
89
- return retVal;
90
- }
91
- }
92
-
93
- const retVal = a !== a && b !== b;
94
- if (!retVal) {
95
- console.warn(`values not equal: ${a} !== ${b}`);
96
- }
97
- return retVal;
98
- }
99
-
100
- export function deepEquals(a: any, b: any, functionRefCompare: boolean = false) {
101
- if (a === b) return true;
102
-
103
- if (a && b) {
104
- if (typeof a === "object" && typeof b === "object") {
105
- const arrA = isArray(a);
106
- const arrB = isArray(b);
107
- let i;
108
- let length;
109
- let key;
110
-
111
- if (arrA && arrB) {
112
- length = a.length;
113
- if (length !== b.length) return false;
114
- for (i = length; i-- !== 0;)
115
- if (!deepEquals(a[i], b[i], functionRefCompare)) return false;
116
- return true;
117
- }
118
-
119
- if (arrA !== arrB) return false;
120
-
121
- const dateA = a instanceof Date;
122
- const dateB = b instanceof Date;
123
- if (dateA !== dateB) return false;
124
- if (dateA && dateB) return a.getTime() === b.getTime();
125
-
126
- const regexpA = a instanceof RegExp;
127
- const regexpB = b instanceof RegExp;
128
- if (regexpA !== regexpB) return false;
129
- if (regexpA && regexpB) return a.toString() === b.toString();
130
-
131
- const keys = keyList(a);
132
- length = keys.length;
133
-
134
- if (length !== keyList(b).length)
135
- return false;
136
-
137
- for (i = length; i-- !== 0;)
138
- if (!hasProp.call(b, keys[i])) return false;
139
-
140
- for (i = length; i-- !== 0;) {
141
- key = keys[i];
142
- if (!deepEquals(a[key], b[key], functionRefCompare)) return false;
143
- }
144
-
145
- return true;
146
- } else if (!functionRefCompare && typeof a === "function" && typeof b === "function") {
147
- return a.toString() === b.toString();
148
- }
149
- }
150
-
151
- return a !== a && b !== b;
152
- }
153
-
154
- export function update<T>(origItem: T, newItem: T, functionRefCompare: boolean = false): T {
155
- return deepEquals(origItem, newItem, functionRefCompare) ? origItem : newItem;
156
- }
1
+ const isArray = Array.isArray;
2
+ const keyList = Object.keys;
3
+ const hasProp = Object.prototype.hasOwnProperty;
4
+
5
+ export function verboseDeepEquals(a: any, b: any, functionRefCompare: boolean = false) {
6
+ if (a === b) return true;
7
+
8
+ if (a && b) {
9
+ if (typeof a === "object" && typeof b === "object") {
10
+ const arrA = isArray(a);
11
+ const arrB = isArray(b);
12
+ let i;
13
+ let length;
14
+ let key;
15
+
16
+ if (arrA && arrB) {
17
+ length = a.length;
18
+ if (length !== b.length) {
19
+ console.warn(`lengths not equal: ${length} !== ${b.length}`);
20
+ return false;
21
+ }
22
+ for (i = length; i-- !== 0;)
23
+ if (!verboseDeepEquals(a[i], b[i], functionRefCompare)) {
24
+ return false;
25
+ }
26
+ return true;
27
+ }
28
+
29
+ if (arrA !== arrB) {
30
+ console.warn(`arrays not equal: ${arrA} !== ${arrB}`);
31
+ return false;
32
+ }
33
+
34
+ const dateA = a instanceof Date;
35
+ const dateB = b instanceof Date;
36
+ if (dateA !== dateB) {
37
+ console.warn(`dates not equal: ${dateA} !== ${dateB}`);
38
+ return false;
39
+ }
40
+ if (dateA && dateB) {
41
+ const retVal = a.getTime() === b.getTime();
42
+ if (!retVal) {
43
+ console.warn(`dates not equal: ${a.getTime()} !== ${b.getTime()}`);
44
+ }
45
+ return retVal;
46
+ }
47
+
48
+ const regexpA = a instanceof RegExp;
49
+ const regexpB = b instanceof RegExp;
50
+ if (regexpA !== regexpB) {
51
+ console.warn(`regexps not equal: ${regexpA} !== ${regexpB}`);
52
+ return false;
53
+ }
54
+ if (regexpA && regexpB) {
55
+ const retVal = a.toString() === b.toString();
56
+ if (!retVal) {
57
+ console.warn(`regexps not equal: ${a.toString()} !== ${b.toString()}`);
58
+ }
59
+ return retVal;
60
+ }
61
+
62
+ const keys = keyList(a);
63
+ length = keys.length;
64
+
65
+ if (length !== keyList(b).length) {
66
+ console.warn(`key lengths not equal: ${length} !== ${keyList(b).length}`);
67
+ return false;
68
+ }
69
+
70
+ for (i = length; i-- !== 0;)
71
+ if (!hasProp.call(b, keys[i])) {
72
+ console.warn(`${keys[i]} in a but not b`);
73
+ return false;
74
+ }
75
+
76
+ for (i = length; i-- !== 0;) {
77
+ key = keys[i];
78
+ if (!verboseDeepEquals(a[key], b[key], functionRefCompare)) {
79
+ return false;
80
+ }
81
+ }
82
+
83
+ return true;
84
+ } else if (!functionRefCompare && typeof a === "function" && typeof b === "function") {
85
+ const retVal = a.toString() === b.toString();
86
+ if (!retVal) {
87
+ console.warn(`functions not equal: ${a.toString()} !== ${b.toString()}`);
88
+ }
89
+ return retVal;
90
+ }
91
+ }
92
+
93
+ const retVal = a !== a && b !== b;
94
+ if (!retVal) {
95
+ console.warn(`values not equal: ${a} !== ${b}`);
96
+ }
97
+ return retVal;
98
+ }
99
+
100
+ export function deepEquals(a: any, b: any, functionRefCompare: boolean = false) {
101
+ if (a === b) return true;
102
+
103
+ if (a && b) {
104
+ if (typeof a === "object" && typeof b === "object") {
105
+ const arrA = isArray(a);
106
+ const arrB = isArray(b);
107
+ let i;
108
+ let length;
109
+ let key;
110
+
111
+ if (arrA && arrB) {
112
+ length = a.length;
113
+ if (length !== b.length) return false;
114
+ for (i = length; i-- !== 0;)
115
+ if (!deepEquals(a[i], b[i], functionRefCompare)) return false;
116
+ return true;
117
+ }
118
+
119
+ if (arrA !== arrB) return false;
120
+
121
+ const dateA = a instanceof Date;
122
+ const dateB = b instanceof Date;
123
+ if (dateA !== dateB) return false;
124
+ if (dateA && dateB) return a.getTime() === b.getTime();
125
+
126
+ const regexpA = a instanceof RegExp;
127
+ const regexpB = b instanceof RegExp;
128
+ if (regexpA !== regexpB) return false;
129
+ if (regexpA && regexpB) return a.toString() === b.toString();
130
+
131
+ const keys = keyList(a);
132
+ length = keys.length;
133
+
134
+ if (length !== keyList(b).length)
135
+ return false;
136
+
137
+ for (i = length; i-- !== 0;)
138
+ if (!hasProp.call(b, keys[i])) return false;
139
+
140
+ for (i = length; i-- !== 0;) {
141
+ key = keys[i];
142
+ if (!deepEquals(a[key], b[key], functionRefCompare)) return false;
143
+ }
144
+
145
+ return true;
146
+ } else if (!functionRefCompare && typeof a === "function" && typeof b === "function") {
147
+ return a.toString() === b.toString();
148
+ }
149
+ }
150
+
151
+ return a !== a && b !== b;
152
+ }
153
+
154
+ export function update<T>(origItem: T, newItem: T, functionRefCompare: boolean = false): T {
155
+ return deepEquals(origItem, newItem, functionRefCompare) ? origItem : newItem;
156
+ }
package/src/index.ts CHANGED
@@ -1,22 +1,22 @@
1
- export * from "./__package__.ts";
2
- export * from "./array.ts";
3
- export * from "./cache.ts";
4
- export * from "./debounce.ts";
5
- export * from "./dictionary.ts";
6
- export * from "./esp.ts";
7
- export * from "./graph.ts";
8
- export * from "./graph2.ts";
9
- export * from "./hashSum.ts";
10
- export * from "./immutable.ts";
11
- export * from "./logging.ts";
12
- export * from "./math.ts";
13
- export * from "./object.ts";
14
- export * from "./observer.ts";
15
- export * from "./dispatch.ts";
16
- export * from "./platform.ts";
17
- export * from "./saxParser.ts";
18
- export * from "./stack.ts";
19
- export * from "./stateful.ts";
20
- export * from "./string.ts";
21
- export * from "./url.ts";
1
+ export * from "./__package__.ts";
2
+ export * from "./array.ts";
3
+ export * from "./cache.ts";
4
+ export * from "./debounce.ts";
5
+ export * from "./dictionary.ts";
6
+ export * from "./esp.ts";
7
+ export * from "./graph.ts";
8
+ export * from "./graph2.ts";
9
+ export * from "./hashSum.ts";
10
+ export * from "./immutable.ts";
11
+ export * from "./logging.ts";
12
+ export * from "./math.ts";
13
+ export * from "./object.ts";
14
+ export * from "./observer.ts";
15
+ export * from "./dispatch.ts";
16
+ export * from "./platform.ts";
17
+ export * from "./saxParser.ts";
18
+ export * from "./stack.ts";
19
+ export * from "./stateful.ts";
20
+ export * from "./string.ts";
21
+ export * from "./url.ts";
22
22
  export * from "./utf8ToBase64.ts";