@hpcc-js/util 3.5.1 → 3.5.4
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 +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.umd.cjs +1 -1
- package/dist/index.umd.cjs.map +1 -1
- package/package.json +5 -4
- package/src/__package__.ts +3 -3
- package/src/array.ts +97 -97
- package/src/cache.ts +65 -65
- package/src/debounce.ts +88 -88
- package/src/dictionary.ts +69 -69
- package/src/dispatch.ts +125 -125
- package/src/esp.ts +32 -32
- package/src/graph.ts +353 -353
- package/src/graph2.ts +675 -675
- package/src/hashSum.ts +55 -55
- package/src/immutable.ts +156 -156
- package/src/index.ts +21 -21
- package/src/logging.ts +212 -212
- package/src/math.ts +92 -92
- package/src/object.ts +122 -122
- 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/src/utf8ToBase64.ts +47 -47
package/src/dispatch.ts
CHANGED
|
@@ -1,125 +1,125 @@
|
|
|
1
|
-
import type { IObserverHandle } from "./observer.ts";
|
|
2
|
-
import { root } from "./platform.ts";
|
|
3
|
-
|
|
4
|
-
export type RequestAnimationFrame = (callback: FrameRequestCallback) => number | undefined;
|
|
5
|
-
export type CancelAnimationFrame = (handle: number) => void | undefined;
|
|
6
|
-
|
|
7
|
-
let requestAnimationFrame: RequestAnimationFrame;
|
|
8
|
-
// let cancelAnimationFrame: CancelAnimationFrame;
|
|
9
|
-
|
|
10
|
-
(function () {
|
|
11
|
-
if (root.requestAnimationFrame) {
|
|
12
|
-
requestAnimationFrame = root.requestAnimationFrame;
|
|
13
|
-
// cancelAnimationFrame = root.cancelAnimationFrame;
|
|
14
|
-
} else {
|
|
15
|
-
let lastTime = 0;
|
|
16
|
-
requestAnimationFrame = function (callback: FrameRequestCallback): any {
|
|
17
|
-
const currTime = new Date().getTime();
|
|
18
|
-
const timeToCall = Math.max(0, 16 - (currTime - lastTime));
|
|
19
|
-
const id = setTimeout(() => callback(currTime + timeToCall), timeToCall);
|
|
20
|
-
lastTime = currTime + timeToCall;
|
|
21
|
-
return id;
|
|
22
|
-
};
|
|
23
|
-
// cancelAnimationFrame = function (handle: number): void {
|
|
24
|
-
// clearTimeout(handle);
|
|
25
|
-
// };
|
|
26
|
-
}
|
|
27
|
-
})();
|
|
28
|
-
|
|
29
|
-
export class Message {
|
|
30
|
-
|
|
31
|
-
get canConflate(): boolean { return false; }
|
|
32
|
-
conflate(other: Message): boolean {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
void(): boolean {
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
type MessageConstructor<T extends Message> = new (...args: any[]) => T;
|
|
41
|
-
|
|
42
|
-
export type Callback<T extends Message> = (messages: T[]) => void;
|
|
43
|
-
export { IObserverHandle };
|
|
44
|
-
|
|
45
|
-
type ObserverAdapter<T extends Message = Message> = {
|
|
46
|
-
id: number;
|
|
47
|
-
type?: MessageConstructor<T>;
|
|
48
|
-
callback: Callback<T>;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
export class Dispatch<T extends Message = Message> {
|
|
52
|
-
|
|
53
|
-
private _observerID: number = 0;
|
|
54
|
-
private _observers: ObserverAdapter<T>[] = [];
|
|
55
|
-
private _messageBuffer: T[] = [];
|
|
56
|
-
private _rafHandle: number | undefined = undefined;
|
|
57
|
-
|
|
58
|
-
constructor() {
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
private observers(): ObserverAdapter<T>[] {
|
|
62
|
-
return this._observers;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
private messages(): T[] {
|
|
66
|
-
const retVal: T[] = [];
|
|
67
|
-
this._messageBuffer.forEach(msg => {
|
|
68
|
-
if (!retVal.some(msg2 => msg2.canConflate && msg2.conflate(msg))) {
|
|
69
|
-
retVal.push(msg);
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
return retVal;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
private dispatchAll() {
|
|
76
|
-
this._rafHandle = undefined;
|
|
77
|
-
this.dispatch(this.messages());
|
|
78
|
-
this.flush();
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
private dispatch(messages: T[]) {
|
|
82
|
-
if (messages.length === 0) return;
|
|
83
|
-
this.observers().forEach(o => {
|
|
84
|
-
const msgs = messages.filter(m => !m.void() && (o.type === undefined || m instanceof o.type));
|
|
85
|
-
if (msgs.length) {
|
|
86
|
-
o.callback(msgs);
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
hasObserver(): boolean {
|
|
92
|
-
return this._observers.length > 0;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
flush() {
|
|
96
|
-
this._messageBuffer = [];
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
send(msg: T) {
|
|
100
|
-
if (!this.hasObserver()) return;
|
|
101
|
-
this.dispatch([msg]);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
post(msg: T) {
|
|
105
|
-
if (!this.hasObserver()) return;
|
|
106
|
-
this._messageBuffer.push(msg);
|
|
107
|
-
if (this._rafHandle === undefined) {
|
|
108
|
-
this._rafHandle = requestAnimationFrame(() => this.dispatchAll());
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
attach(callback: Callback<T>, type?: MessageConstructor<T>): IObserverHandle {
|
|
113
|
-
const context = this;
|
|
114
|
-
const id = ++this._observerID;
|
|
115
|
-
this._observers.push({ id, type, callback });
|
|
116
|
-
return {
|
|
117
|
-
release() {
|
|
118
|
-
context._observers = context._observers.filter(o => o.id !== id);
|
|
119
|
-
},
|
|
120
|
-
unwatch() {
|
|
121
|
-
this.release();
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
}
|
|
1
|
+
import type { IObserverHandle } from "./observer.ts";
|
|
2
|
+
import { root } from "./platform.ts";
|
|
3
|
+
|
|
4
|
+
export type RequestAnimationFrame = (callback: FrameRequestCallback) => number | undefined;
|
|
5
|
+
export type CancelAnimationFrame = (handle: number) => void | undefined;
|
|
6
|
+
|
|
7
|
+
let requestAnimationFrame: RequestAnimationFrame;
|
|
8
|
+
// let cancelAnimationFrame: CancelAnimationFrame;
|
|
9
|
+
|
|
10
|
+
(function () {
|
|
11
|
+
if (root.requestAnimationFrame) {
|
|
12
|
+
requestAnimationFrame = root.requestAnimationFrame;
|
|
13
|
+
// cancelAnimationFrame = root.cancelAnimationFrame;
|
|
14
|
+
} else {
|
|
15
|
+
let lastTime = 0;
|
|
16
|
+
requestAnimationFrame = function (callback: FrameRequestCallback): any {
|
|
17
|
+
const currTime = new Date().getTime();
|
|
18
|
+
const timeToCall = Math.max(0, 16 - (currTime - lastTime));
|
|
19
|
+
const id = setTimeout(() => callback(currTime + timeToCall), timeToCall);
|
|
20
|
+
lastTime = currTime + timeToCall;
|
|
21
|
+
return id;
|
|
22
|
+
};
|
|
23
|
+
// cancelAnimationFrame = function (handle: number): void {
|
|
24
|
+
// clearTimeout(handle);
|
|
25
|
+
// };
|
|
26
|
+
}
|
|
27
|
+
})();
|
|
28
|
+
|
|
29
|
+
export class Message {
|
|
30
|
+
|
|
31
|
+
get canConflate(): boolean { return false; }
|
|
32
|
+
conflate(other: Message): boolean {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
void(): boolean {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
type MessageConstructor<T extends Message> = new (...args: any[]) => T;
|
|
41
|
+
|
|
42
|
+
export type Callback<T extends Message> = (messages: T[]) => void;
|
|
43
|
+
export { IObserverHandle };
|
|
44
|
+
|
|
45
|
+
type ObserverAdapter<T extends Message = Message> = {
|
|
46
|
+
id: number;
|
|
47
|
+
type?: MessageConstructor<T>;
|
|
48
|
+
callback: Callback<T>;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export class Dispatch<T extends Message = Message> {
|
|
52
|
+
|
|
53
|
+
private _observerID: number = 0;
|
|
54
|
+
private _observers: ObserverAdapter<T>[] = [];
|
|
55
|
+
private _messageBuffer: T[] = [];
|
|
56
|
+
private _rafHandle: number | undefined = undefined;
|
|
57
|
+
|
|
58
|
+
constructor() {
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
private observers(): ObserverAdapter<T>[] {
|
|
62
|
+
return this._observers;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private messages(): T[] {
|
|
66
|
+
const retVal: T[] = [];
|
|
67
|
+
this._messageBuffer.forEach(msg => {
|
|
68
|
+
if (!retVal.some(msg2 => msg2.canConflate && msg2.conflate(msg))) {
|
|
69
|
+
retVal.push(msg);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
return retVal;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
private dispatchAll() {
|
|
76
|
+
this._rafHandle = undefined;
|
|
77
|
+
this.dispatch(this.messages());
|
|
78
|
+
this.flush();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
private dispatch(messages: T[]) {
|
|
82
|
+
if (messages.length === 0) return;
|
|
83
|
+
this.observers().forEach(o => {
|
|
84
|
+
const msgs = messages.filter(m => !m.void() && (o.type === undefined || m instanceof o.type));
|
|
85
|
+
if (msgs.length) {
|
|
86
|
+
o.callback(msgs);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
hasObserver(): boolean {
|
|
92
|
+
return this._observers.length > 0;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
flush() {
|
|
96
|
+
this._messageBuffer = [];
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
send(msg: T) {
|
|
100
|
+
if (!this.hasObserver()) return;
|
|
101
|
+
this.dispatch([msg]);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
post(msg: T) {
|
|
105
|
+
if (!this.hasObserver()) return;
|
|
106
|
+
this._messageBuffer.push(msg);
|
|
107
|
+
if (this._rafHandle === undefined) {
|
|
108
|
+
this._rafHandle = requestAnimationFrame(() => this.dispatchAll());
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
attach(callback: Callback<T>, type?: MessageConstructor<T>): IObserverHandle {
|
|
113
|
+
const context = this;
|
|
114
|
+
const id = ++this._observerID;
|
|
115
|
+
this._observers.push({ id, type, callback });
|
|
116
|
+
return {
|
|
117
|
+
release() {
|
|
118
|
+
context._observers = context._observers.filter(o => o.id !== id);
|
|
119
|
+
},
|
|
120
|
+
unwatch() {
|
|
121
|
+
this.release();
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
}
|
package/src/esp.ts
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
export function espTime2Seconds(duration: string): number {
|
|
2
|
-
if (!duration) {
|
|
3
|
-
return 0;
|
|
4
|
-
} else {
|
|
5
|
-
if (!isNaN(Number(duration))) {
|
|
6
|
-
return Number(duration);
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
// GH: <n>ns or <m>ms or <s>s or [<d> days ][<h>:][<m>:]<s>[.<ms>]
|
|
10
|
-
const nsIndex = duration.indexOf("ns");
|
|
11
|
-
if (nsIndex !== -1) {
|
|
12
|
-
return parseFloat(duration.substr(0, nsIndex)) / 1000000000;
|
|
13
|
-
}
|
|
14
|
-
const msIndex = duration.indexOf("ms");
|
|
15
|
-
if (msIndex !== -1) {
|
|
16
|
-
return parseFloat(duration.substr(0, msIndex)) / 1000;
|
|
17
|
-
}
|
|
18
|
-
const sIndex = duration.indexOf("s");
|
|
19
|
-
if (sIndex !== -1 && duration.indexOf("days") === -1) {
|
|
20
|
-
return parseFloat(duration.substr(0, sIndex));
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const dayTimeParts = duration.split(" days ");
|
|
24
|
-
const days: number = dayTimeParts.length > 1 ? parseFloat(dayTimeParts[0]) : 0.0;
|
|
25
|
-
const time: string = dayTimeParts.length > 1 ? dayTimeParts[1] : dayTimeParts[0];
|
|
26
|
-
let secs = 0.0;
|
|
27
|
-
const timeParts = time.split(":").reverse();
|
|
28
|
-
for (let j = 0; j < timeParts.length; ++j) {
|
|
29
|
-
secs += parseFloat(timeParts[j]) * Math.pow(60, j);
|
|
30
|
-
}
|
|
31
|
-
return (days * 24 * 60 * 60) + secs;
|
|
32
|
-
}
|
|
1
|
+
export function espTime2Seconds(duration: string): number {
|
|
2
|
+
if (!duration) {
|
|
3
|
+
return 0;
|
|
4
|
+
} else {
|
|
5
|
+
if (!isNaN(Number(duration))) {
|
|
6
|
+
return Number(duration);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
// GH: <n>ns or <m>ms or <s>s or [<d> days ][<h>:][<m>:]<s>[.<ms>]
|
|
10
|
+
const nsIndex = duration.indexOf("ns");
|
|
11
|
+
if (nsIndex !== -1) {
|
|
12
|
+
return parseFloat(duration.substr(0, nsIndex)) / 1000000000;
|
|
13
|
+
}
|
|
14
|
+
const msIndex = duration.indexOf("ms");
|
|
15
|
+
if (msIndex !== -1) {
|
|
16
|
+
return parseFloat(duration.substr(0, msIndex)) / 1000;
|
|
17
|
+
}
|
|
18
|
+
const sIndex = duration.indexOf("s");
|
|
19
|
+
if (sIndex !== -1 && duration.indexOf("days") === -1) {
|
|
20
|
+
return parseFloat(duration.substr(0, sIndex));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const dayTimeParts = duration.split(" days ");
|
|
24
|
+
const days: number = dayTimeParts.length > 1 ? parseFloat(dayTimeParts[0]) : 0.0;
|
|
25
|
+
const time: string = dayTimeParts.length > 1 ? dayTimeParts[1] : dayTimeParts[0];
|
|
26
|
+
let secs = 0.0;
|
|
27
|
+
const timeParts = time.split(":").reverse();
|
|
28
|
+
for (let j = 0; j < timeParts.length; ++j) {
|
|
29
|
+
secs += parseFloat(timeParts[j]) * Math.pow(60, j);
|
|
30
|
+
}
|
|
31
|
+
return (days * 24 * 60 * 60) + secs;
|
|
32
|
+
}
|