semantic-typescript 0.3.3 → 0.3.8
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/dist/collectable.d.ts +19 -24
- package/dist/collectable.js +373 -175
- package/dist/collector.d.ts +101 -24
- package/dist/collector.js +402 -146
- package/dist/factory.d.ts +38 -8
- package/dist/factory.js +300 -163
- package/dist/guard.d.ts +8 -3
- package/dist/guard.js +29 -5
- package/dist/hook.d.ts +13 -0
- package/dist/hook.js +114 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/optional.js +36 -3
- package/dist/semantic.d.ts +17 -10
- package/dist/semantic.js +355 -195
- package/dist/statistics.d.ts +13 -17
- package/dist/statistics.js +234 -522
- package/dist/utility.d.ts +4 -0
- package/dist/utility.js +2 -1
- package/dist/window.d.ts +12 -0
- package/dist/window.js +70 -0
- package/package.json +1 -1
- package/readme.cn.md +732 -210
- package/readme.md +426 -150
package/dist/factory.d.ts
CHANGED
|
@@ -1,19 +1,49 @@
|
|
|
1
1
|
import { Semantic } from "./semantic";
|
|
2
|
-
import type {
|
|
3
|
-
|
|
2
|
+
import type { BiPredicate, Functional, Predicate, Supplier, Generator } from "./utility";
|
|
3
|
+
interface AnimationFrameFunction {
|
|
4
|
+
(period: number): Semantic<number>;
|
|
5
|
+
(period: number, delay: number): Semantic<number>;
|
|
6
|
+
}
|
|
7
|
+
export declare let animationFrame: AnimationFrameFunction;
|
|
4
8
|
interface Attribute<T> {
|
|
5
9
|
key: keyof T;
|
|
6
10
|
value: T[keyof T];
|
|
7
11
|
}
|
|
8
12
|
export declare let attribute: <T extends object>(target: T) => Semantic<Attribute<T>>;
|
|
9
|
-
|
|
13
|
+
interface BlobFunction {
|
|
14
|
+
(blob: Blob): Semantic<Uint8Array>;
|
|
15
|
+
(blob: Blob, chunk: bigint): Semantic<Uint8Array>;
|
|
16
|
+
}
|
|
17
|
+
export declare let blob: BlobFunction;
|
|
10
18
|
export declare let empty: <E>() => Semantic<E>;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
19
|
+
interface FillFunction {
|
|
20
|
+
<E>(element: E, count: bigint): Semantic<E>;
|
|
21
|
+
<E>(supplier: Supplier<E>, count: bigint): Semantic<E>;
|
|
22
|
+
}
|
|
23
|
+
export declare let fill: FillFunction;
|
|
24
|
+
export interface FromFunction {
|
|
25
|
+
<E>(iterable: Iterable<E>): Semantic<E>;
|
|
26
|
+
<E>(iterable: AsyncIterable<E>): Semantic<E>;
|
|
27
|
+
}
|
|
28
|
+
export declare let from: FromFunction;
|
|
29
|
+
interface GenerateFunction {
|
|
30
|
+
<E>(supplier: Supplier<E>, count: bigint): Semantic<E>;
|
|
31
|
+
<E>(element: E, count: bigint): Semantic<E>;
|
|
32
|
+
<E>(supplier: Supplier<E>, interrupt: Predicate<E>): Semantic<E>;
|
|
33
|
+
<E>(supplier: Supplier<E>, interrupt: BiPredicate<E, bigint>): Semantic<E>;
|
|
34
|
+
}
|
|
35
|
+
export declare let generate: GenerateFunction;
|
|
36
|
+
interface IntervalFunction {
|
|
37
|
+
(period: number): Semantic<number>;
|
|
38
|
+
(period: number, delay: number): Semantic<number>;
|
|
39
|
+
}
|
|
40
|
+
export declare let interval: IntervalFunction;
|
|
15
41
|
export declare let iterate: <E>(generator: Generator<E>) => Semantic<E>;
|
|
16
42
|
export declare let promise: (<T>(promise: Promise<T>) => Semantic<T>);
|
|
17
|
-
|
|
43
|
+
interface RangeFunction {
|
|
44
|
+
(start: number, end: number): Semantic<number>;
|
|
45
|
+
(start: number, end: number, step: number): Semantic<number>;
|
|
46
|
+
}
|
|
47
|
+
export declare let range: RangeFunction;
|
|
18
48
|
export declare let websocket: Functional<WebSocket, Semantic<MessageEvent | CloseEvent | Event>>;
|
|
19
49
|
export {};
|
package/dist/factory.js
CHANGED
|
@@ -1,51 +1,63 @@
|
|
|
1
|
-
import { isBigInt, isFunction, isIterable, isNumber, isObject, isPromise } from "./guard";
|
|
1
|
+
import { isBigInt, isFunction, isIterable, isNumber, isObject, isPromise, isAsyncIterable } from "./guard";
|
|
2
2
|
import { useCompare, useTraverse } from "./hook";
|
|
3
3
|
import { Semantic } from "./semantic";
|
|
4
4
|
import { invalidate, validate } from "./utility";
|
|
5
|
+
;
|
|
5
6
|
export let animationFrame = (period, delay = 0) => {
|
|
6
7
|
if (period <= 0 || !Number.isFinite(period) || delay < 0 || !Number.isFinite(delay)) {
|
|
7
8
|
throw new TypeError("Period must be positive finite number and delay must be non-negative finite number.");
|
|
8
9
|
}
|
|
9
10
|
return new Semantic((accept, interrupt) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
else if (performance.now() - start < period) {
|
|
17
|
-
requestAnimationFrame(animate);
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
if (interrupt(start, index)) {
|
|
21
|
-
return;
|
|
11
|
+
try {
|
|
12
|
+
let start = performance.now();
|
|
13
|
+
let index = 0n;
|
|
14
|
+
let animate = () => {
|
|
15
|
+
if (performance.now() - start >= delay) {
|
|
16
|
+
requestAnimationFrame(animate);
|
|
22
17
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
18
|
+
else if (performance.now() - start < period) {
|
|
19
|
+
requestAnimationFrame(animate);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
if (interrupt(start, index)) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
accept(performance.now(), index);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
throw new Error("Uncaught error as creating animation frame semantic.");
|
|
31
|
+
}
|
|
26
32
|
});
|
|
27
33
|
};
|
|
28
34
|
;
|
|
29
35
|
export let attribute = (target) => {
|
|
30
36
|
if (isObject(target)) {
|
|
31
37
|
return new Semantic((accept, interrupt) => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
38
|
+
try {
|
|
39
|
+
let index = 0n;
|
|
40
|
+
useTraverse(target, (key, value) => {
|
|
41
|
+
let attribute = {
|
|
42
|
+
key: key,
|
|
43
|
+
value: value
|
|
44
|
+
};
|
|
45
|
+
if (interrupt(attribute, index)) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
accept(attribute, index);
|
|
49
|
+
index++;
|
|
50
|
+
return true;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
throw new Error("Uncaught error as creating attribute semantic.");
|
|
55
|
+
}
|
|
45
56
|
});
|
|
46
57
|
}
|
|
47
58
|
throw new TypeError("Target must be an object.");
|
|
48
59
|
};
|
|
60
|
+
;
|
|
49
61
|
export let blob = (blob, chunk = 64n * 1024n) => {
|
|
50
62
|
let size = Number(chunk);
|
|
51
63
|
if (size <= 0 || !Number.isSafeInteger(size)) {
|
|
@@ -55,115 +67,228 @@ export let blob = (blob, chunk = 64n * 1024n) => {
|
|
|
55
67
|
throw new TypeError("Blob is invalid.");
|
|
56
68
|
}
|
|
57
69
|
return new Semantic((accept, interrupt) => {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
if (
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
70
|
+
try {
|
|
71
|
+
let index = 0n;
|
|
72
|
+
let stoppable = false;
|
|
73
|
+
let stream = blob.stream();
|
|
74
|
+
let reader = stream.getReader();
|
|
75
|
+
let buffer = new Uint8Array(size);
|
|
76
|
+
let offset = 0;
|
|
77
|
+
(async () => {
|
|
78
|
+
try {
|
|
79
|
+
while (!stoppable) {
|
|
80
|
+
let { done, value } = await reader.read();
|
|
81
|
+
if (done) {
|
|
82
|
+
if (offset > 0) {
|
|
83
|
+
let element = buffer.subarray(0, offset);
|
|
84
|
+
if (interrupt(element, index)) {
|
|
85
|
+
stoppable = true;
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
accept(element, index);
|
|
89
|
+
index++;
|
|
90
|
+
}
|
|
77
91
|
}
|
|
92
|
+
break;
|
|
78
93
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
94
|
+
let chunkData = value;
|
|
95
|
+
let position = 0;
|
|
96
|
+
while (position < chunkData.length && !stoppable) {
|
|
97
|
+
let space = size - offset;
|
|
98
|
+
let toCopy = Math.min(space, chunkData.length - position);
|
|
99
|
+
buffer.set(chunkData.subarray(position, position + toCopy), offset);
|
|
100
|
+
offset += toCopy;
|
|
101
|
+
position += toCopy;
|
|
102
|
+
if (offset === size) {
|
|
103
|
+
if (interrupt(buffer, index)) {
|
|
104
|
+
stoppable = true;
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
accept(buffer, index);
|
|
108
|
+
index++;
|
|
109
|
+
}
|
|
110
|
+
offset = 0;
|
|
92
111
|
}
|
|
93
|
-
else {
|
|
94
|
-
accept(buffer, index);
|
|
95
|
-
index++;
|
|
96
|
-
}
|
|
97
|
-
offset = 0;
|
|
98
112
|
}
|
|
99
113
|
}
|
|
100
114
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
console.error(error);
|
|
104
|
-
}
|
|
105
|
-
finally {
|
|
106
|
-
if (stoppable) {
|
|
107
|
-
await reader.cancel();
|
|
115
|
+
catch (error) {
|
|
116
|
+
console.error(error);
|
|
108
117
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
118
|
+
finally {
|
|
119
|
+
if (stoppable) {
|
|
120
|
+
await reader.cancel();
|
|
121
|
+
}
|
|
122
|
+
reader.releaseLock();
|
|
123
|
+
}
|
|
124
|
+
})();
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
throw new Error("Uncaught error as creating blob semantic.");
|
|
128
|
+
}
|
|
112
129
|
});
|
|
113
130
|
};
|
|
114
131
|
export let empty = () => {
|
|
115
132
|
return new Semantic(() => { });
|
|
116
133
|
};
|
|
134
|
+
;
|
|
117
135
|
export let fill = (element, count) => {
|
|
118
136
|
if (validate(element) && count > 0n) {
|
|
119
137
|
return new Semantic((accept, interrupt) => {
|
|
120
|
-
|
|
121
|
-
let
|
|
122
|
-
|
|
123
|
-
|
|
138
|
+
try {
|
|
139
|
+
for (let i = 0n; i < count; i++) {
|
|
140
|
+
let item = isFunction(element) ? element() : element;
|
|
141
|
+
if (interrupt(item, i)) {
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
accept(item, i);
|
|
124
145
|
}
|
|
125
|
-
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
throw new Error("Uncaught error as creating fill semantic.");
|
|
126
149
|
}
|
|
127
150
|
});
|
|
128
151
|
}
|
|
129
152
|
throw new TypeError("Invalid arguments.");
|
|
130
153
|
};
|
|
154
|
+
;
|
|
131
155
|
export let from = (iterable) => {
|
|
132
156
|
if (isIterable(iterable)) {
|
|
133
157
|
return new Semantic((accept, interrupt) => {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
158
|
+
try {
|
|
159
|
+
let index = 0n;
|
|
160
|
+
for (let element of iterable) {
|
|
161
|
+
if (interrupt(element, index)) {
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
accept(element, index);
|
|
165
|
+
index++;
|
|
138
166
|
}
|
|
139
|
-
|
|
140
|
-
|
|
167
|
+
}
|
|
168
|
+
catch (error) {
|
|
169
|
+
throw new Error("Uncaught error as creating from semantic.");
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
else if (isAsyncIterable(iterable)) {
|
|
174
|
+
return new Semantic(async (accept, interrupt) => {
|
|
175
|
+
try {
|
|
176
|
+
let index = 0n;
|
|
177
|
+
for await (let element of iterable) {
|
|
178
|
+
if (interrupt(element, index)) {
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
181
|
+
accept(element, index);
|
|
182
|
+
index++;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
catch (error) {
|
|
186
|
+
throw new Error("Uncaught error as creating from semantic.");
|
|
141
187
|
}
|
|
142
188
|
});
|
|
143
189
|
}
|
|
144
190
|
throw new TypeError("Invalid arguments");
|
|
145
191
|
};
|
|
146
|
-
|
|
147
|
-
|
|
192
|
+
;
|
|
193
|
+
export let generate = (argument1, argument2) => {
|
|
194
|
+
if (isFunction(argument1)) {
|
|
195
|
+
if (isFunction(argument2)) {
|
|
196
|
+
let shutdown = argument2;
|
|
197
|
+
return new Semantic((accept, interrupt) => {
|
|
198
|
+
try {
|
|
199
|
+
let index = 0n;
|
|
200
|
+
while (true) {
|
|
201
|
+
if (interrupt(argument1(), index) || shutdown(argument1(), index)) {
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
accept(argument1(), index);
|
|
205
|
+
index++;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
catch (error) {
|
|
209
|
+
throw new Error("Uncaught error as creating generate semantic.");
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
if (isBigInt(argument2)) {
|
|
214
|
+
let limit = argument2;
|
|
215
|
+
return new Semantic((accept, interrupt) => {
|
|
216
|
+
try {
|
|
217
|
+
let index = 0n;
|
|
218
|
+
while (index < limit) {
|
|
219
|
+
if (interrupt(argument1(), index)) {
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
accept(argument1(), index);
|
|
223
|
+
index++;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
catch (error) {
|
|
227
|
+
throw new Error("Uncaught error as creating generate semantic.");
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
throw new TypeError("Invalid arguments.");
|
|
232
|
+
}
|
|
233
|
+
let element = argument1;
|
|
234
|
+
if (isFunction(argument2)) {
|
|
235
|
+
let shutdown = argument2;
|
|
148
236
|
return new Semantic((accept, interrupt) => {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
237
|
+
try {
|
|
238
|
+
let index = 0n;
|
|
239
|
+
while (true) {
|
|
240
|
+
if (interrupt(element, index) || shutdown(element, index)) {
|
|
241
|
+
break;
|
|
242
|
+
}
|
|
243
|
+
accept(element, index);
|
|
244
|
+
index++;
|
|
154
245
|
}
|
|
155
|
-
|
|
156
|
-
|
|
246
|
+
}
|
|
247
|
+
catch (error) {
|
|
248
|
+
throw new Error("Uncaught error as creating generate semantic.");
|
|
157
249
|
}
|
|
158
250
|
});
|
|
159
251
|
}
|
|
160
|
-
|
|
252
|
+
if (isBigInt(argument2)) {
|
|
253
|
+
let limit = argument2;
|
|
254
|
+
return new Semantic((accept, interrupt) => {
|
|
255
|
+
try {
|
|
256
|
+
let index = 0n;
|
|
257
|
+
while (index < limit) {
|
|
258
|
+
if (interrupt(element, index)) {
|
|
259
|
+
break;
|
|
260
|
+
}
|
|
261
|
+
accept(element, index);
|
|
262
|
+
index++;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
catch (error) {
|
|
266
|
+
throw new Error("Uncaught error as creating generate semantic.");
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
throw new TypeError("Invalid arguments.");
|
|
161
271
|
};
|
|
272
|
+
;
|
|
162
273
|
export let interval = (period, delay = 0) => {
|
|
163
274
|
if (period > 0 && delay >= 0) {
|
|
164
275
|
return new Semantic((accept, interrupt) => {
|
|
165
|
-
|
|
166
|
-
|
|
276
|
+
try {
|
|
277
|
+
if (delay > 0) {
|
|
278
|
+
setTimeout(() => {
|
|
279
|
+
let count = 0;
|
|
280
|
+
let index = 0n;
|
|
281
|
+
let timer = setInterval(() => {
|
|
282
|
+
if (interrupt(count, index)) {
|
|
283
|
+
clearInterval(timer);
|
|
284
|
+
}
|
|
285
|
+
accept(count, BigInt(index));
|
|
286
|
+
index++;
|
|
287
|
+
count += period;
|
|
288
|
+
}, period);
|
|
289
|
+
}, delay);
|
|
290
|
+
}
|
|
291
|
+
else {
|
|
167
292
|
let count = 0;
|
|
168
293
|
let index = 0n;
|
|
169
294
|
let timer = setInterval(() => {
|
|
@@ -174,19 +299,10 @@ export let interval = (period, delay = 0) => {
|
|
|
174
299
|
index++;
|
|
175
300
|
count += period;
|
|
176
301
|
}, period);
|
|
177
|
-
}
|
|
302
|
+
}
|
|
178
303
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
let index = 0n;
|
|
182
|
-
let timer = setInterval(() => {
|
|
183
|
-
if (interrupt(count, index)) {
|
|
184
|
-
clearInterval(timer);
|
|
185
|
-
}
|
|
186
|
-
accept(count, BigInt(index));
|
|
187
|
-
index++;
|
|
188
|
-
count += period;
|
|
189
|
-
}, period);
|
|
304
|
+
catch (error) {
|
|
305
|
+
throw new Error("Uncaught error as creating interval semantic.");
|
|
190
306
|
}
|
|
191
307
|
});
|
|
192
308
|
}
|
|
@@ -194,27 +310,38 @@ export let interval = (period, delay = 0) => {
|
|
|
194
310
|
};
|
|
195
311
|
export let iterate = (generator) => {
|
|
196
312
|
if (isFunction(generator)) {
|
|
197
|
-
|
|
313
|
+
try {
|
|
314
|
+
return new Semantic(generator);
|
|
315
|
+
}
|
|
316
|
+
catch (error) {
|
|
317
|
+
throw new Error("Uncaught error as creating iterate semantic.");
|
|
318
|
+
}
|
|
198
319
|
}
|
|
199
320
|
throw new TypeError("Invalid arguments.");
|
|
200
321
|
};
|
|
201
322
|
export let promise = (promise) => {
|
|
202
323
|
if (isPromise(promise)) {
|
|
203
324
|
return new Semantic((accept, interrupt) => {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
325
|
+
try {
|
|
326
|
+
promise.then((value) => {
|
|
327
|
+
if (interrupt(value, 0n)) {
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
accept(value, 0n);
|
|
331
|
+
}).catch((error) => {
|
|
332
|
+
console.error(error);
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
catch (error) {
|
|
336
|
+
throw new Error("Uncaught error as creating promise semantic.");
|
|
337
|
+
}
|
|
212
338
|
});
|
|
213
339
|
}
|
|
214
340
|
else {
|
|
215
341
|
throw new TypeError("Invalid arguments.");
|
|
216
342
|
}
|
|
217
343
|
};
|
|
344
|
+
;
|
|
218
345
|
export let range = (start, end, step = 1) => {
|
|
219
346
|
if ((!isNumber(step) && !isBigInt(step)) || (isNumber(step) && useCompare(step, 0) === 0) || (isBigInt(step) && useCompare(step, 0n) === 0)) {
|
|
220
347
|
throw new TypeError("Step must be numeric and cannot be zero.");
|
|
@@ -223,12 +350,17 @@ export let range = (start, end, step = 1) => {
|
|
|
223
350
|
let minimum = start, maximum = end, limit = Number(step);
|
|
224
351
|
let condition = limit > 0 ? (i) => i < maximum : (i) => i > maximum;
|
|
225
352
|
return new Semantic((accept, interrupt) => {
|
|
226
|
-
|
|
227
|
-
let
|
|
228
|
-
|
|
229
|
-
|
|
353
|
+
try {
|
|
354
|
+
for (let i = minimum; condition(i); i += limit) {
|
|
355
|
+
let value = i;
|
|
356
|
+
if (interrupt(value, BigInt(i))) {
|
|
357
|
+
break;
|
|
358
|
+
}
|
|
359
|
+
accept(value, BigInt(i));
|
|
230
360
|
}
|
|
231
|
-
|
|
361
|
+
}
|
|
362
|
+
catch (error) {
|
|
363
|
+
throw new Error("Uncaught error as creating range semantic.");
|
|
232
364
|
}
|
|
233
365
|
});
|
|
234
366
|
}
|
|
@@ -239,43 +371,48 @@ export let websocket = (websocket) => {
|
|
|
239
371
|
throw new TypeError("WebSocket is invalid.");
|
|
240
372
|
}
|
|
241
373
|
return new Semantic((accept, interrupt) => {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
stop
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
stop
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
stop
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
stop
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
374
|
+
try {
|
|
375
|
+
let index = 0n;
|
|
376
|
+
let stop = false;
|
|
377
|
+
websocket.addEventListener("open", (event) => {
|
|
378
|
+
if (stop || interrupt(event, index)) {
|
|
379
|
+
stop = true;
|
|
380
|
+
}
|
|
381
|
+
else {
|
|
382
|
+
accept(event, index);
|
|
383
|
+
index++;
|
|
384
|
+
}
|
|
385
|
+
});
|
|
386
|
+
websocket.addEventListener("message", (event) => {
|
|
387
|
+
if (stop || interrupt(event, index)) {
|
|
388
|
+
stop = true;
|
|
389
|
+
}
|
|
390
|
+
else {
|
|
391
|
+
accept(event, index);
|
|
392
|
+
index++;
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
websocket.addEventListener("error", (event) => {
|
|
396
|
+
if (stop || interrupt(event, index)) {
|
|
397
|
+
stop = true;
|
|
398
|
+
}
|
|
399
|
+
else {
|
|
400
|
+
accept(event, index);
|
|
401
|
+
index++;
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
websocket.addEventListener("close", (event) => {
|
|
405
|
+
if (stop || interrupt(event, index)) {
|
|
406
|
+
stop = true;
|
|
407
|
+
}
|
|
408
|
+
else {
|
|
409
|
+
accept(event, index);
|
|
410
|
+
index++;
|
|
411
|
+
}
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
catch (error) {
|
|
415
|
+
throw new Error("Uncaught error as creating websocket semantic.");
|
|
416
|
+
}
|
|
280
417
|
});
|
|
281
418
|
};
|
package/dist/guard.d.ts
CHANGED
|
@@ -2,7 +2,8 @@ import type { Collectable, OrderedCollectable, UnorderedCollectable } from "./co
|
|
|
2
2
|
import type { Collector } from "./collector";
|
|
3
3
|
import type { Semantic } from "./semantic";
|
|
4
4
|
import type { Statistics } from "./statistics";
|
|
5
|
-
import type { AsyncFunction, MaybePrimitive, Primitive } from "./utility";
|
|
5
|
+
import type { AsyncFunction, Generator, MaybePrimitive, Primitive } from "./utility";
|
|
6
|
+
import type { WindowCollectable } from "./window";
|
|
6
7
|
export declare let isBoolean: (t: unknown) => t is boolean;
|
|
7
8
|
export declare let isString: (t: unknown) => t is string;
|
|
8
9
|
export declare let isNumber: (t: unknown) => t is number;
|
|
@@ -11,15 +12,19 @@ export declare let isObject: (t: unknown) => t is object;
|
|
|
11
12
|
export declare let isSymbol: (t: unknown) => t is symbol;
|
|
12
13
|
export declare let isBigInt: (t: unknown) => t is bigint;
|
|
13
14
|
export declare let isPrimitive: (t: MaybePrimitive<unknown>) => t is Primitive;
|
|
15
|
+
export declare let isAsyncIterable: (t: unknown) => t is Iterable<unknown>;
|
|
14
16
|
export declare let isIterable: (t: unknown) => t is Iterable<unknown>;
|
|
15
17
|
export declare let isSemantic: (t: unknown) => t is Semantic<unknown>;
|
|
16
18
|
export declare let isCollector: (t: unknown) => t is Collector<unknown, unknown, unknown>;
|
|
17
19
|
export declare let isCollectable: (t: unknown) => t is Collectable<unknown>;
|
|
18
20
|
export declare let isOrderedCollectable: (t: unknown) => t is OrderedCollectable<unknown>;
|
|
19
|
-
export declare let isWindowCollectable: (t: unknown) => t is
|
|
21
|
+
export declare let isWindowCollectable: (t: unknown) => t is WindowCollectable<unknown>;
|
|
20
22
|
export declare let isUnorderedCollectable: (t: unknown) => t is UnorderedCollectable<unknown>;
|
|
21
23
|
export declare let isStatistics: (t: unknown) => t is Statistics<unknown, number | bigint>;
|
|
22
24
|
export declare let isNumericStatistics: (t: unknown) => t is Statistics<unknown, number | bigint>;
|
|
23
25
|
export declare let isBigIntStatistics: (t: unknown) => t is Statistics<unknown, number | bigint>;
|
|
24
26
|
export declare let isPromise: (t: unknown) => t is Promise<unknown>;
|
|
25
|
-
export declare let
|
|
27
|
+
export declare let isGenerator: (t: unknown) => t is Generator<unknown>;
|
|
28
|
+
export declare let isAsyncFunction: (t: unknown) => t is AsyncFunction;
|
|
29
|
+
export declare let isGeneratorFunction: (t: unknown) => t is globalThis.Generator<unknown, unknown, unknown>;
|
|
30
|
+
export declare let isAsyncGeneratorFunction: (t: unknown) => t is globalThis.AsyncGenerator<unknown, unknown, unknown>;
|