@hpcc-js/util 2.42.0 → 2.46.1
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/LICENSE +43 -43
- package/dist/index.js +2281 -2281
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/lib-es6/__package__.js +3 -3
- package/lib-es6/__package__.js.map +1 -1
- package/lib-es6/array.js +84 -84
- package/lib-es6/cache.js +60 -60
- package/lib-es6/debounce.js +85 -85
- package/lib-es6/dictionary.js +61 -61
- package/lib-es6/dispatch.js +101 -101
- package/lib-es6/esp.js +32 -32
- package/lib-es6/graph.js +348 -348
- package/lib-es6/graph2.js +603 -603
- package/lib-es6/hashSum.js +49 -49
- package/lib-es6/immutable.js +54 -54
- package/lib-es6/index.js +21 -21
- package/lib-es6/logging.js +177 -177
- package/lib-es6/math.js +90 -90
- package/lib-es6/object.js +121 -121
- package/lib-es6/observer.js +79 -79
- package/lib-es6/platform.js +17 -17
- package/lib-es6/saxParser.js +125 -125
- package/lib-es6/stack.js +41 -41
- package/lib-es6/stateful.js +170 -170
- package/lib-es6/string.js +22 -22
- package/lib-es6/url.js +32 -32
- package/package.json +7 -21
- package/src/__package__.ts +2 -2
- package/src/array.ts +98 -98
- package/src/cache.ts +65 -65
- package/src/debounce.ts +88 -88
- package/src/dictionary.ts +69 -69
- package/src/dispatch.ts +119 -119
- package/src/esp.ts +32 -32
- package/src/graph.ts +353 -353
- package/src/graph2.ts +661 -661
- package/src/hashSum.ts +55 -55
- package/src/immutable.ts +57 -57
- package/src/index.ts +21 -21
- package/src/logging.ts +211 -211
- package/src/math.ts +92 -92
- package/src/object.ts +117 -117
- package/src/observer.ts +91 -91
- package/src/platform.ts +20 -20
- package/src/saxParser.ts +135 -135
- package/src/stack.ts +41 -41
- package/src/stateful.ts +178 -178
- package/src/string.ts +21 -21
- package/src/url.ts +27 -27
- package/types/__package__.d.ts +3 -3
- package/types/__package__.d.ts.map +1 -1
- package/types/array.d.ts +13 -13
- package/types/cache.d.ts +20 -20
- package/types/debounce.d.ts +12 -12
- package/types/dictionary.d.ts +20 -20
- package/types/dispatch.d.ts +26 -26
- package/types/esp.d.ts +1 -1
- package/types/graph.d.ts +73 -73
- package/types/graph2.d.ts +111 -111
- package/types/hashSum.d.ts +1 -1
- package/types/immutable.d.ts +2 -2
- package/types/index.d.ts +21 -21
- package/types/logging.d.ts +57 -57
- package/types/math.d.ts +70 -70
- package/types/object.d.ts +48 -48
- package/types/observer.d.ts +18 -18
- package/types/platform.d.ts +5 -5
- package/types/saxParser.d.ts +28 -28
- package/types/stack.d.ts +28 -28
- package/types/stateful.d.ts +33 -33
- package/types/string.d.ts +2 -2
- package/types/url.d.ts +2 -2
- package/types-3.4/__package__.d.ts +2 -2
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,57 +1,57 @@
|
|
|
1
|
-
const isArray = Array.isArray;
|
|
2
|
-
const keyList = Object.keys;
|
|
3
|
-
const hasProp = Object.prototype.hasOwnProperty;
|
|
4
|
-
|
|
5
|
-
export function deepEquals(a: any, b: any) {
|
|
6
|
-
if (a === b) return true;
|
|
7
|
-
|
|
8
|
-
if (a && b && typeof a === "object" && typeof b === "object") {
|
|
9
|
-
const arrA = isArray(a);
|
|
10
|
-
const arrB = isArray(b);
|
|
11
|
-
let i;
|
|
12
|
-
let length;
|
|
13
|
-
let key;
|
|
14
|
-
|
|
15
|
-
if (arrA && arrB) {
|
|
16
|
-
length = a.length;
|
|
17
|
-
if (length !== b.length) return false;
|
|
18
|
-
for (i = length; i-- !== 0;)
|
|
19
|
-
if (!deepEquals(a[i], b[i])) return false;
|
|
20
|
-
return true;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (arrA !== arrB) return false;
|
|
24
|
-
|
|
25
|
-
const dateA = a instanceof Date;
|
|
26
|
-
const dateB = b instanceof Date;
|
|
27
|
-
if (dateA !== dateB) return false;
|
|
28
|
-
if (dateA && dateB) return a.getTime() === b.getTime();
|
|
29
|
-
|
|
30
|
-
const regexpA = a instanceof RegExp;
|
|
31
|
-
const regexpB = b instanceof RegExp;
|
|
32
|
-
if (regexpA !== regexpB) return false;
|
|
33
|
-
if (regexpA && regexpB) return a.toString() === b.toString();
|
|
34
|
-
|
|
35
|
-
const keys = keyList(a);
|
|
36
|
-
length = keys.length;
|
|
37
|
-
|
|
38
|
-
if (length !== keyList(b).length)
|
|
39
|
-
return false;
|
|
40
|
-
|
|
41
|
-
for (i = length; i-- !== 0;)
|
|
42
|
-
if (!hasProp.call(b, keys[i])) return false;
|
|
43
|
-
|
|
44
|
-
for (i = length; i-- !== 0;) {
|
|
45
|
-
key = keys[i];
|
|
46
|
-
if (!deepEquals(a[key], b[key])) return false;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return true;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return a !== a && b !== b;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export function update<T>(origItem: T, newItem: T): T {
|
|
56
|
-
return deepEquals(origItem, newItem) ? origItem : newItem;
|
|
57
|
-
}
|
|
1
|
+
const isArray = Array.isArray;
|
|
2
|
+
const keyList = Object.keys;
|
|
3
|
+
const hasProp = Object.prototype.hasOwnProperty;
|
|
4
|
+
|
|
5
|
+
export function deepEquals(a: any, b: any) {
|
|
6
|
+
if (a === b) return true;
|
|
7
|
+
|
|
8
|
+
if (a && b && typeof a === "object" && typeof b === "object") {
|
|
9
|
+
const arrA = isArray(a);
|
|
10
|
+
const arrB = isArray(b);
|
|
11
|
+
let i;
|
|
12
|
+
let length;
|
|
13
|
+
let key;
|
|
14
|
+
|
|
15
|
+
if (arrA && arrB) {
|
|
16
|
+
length = a.length;
|
|
17
|
+
if (length !== b.length) return false;
|
|
18
|
+
for (i = length; i-- !== 0;)
|
|
19
|
+
if (!deepEquals(a[i], b[i])) return false;
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (arrA !== arrB) return false;
|
|
24
|
+
|
|
25
|
+
const dateA = a instanceof Date;
|
|
26
|
+
const dateB = b instanceof Date;
|
|
27
|
+
if (dateA !== dateB) return false;
|
|
28
|
+
if (dateA && dateB) return a.getTime() === b.getTime();
|
|
29
|
+
|
|
30
|
+
const regexpA = a instanceof RegExp;
|
|
31
|
+
const regexpB = b instanceof RegExp;
|
|
32
|
+
if (regexpA !== regexpB) return false;
|
|
33
|
+
if (regexpA && regexpB) return a.toString() === b.toString();
|
|
34
|
+
|
|
35
|
+
const keys = keyList(a);
|
|
36
|
+
length = keys.length;
|
|
37
|
+
|
|
38
|
+
if (length !== keyList(b).length)
|
|
39
|
+
return false;
|
|
40
|
+
|
|
41
|
+
for (i = length; i-- !== 0;)
|
|
42
|
+
if (!hasProp.call(b, keys[i])) return false;
|
|
43
|
+
|
|
44
|
+
for (i = length; i-- !== 0;) {
|
|
45
|
+
key = keys[i];
|
|
46
|
+
if (!deepEquals(a[key], b[key])) return false;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return a !== a && b !== b;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function update<T>(origItem: T, newItem: T): T {
|
|
56
|
+
return deepEquals(origItem, newItem) ? origItem : newItem;
|
|
57
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
export * from "./__package__";
|
|
2
|
-
export * from "./array";
|
|
3
|
-
export * from "./cache";
|
|
4
|
-
export * from "./debounce";
|
|
5
|
-
export * from "./dictionary";
|
|
6
|
-
export * from "./esp";
|
|
7
|
-
export * from "./graph";
|
|
8
|
-
export * from "./graph2";
|
|
9
|
-
export * from "./hashSum";
|
|
10
|
-
export * from "./immutable";
|
|
11
|
-
export * from "./logging";
|
|
12
|
-
export * from "./math";
|
|
13
|
-
export * from "./object";
|
|
14
|
-
export * from "./observer";
|
|
15
|
-
export * from "./dispatch";
|
|
16
|
-
export * from "./platform";
|
|
17
|
-
export * from "./saxParser";
|
|
18
|
-
export * from "./stack";
|
|
19
|
-
export * from "./stateful";
|
|
20
|
-
export * from "./string";
|
|
21
|
-
export * from "./url";
|
|
1
|
+
export * from "./__package__";
|
|
2
|
+
export * from "./array";
|
|
3
|
+
export * from "./cache";
|
|
4
|
+
export * from "./debounce";
|
|
5
|
+
export * from "./dictionary";
|
|
6
|
+
export * from "./esp";
|
|
7
|
+
export * from "./graph";
|
|
8
|
+
export * from "./graph2";
|
|
9
|
+
export * from "./hashSum";
|
|
10
|
+
export * from "./immutable";
|
|
11
|
+
export * from "./logging";
|
|
12
|
+
export * from "./math";
|
|
13
|
+
export * from "./object";
|
|
14
|
+
export * from "./observer";
|
|
15
|
+
export * from "./dispatch";
|
|
16
|
+
export * from "./platform";
|
|
17
|
+
export * from "./saxParser";
|
|
18
|
+
export * from "./stack";
|
|
19
|
+
export * from "./stateful";
|
|
20
|
+
export * from "./string";
|
|
21
|
+
export * from "./url";
|