@hpcc-js/util 2.46.1 → 2.47.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.
Files changed (79) hide show
  1. package/LICENSE +43 -43
  2. package/dist/index.js +2373 -2281
  3. package/dist/index.js.map +1 -1
  4. package/dist/index.min.js +1 -1
  5. package/dist/index.min.js.map +1 -1
  6. package/lib-es6/__package__.js +3 -3
  7. package/lib-es6/array.js +84 -84
  8. package/lib-es6/cache.js +60 -60
  9. package/lib-es6/debounce.js +85 -85
  10. package/lib-es6/dictionary.js +61 -61
  11. package/lib-es6/dispatch.js +101 -101
  12. package/lib-es6/esp.js +32 -32
  13. package/lib-es6/graph.js +348 -348
  14. package/lib-es6/graph2.js +603 -603
  15. package/lib-es6/hashSum.js +49 -49
  16. package/lib-es6/immutable.js +144 -54
  17. package/lib-es6/immutable.js.map +1 -1
  18. package/lib-es6/index.js +21 -21
  19. package/lib-es6/logging.js +178 -177
  20. package/lib-es6/logging.js.map +1 -1
  21. package/lib-es6/math.js +90 -90
  22. package/lib-es6/object.js +121 -121
  23. package/lib-es6/observer.js +79 -79
  24. package/lib-es6/platform.js +17 -17
  25. package/lib-es6/saxParser.js +125 -125
  26. package/lib-es6/stack.js +41 -41
  27. package/lib-es6/stateful.js +170 -170
  28. package/lib-es6/string.js +22 -22
  29. package/lib-es6/url.js +32 -32
  30. package/package.json +3 -3
  31. package/src/__package__.ts +2 -2
  32. package/src/array.ts +98 -98
  33. package/src/cache.ts +65 -65
  34. package/src/debounce.ts +88 -88
  35. package/src/dictionary.ts +69 -69
  36. package/src/dispatch.ts +119 -119
  37. package/src/esp.ts +32 -32
  38. package/src/graph.ts +353 -353
  39. package/src/graph2.ts +661 -661
  40. package/src/hashSum.ts +55 -55
  41. package/src/immutable.ts +156 -57
  42. package/src/index.ts +21 -21
  43. package/src/logging.ts +212 -211
  44. package/src/math.ts +92 -92
  45. package/src/object.ts +117 -117
  46. package/src/observer.ts +91 -91
  47. package/src/platform.ts +20 -20
  48. package/src/saxParser.ts +135 -135
  49. package/src/stack.ts +41 -41
  50. package/src/stateful.ts +178 -178
  51. package/src/string.ts +21 -21
  52. package/src/url.ts +27 -27
  53. package/types/__package__.d.ts +3 -3
  54. package/types/array.d.ts +13 -13
  55. package/types/cache.d.ts +20 -20
  56. package/types/debounce.d.ts +12 -12
  57. package/types/dictionary.d.ts +20 -20
  58. package/types/dispatch.d.ts +26 -26
  59. package/types/dispatch.d.ts.map +1 -1
  60. package/types/esp.d.ts +1 -1
  61. package/types/graph.d.ts +73 -73
  62. package/types/graph2.d.ts +111 -111
  63. package/types/hashSum.d.ts +1 -1
  64. package/types/immutable.d.ts +3 -2
  65. package/types/immutable.d.ts.map +1 -1
  66. package/types/index.d.ts +21 -21
  67. package/types/logging.d.ts +57 -57
  68. package/types/logging.d.ts.map +1 -1
  69. package/types/math.d.ts +70 -70
  70. package/types/object.d.ts +48 -48
  71. package/types/observer.d.ts +18 -18
  72. package/types/platform.d.ts +5 -5
  73. package/types/saxParser.d.ts +28 -28
  74. package/types/stack.d.ts +28 -28
  75. package/types/stateful.d.ts +33 -33
  76. package/types/string.d.ts +2 -2
  77. package/types/url.d.ts +2 -2
  78. package/types-3.4/__package__.d.ts +2 -2
  79. package/types-3.4/immutable.d.ts +1 -0
package/src/object.ts CHANGED
@@ -1,117 +1,117 @@
1
- /**
2
- * inner - return inner property of Object
3
- * Usage: inner("some.prop.to.locate", obj);
4
- *
5
- * @param prop - property to locate
6
- * @param obj - object to locate property in
7
- */
8
- export function inner(prop: string, obj: any): any {
9
- if (prop === void 0 || obj === void 0) return void 0;
10
- for (const item of prop.split(".")) {
11
- if (!obj.hasOwnProperty(item)) {
12
- return undefined;
13
- }
14
- obj = obj[item];
15
- }
16
- return obj;
17
- }
18
-
19
- /**
20
- * exists - return true if inner property of Object exists
21
- * Usage: exists("some.prop.to.locate", obj);
22
- *
23
- * @param prop - property to locate
24
- * @param obj - object to locate property in
25
- */
26
- export function exists(prop: string, obj: any): boolean {
27
- return inner(prop, obj) !== undefined;
28
- }
29
-
30
- function _mixin(dest: any, source: any): any {
31
- const empty: any = {};
32
- for (const key in source) {
33
- if (!source.hasOwnProperty(key)) continue;
34
- if (key === "__proto__" || key === "constructor") continue;
35
- let s: any = source[key];
36
- if (s instanceof Array) {
37
- // TODO: Do we need to support arrays?
38
- } else if (typeof s === "object") {
39
- s = deepMixin(dest[key], s);
40
- }
41
- if (!(key in dest) || (dest[key] !== s && (!(key in empty) || empty[key] !== s))) {
42
- dest[key] = s;
43
- }
44
- }
45
- return dest;
46
- }
47
-
48
- /**
49
- * deepMixin - combine several objects from right to left
50
- * Usage: deepMixin({a: "a"}, {b: "b"});
51
- *
52
- * @param dest - target object to mix into.
53
- * @param sources - objects to mix in
54
- */
55
- export function deepMixin(dest: any = {}, ...sources: any[]): any {
56
- if (typeof dest !== "object") throw new Error(`Destination "${dest}" must be an object.`);
57
- for (const source of sources) {
58
- _mixin(dest, source);
59
- }
60
- return dest;
61
- }
62
-
63
- /**
64
- * deepMixinT - combine several objects of Partial<T> from right to left
65
- * Usage: deepMixinT<MyInterface>({a: "a"}, {b: "b"});
66
- *
67
- * Note: Only provided as a convenience, so user gets auto completion based on destination type.
68
- *
69
- * @param dest - target object to mix into.
70
- * @param sources - objects to mix in
71
- */
72
- export function deepMixinT<T>(dest: Partial<T> = {}, ...sources: Array<Partial<T>>): T {
73
- return deepMixin(dest, ...sources);
74
- }
75
-
76
- /**
77
- * safeStingify - JSONsimilar to .stringify, except ignores circular references.
78
- * Usage: safeStingify(object);
79
- *
80
- * @param obj - any object.
81
- */
82
- export function safeStringify(obj: object) {
83
- const cache: any[] = [];
84
- return JSON.stringify(obj, function (key, value) {
85
- if (typeof value === "object" && value !== null) {
86
- if (cache.indexOf(value) !== -1) {
87
- return;
88
- }
89
-
90
- cache.push(value);
91
- }
92
- return value;
93
- });
94
- }
95
-
96
- export function isArray(arg: any): arg is any[] {
97
- if (Array.isArray !== undefined) {
98
- return Array.isArray(arg);
99
- }
100
- return Object.prototype.toString.call(arg) === "[object Array]";
101
- }
102
-
103
- export interface ClassMeta {
104
- module: string;
105
- file: string;
106
- class: string;
107
- }
108
-
109
- export function classID2Meta(classID: string): ClassMeta {
110
- const info = classID.split("_");
111
- const classInfo = info[1].split(".");
112
- return {
113
- module: `@hpcc-js/${info[0]}`,
114
- file: classInfo[0],
115
- class: classInfo[1] || classInfo[0]
116
- };
117
- }
1
+ /**
2
+ * inner - return inner property of Object
3
+ * Usage: inner("some.prop.to.locate", obj);
4
+ *
5
+ * @param prop - property to locate
6
+ * @param obj - object to locate property in
7
+ */
8
+ export function inner(prop: string, obj: any): any {
9
+ if (prop === void 0 || obj === void 0) return void 0;
10
+ for (const item of prop.split(".")) {
11
+ if (!obj.hasOwnProperty(item)) {
12
+ return undefined;
13
+ }
14
+ obj = obj[item];
15
+ }
16
+ return obj;
17
+ }
18
+
19
+ /**
20
+ * exists - return true if inner property of Object exists
21
+ * Usage: exists("some.prop.to.locate", obj);
22
+ *
23
+ * @param prop - property to locate
24
+ * @param obj - object to locate property in
25
+ */
26
+ export function exists(prop: string, obj: any): boolean {
27
+ return inner(prop, obj) !== undefined;
28
+ }
29
+
30
+ function _mixin(dest: any, source: any): any {
31
+ const empty: any = {};
32
+ for (const key in source) {
33
+ if (!source.hasOwnProperty(key)) continue;
34
+ if (key === "__proto__" || key === "constructor") continue;
35
+ let s: any = source[key];
36
+ if (s instanceof Array) {
37
+ // TODO: Do we need to support arrays?
38
+ } else if (typeof s === "object") {
39
+ s = deepMixin(dest[key], s);
40
+ }
41
+ if (!(key in dest) || (dest[key] !== s && (!(key in empty) || empty[key] !== s))) {
42
+ dest[key] = s;
43
+ }
44
+ }
45
+ return dest;
46
+ }
47
+
48
+ /**
49
+ * deepMixin - combine several objects from right to left
50
+ * Usage: deepMixin({a: "a"}, {b: "b"});
51
+ *
52
+ * @param dest - target object to mix into.
53
+ * @param sources - objects to mix in
54
+ */
55
+ export function deepMixin(dest: any = {}, ...sources: any[]): any {
56
+ if (typeof dest !== "object") throw new Error(`Destination "${dest}" must be an object.`);
57
+ for (const source of sources) {
58
+ _mixin(dest, source);
59
+ }
60
+ return dest;
61
+ }
62
+
63
+ /**
64
+ * deepMixinT - combine several objects of Partial<T> from right to left
65
+ * Usage: deepMixinT<MyInterface>({a: "a"}, {b: "b"});
66
+ *
67
+ * Note: Only provided as a convenience, so user gets auto completion based on destination type.
68
+ *
69
+ * @param dest - target object to mix into.
70
+ * @param sources - objects to mix in
71
+ */
72
+ export function deepMixinT<T>(dest: Partial<T> = {}, ...sources: Array<Partial<T>>): T {
73
+ return deepMixin(dest, ...sources);
74
+ }
75
+
76
+ /**
77
+ * safeStingify - JSONsimilar to .stringify, except ignores circular references.
78
+ * Usage: safeStingify(object);
79
+ *
80
+ * @param obj - any object.
81
+ */
82
+ export function safeStringify(obj: object) {
83
+ const cache: any[] = [];
84
+ return JSON.stringify(obj, function (key, value) {
85
+ if (typeof value === "object" && value !== null) {
86
+ if (cache.indexOf(value) !== -1) {
87
+ return;
88
+ }
89
+
90
+ cache.push(value);
91
+ }
92
+ return value;
93
+ });
94
+ }
95
+
96
+ export function isArray(arg: any): arg is any[] {
97
+ if (Array.isArray !== undefined) {
98
+ return Array.isArray(arg);
99
+ }
100
+ return Object.prototype.toString.call(arg) === "[object Array]";
101
+ }
102
+
103
+ export interface ClassMeta {
104
+ module: string;
105
+ file: string;
106
+ class: string;
107
+ }
108
+
109
+ export function classID2Meta(classID: string): ClassMeta {
110
+ const info = classID.split("_");
111
+ const classInfo = info[1].split(".");
112
+ return {
113
+ module: `@hpcc-js/${info[0]}`,
114
+ file: classInfo[0],
115
+ class: classInfo[1] || classInfo[0]
116
+ };
117
+ }
package/src/observer.ts CHANGED
@@ -1,91 +1,91 @@
1
- /**
2
- * IObserverHandle - Reference to an observing instance
3
- */
4
- export interface IObserverHandle {
5
- release(): void;
6
- unwatch(): void;
7
- }
8
-
9
- export type CallbackFunction = (...args: any[]) => void;
10
-
11
- class ObserverHandle<T extends string> implements IObserverHandle {
12
- private eventTarget: Observable<T>;
13
- private eventID: T;
14
- private callback: CallbackFunction;
15
-
16
- constructor(eventTarget: Observable<T>, eventID: T, callback: CallbackFunction) {
17
- this.eventTarget = eventTarget;
18
- this.eventID = eventID;
19
- this.callback = callback;
20
- }
21
-
22
- release() {
23
- this.eventTarget.removeObserver(this.eventID, this.callback);
24
- }
25
-
26
- unwatch() {
27
- this.release();
28
- }
29
- }
30
-
31
- export type EventID = string;
32
- export class Observable<T extends EventID> {
33
- private _eventObservers: { [eventID: string]: CallbackFunction[] } = {};
34
-
35
- constructor(...events: T[]) {
36
- }
37
-
38
- addObserver(eventID: T, callback: CallbackFunction): IObserverHandle {
39
- let eventObservers: CallbackFunction[] = this._eventObservers[eventID];
40
- if (!eventObservers) {
41
- eventObservers = [];
42
- this._eventObservers[eventID] = eventObservers;
43
- }
44
- eventObservers.push(callback);
45
- return new ObserverHandle<T>(this, eventID, callback);
46
- }
47
-
48
- removeObserver(eventID: T, callback: CallbackFunction): this {
49
- const eventObservers = this._eventObservers[eventID];
50
- if (eventObservers) {
51
- for (let i = eventObservers.length - 1; i >= 0; --i) {
52
- if (eventObservers[i] === callback) {
53
- eventObservers.splice(i, 1);
54
- }
55
- }
56
- }
57
- return this;
58
- }
59
-
60
- dispatchEvent(eventID: T, ...args: any[]): this {
61
- const eventObservers = this._eventObservers[eventID];
62
- if (eventObservers) {
63
- for (const observer of eventObservers) {
64
- observer(...args);
65
- }
66
- }
67
- return this;
68
- }
69
-
70
- private _hasObserver(eventID: string): boolean {
71
- const eventObservers = this._eventObservers[eventID];
72
- for (const observer in eventObservers) {
73
- if (eventObservers[observer]) {
74
- return true;
75
- }
76
- }
77
- return false;
78
- }
79
-
80
- hasObserver(_eventID?: T): boolean {
81
- if (_eventID !== void 0) {
82
- return this._hasObserver(_eventID);
83
- }
84
- for (const eventID in this._eventObservers) {
85
- if (this._hasObserver(eventID)) {
86
- return true;
87
- }
88
- }
89
- return false;
90
- }
91
- }
1
+ /**
2
+ * IObserverHandle - Reference to an observing instance
3
+ */
4
+ export interface IObserverHandle {
5
+ release(): void;
6
+ unwatch(): void;
7
+ }
8
+
9
+ export type CallbackFunction = (...args: any[]) => void;
10
+
11
+ class ObserverHandle<T extends string> implements IObserverHandle {
12
+ private eventTarget: Observable<T>;
13
+ private eventID: T;
14
+ private callback: CallbackFunction;
15
+
16
+ constructor(eventTarget: Observable<T>, eventID: T, callback: CallbackFunction) {
17
+ this.eventTarget = eventTarget;
18
+ this.eventID = eventID;
19
+ this.callback = callback;
20
+ }
21
+
22
+ release() {
23
+ this.eventTarget.removeObserver(this.eventID, this.callback);
24
+ }
25
+
26
+ unwatch() {
27
+ this.release();
28
+ }
29
+ }
30
+
31
+ export type EventID = string;
32
+ export class Observable<T extends EventID> {
33
+ private _eventObservers: { [eventID: string]: CallbackFunction[] } = {};
34
+
35
+ constructor(...events: T[]) {
36
+ }
37
+
38
+ addObserver(eventID: T, callback: CallbackFunction): IObserverHandle {
39
+ let eventObservers: CallbackFunction[] = this._eventObservers[eventID];
40
+ if (!eventObservers) {
41
+ eventObservers = [];
42
+ this._eventObservers[eventID] = eventObservers;
43
+ }
44
+ eventObservers.push(callback);
45
+ return new ObserverHandle<T>(this, eventID, callback);
46
+ }
47
+
48
+ removeObserver(eventID: T, callback: CallbackFunction): this {
49
+ const eventObservers = this._eventObservers[eventID];
50
+ if (eventObservers) {
51
+ for (let i = eventObservers.length - 1; i >= 0; --i) {
52
+ if (eventObservers[i] === callback) {
53
+ eventObservers.splice(i, 1);
54
+ }
55
+ }
56
+ }
57
+ return this;
58
+ }
59
+
60
+ dispatchEvent(eventID: T, ...args: any[]): this {
61
+ const eventObservers = this._eventObservers[eventID];
62
+ if (eventObservers) {
63
+ for (const observer of eventObservers) {
64
+ observer(...args);
65
+ }
66
+ }
67
+ return this;
68
+ }
69
+
70
+ private _hasObserver(eventID: string): boolean {
71
+ const eventObservers = this._eventObservers[eventID];
72
+ for (const observer in eventObservers) {
73
+ if (eventObservers[observer]) {
74
+ return true;
75
+ }
76
+ }
77
+ return false;
78
+ }
79
+
80
+ hasObserver(_eventID?: T): boolean {
81
+ if (_eventID !== void 0) {
82
+ return this._hasObserver(_eventID);
83
+ }
84
+ for (const eventID in this._eventObservers) {
85
+ if (this._hasObserver(eventID)) {
86
+ return true;
87
+ }
88
+ }
89
+ return false;
90
+ }
91
+ }
package/src/platform.ts CHANGED
@@ -1,20 +1,20 @@
1
- declare const process: any;
2
-
3
- export const root: any = typeof globalThis !== "undefined" ? globalThis : window;
4
- export const isBrowser: boolean = typeof window !== "undefined" && root === window;
5
- export const isNode: boolean = typeof process !== "undefined" && process.versions != null && process.versions.node != null;
6
- export const isCI: boolean = isNode && process.env != null && (process.env.TRAVIS != null || process.env.GITHUB_ACTIONS != null);
7
-
8
- export function getScriptSrc(partial: string) {
9
- const scripts = document.scripts || [];
10
- for (let i = document.scripts.length - 1; i >= 0; --i) {
11
- const script = scripts[i];
12
- if (script.src) {
13
- const idx = script.src.indexOf(partial);
14
- if (idx >= 0) {
15
- return script.src.substring(0, idx);
16
- }
17
- }
18
- }
19
- return "";
20
- }
1
+ declare const process: any;
2
+
3
+ export const root: any = typeof globalThis !== "undefined" ? globalThis : window;
4
+ export const isBrowser: boolean = typeof window !== "undefined" && root === window;
5
+ export const isNode: boolean = typeof process !== "undefined" && process.versions != null && process.versions.node != null;
6
+ export const isCI: boolean = isNode && process.env != null && (process.env.TRAVIS != null || process.env.GITHUB_ACTIONS != null);
7
+
8
+ export function getScriptSrc(partial: string) {
9
+ const scripts = document.scripts || [];
10
+ for (let i = document.scripts.length - 1; i >= 0; --i) {
11
+ const script = scripts[i];
12
+ if (script.src) {
13
+ const idx = script.src.indexOf(partial);
14
+ if (idx >= 0) {
15
+ return script.src.substring(0, idx);
16
+ }
17
+ }
18
+ }
19
+ return "";
20
+ }