semantic-typescript 0.3.3 → 0.3.7
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 +329 -177
- package/dist/collector.d.ts +93 -16
- package/dist/collector.js +297 -107
- package/dist/factory.js +214 -159
- package/dist/guard.d.ts +3 -1
- package/dist/guard.js +14 -2
- package/dist/hook.d.ts +12 -0
- package/dist/hook.js +70 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/semantic.d.ts +2 -6
- package/dist/semantic.js +335 -185
- package/dist/statistics.d.ts +13 -17
- package/dist/statistics.js +204 -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 +60 -0
- package/package.json +1 -1
- package/readme.md +198 -21
package/dist/factory.js
CHANGED
|
@@ -7,41 +7,51 @@ export let animationFrame = (period, delay = 0) => {
|
|
|
7
7
|
throw new TypeError("Period must be positive finite number and delay must be non-negative finite number.");
|
|
8
8
|
}
|
|
9
9
|
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;
|
|
10
|
+
try {
|
|
11
|
+
let start = performance.now();
|
|
12
|
+
let index = 0n;
|
|
13
|
+
let animate = () => {
|
|
14
|
+
if (performance.now() - start >= delay) {
|
|
15
|
+
requestAnimationFrame(animate);
|
|
22
16
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
17
|
+
else if (performance.now() - start < period) {
|
|
18
|
+
requestAnimationFrame(animate);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
if (interrupt(start, index)) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
accept(performance.now(), index);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
throw new Error("Uncaught error as creating animation frame semantic.");
|
|
30
|
+
}
|
|
26
31
|
});
|
|
27
32
|
};
|
|
28
33
|
;
|
|
29
34
|
export let attribute = (target) => {
|
|
30
35
|
if (isObject(target)) {
|
|
31
36
|
return new Semantic((accept, interrupt) => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
37
|
+
try {
|
|
38
|
+
let index = 0n;
|
|
39
|
+
useTraverse(target, (key, value) => {
|
|
40
|
+
let attribute = {
|
|
41
|
+
key: key,
|
|
42
|
+
value: value
|
|
43
|
+
};
|
|
44
|
+
if (interrupt(attribute, index)) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
accept(attribute, index);
|
|
48
|
+
index++;
|
|
49
|
+
return true;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
throw new Error("Uncaught error as creating attribute semantic.");
|
|
54
|
+
}
|
|
45
55
|
});
|
|
46
56
|
}
|
|
47
57
|
throw new TypeError("Target must be an object.");
|
|
@@ -55,60 +65,65 @@ export let blob = (blob, chunk = 64n * 1024n) => {
|
|
|
55
65
|
throw new TypeError("Blob is invalid.");
|
|
56
66
|
}
|
|
57
67
|
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
|
-
|
|
68
|
+
try {
|
|
69
|
+
let index = 0n;
|
|
70
|
+
let stoppable = false;
|
|
71
|
+
let stream = blob.stream();
|
|
72
|
+
let reader = stream.getReader();
|
|
73
|
+
let buffer = new Uint8Array(size);
|
|
74
|
+
let offset = 0;
|
|
75
|
+
(async () => {
|
|
76
|
+
try {
|
|
77
|
+
while (!stoppable) {
|
|
78
|
+
let { done, value } = await reader.read();
|
|
79
|
+
if (done) {
|
|
80
|
+
if (offset > 0) {
|
|
81
|
+
let element = buffer.subarray(0, offset);
|
|
82
|
+
if (interrupt(element, index)) {
|
|
83
|
+
stoppable = true;
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
accept(element, index);
|
|
87
|
+
index++;
|
|
88
|
+
}
|
|
77
89
|
}
|
|
90
|
+
break;
|
|
78
91
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
+
let chunkData = value;
|
|
93
|
+
let position = 0;
|
|
94
|
+
while (position < chunkData.length && !stoppable) {
|
|
95
|
+
let space = size - offset;
|
|
96
|
+
let toCopy = Math.min(space, chunkData.length - position);
|
|
97
|
+
buffer.set(chunkData.subarray(position, position + toCopy), offset);
|
|
98
|
+
offset += toCopy;
|
|
99
|
+
position += toCopy;
|
|
100
|
+
if (offset === size) {
|
|
101
|
+
if (interrupt(buffer, index)) {
|
|
102
|
+
stoppable = true;
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
accept(buffer, index);
|
|
106
|
+
index++;
|
|
107
|
+
}
|
|
108
|
+
offset = 0;
|
|
92
109
|
}
|
|
93
|
-
else {
|
|
94
|
-
accept(buffer, index);
|
|
95
|
-
index++;
|
|
96
|
-
}
|
|
97
|
-
offset = 0;
|
|
98
110
|
}
|
|
99
111
|
}
|
|
100
112
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
console.error(error);
|
|
104
|
-
}
|
|
105
|
-
finally {
|
|
106
|
-
if (stoppable) {
|
|
107
|
-
await reader.cancel();
|
|
113
|
+
catch (error) {
|
|
114
|
+
console.error(error);
|
|
108
115
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
116
|
+
finally {
|
|
117
|
+
if (stoppable) {
|
|
118
|
+
await reader.cancel();
|
|
119
|
+
}
|
|
120
|
+
reader.releaseLock();
|
|
121
|
+
}
|
|
122
|
+
})();
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
throw new Error("Uncaught error as creating blob semantic.");
|
|
126
|
+
}
|
|
112
127
|
});
|
|
113
128
|
};
|
|
114
129
|
export let empty = () => {
|
|
@@ -117,12 +132,17 @@ export let empty = () => {
|
|
|
117
132
|
export let fill = (element, count) => {
|
|
118
133
|
if (validate(element) && count > 0n) {
|
|
119
134
|
return new Semantic((accept, interrupt) => {
|
|
120
|
-
|
|
121
|
-
let
|
|
122
|
-
|
|
123
|
-
|
|
135
|
+
try {
|
|
136
|
+
for (let i = 0n; i < count; i++) {
|
|
137
|
+
let item = isFunction(element) ? element() : element;
|
|
138
|
+
if (interrupt(item, i)) {
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
accept(item, i);
|
|
124
142
|
}
|
|
125
|
-
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
throw new Error("Uncaught error as creating fill semantic.");
|
|
126
146
|
}
|
|
127
147
|
});
|
|
128
148
|
}
|
|
@@ -131,13 +151,18 @@ export let fill = (element, count) => {
|
|
|
131
151
|
export let from = (iterable) => {
|
|
132
152
|
if (isIterable(iterable)) {
|
|
133
153
|
return new Semantic((accept, interrupt) => {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
154
|
+
try {
|
|
155
|
+
let index = 0n;
|
|
156
|
+
for (let element of iterable) {
|
|
157
|
+
if (interrupt(element, index)) {
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
accept(element, index);
|
|
161
|
+
index++;
|
|
138
162
|
}
|
|
139
|
-
|
|
140
|
-
|
|
163
|
+
}
|
|
164
|
+
catch (error) {
|
|
165
|
+
throw new Error("Uncaught error as creating from semantic.");
|
|
141
166
|
}
|
|
142
167
|
});
|
|
143
168
|
}
|
|
@@ -146,14 +171,19 @@ export let from = (iterable) => {
|
|
|
146
171
|
export let generate = (supplier, interrupt) => {
|
|
147
172
|
if (isFunction(supplier) && isFunction(interrupt)) {
|
|
148
173
|
return new Semantic((accept, interrupt) => {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
174
|
+
try {
|
|
175
|
+
let index = 0n;
|
|
176
|
+
while (true) {
|
|
177
|
+
let element = supplier();
|
|
178
|
+
if (interrupt(element, index)) {
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
181
|
+
accept(element, index);
|
|
182
|
+
index++;
|
|
154
183
|
}
|
|
155
|
-
|
|
156
|
-
|
|
184
|
+
}
|
|
185
|
+
catch (error) {
|
|
186
|
+
throw new Error("Uncaught error as creating generate semantic.");
|
|
157
187
|
}
|
|
158
188
|
});
|
|
159
189
|
}
|
|
@@ -162,8 +192,22 @@ export let generate = (supplier, interrupt) => {
|
|
|
162
192
|
export let interval = (period, delay = 0) => {
|
|
163
193
|
if (period > 0 && delay >= 0) {
|
|
164
194
|
return new Semantic((accept, interrupt) => {
|
|
165
|
-
|
|
166
|
-
|
|
195
|
+
try {
|
|
196
|
+
if (delay > 0) {
|
|
197
|
+
setTimeout(() => {
|
|
198
|
+
let count = 0;
|
|
199
|
+
let index = 0n;
|
|
200
|
+
let timer = setInterval(() => {
|
|
201
|
+
if (interrupt(count, index)) {
|
|
202
|
+
clearInterval(timer);
|
|
203
|
+
}
|
|
204
|
+
accept(count, BigInt(index));
|
|
205
|
+
index++;
|
|
206
|
+
count += period;
|
|
207
|
+
}, period);
|
|
208
|
+
}, delay);
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
167
211
|
let count = 0;
|
|
168
212
|
let index = 0n;
|
|
169
213
|
let timer = setInterval(() => {
|
|
@@ -174,19 +218,10 @@ export let interval = (period, delay = 0) => {
|
|
|
174
218
|
index++;
|
|
175
219
|
count += period;
|
|
176
220
|
}, period);
|
|
177
|
-
}
|
|
221
|
+
}
|
|
178
222
|
}
|
|
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);
|
|
223
|
+
catch (error) {
|
|
224
|
+
throw new Error("Uncaught error as creating interval semantic.");
|
|
190
225
|
}
|
|
191
226
|
});
|
|
192
227
|
}
|
|
@@ -194,21 +229,31 @@ export let interval = (period, delay = 0) => {
|
|
|
194
229
|
};
|
|
195
230
|
export let iterate = (generator) => {
|
|
196
231
|
if (isFunction(generator)) {
|
|
197
|
-
|
|
232
|
+
try {
|
|
233
|
+
return new Semantic(generator);
|
|
234
|
+
}
|
|
235
|
+
catch (error) {
|
|
236
|
+
throw new Error("Uncaught error as creating iterate semantic.");
|
|
237
|
+
}
|
|
198
238
|
}
|
|
199
239
|
throw new TypeError("Invalid arguments.");
|
|
200
240
|
};
|
|
201
241
|
export let promise = (promise) => {
|
|
202
242
|
if (isPromise(promise)) {
|
|
203
243
|
return new Semantic((accept, interrupt) => {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
244
|
+
try {
|
|
245
|
+
promise.then((value) => {
|
|
246
|
+
if (interrupt(value, 0n)) {
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
accept(value, 0n);
|
|
250
|
+
}).catch((error) => {
|
|
251
|
+
console.error(error);
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
catch (error) {
|
|
255
|
+
throw new Error("Uncaught error as creating promise semantic.");
|
|
256
|
+
}
|
|
212
257
|
});
|
|
213
258
|
}
|
|
214
259
|
else {
|
|
@@ -223,12 +268,17 @@ export let range = (start, end, step = 1) => {
|
|
|
223
268
|
let minimum = start, maximum = end, limit = Number(step);
|
|
224
269
|
let condition = limit > 0 ? (i) => i < maximum : (i) => i > maximum;
|
|
225
270
|
return new Semantic((accept, interrupt) => {
|
|
226
|
-
|
|
227
|
-
let
|
|
228
|
-
|
|
229
|
-
|
|
271
|
+
try {
|
|
272
|
+
for (let i = minimum; condition(i); i += limit) {
|
|
273
|
+
let value = i;
|
|
274
|
+
if (interrupt(value, BigInt(i))) {
|
|
275
|
+
break;
|
|
276
|
+
}
|
|
277
|
+
accept(value, BigInt(i));
|
|
230
278
|
}
|
|
231
|
-
|
|
279
|
+
}
|
|
280
|
+
catch (error) {
|
|
281
|
+
throw new Error("Uncaught error as creating range semantic.");
|
|
232
282
|
}
|
|
233
283
|
});
|
|
234
284
|
}
|
|
@@ -239,43 +289,48 @@ export let websocket = (websocket) => {
|
|
|
239
289
|
throw new TypeError("WebSocket is invalid.");
|
|
240
290
|
}
|
|
241
291
|
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
|
-
|
|
292
|
+
try {
|
|
293
|
+
let index = 0n;
|
|
294
|
+
let stop = false;
|
|
295
|
+
websocket.addEventListener("open", (event) => {
|
|
296
|
+
if (stop || interrupt(event, index)) {
|
|
297
|
+
stop = true;
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
accept(event, index);
|
|
301
|
+
index++;
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
websocket.addEventListener("message", (event) => {
|
|
305
|
+
if (stop || interrupt(event, index)) {
|
|
306
|
+
stop = true;
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
accept(event, index);
|
|
310
|
+
index++;
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
websocket.addEventListener("error", (event) => {
|
|
314
|
+
if (stop || interrupt(event, index)) {
|
|
315
|
+
stop = true;
|
|
316
|
+
}
|
|
317
|
+
else {
|
|
318
|
+
accept(event, index);
|
|
319
|
+
index++;
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
websocket.addEventListener("close", (event) => {
|
|
323
|
+
if (stop || interrupt(event, index)) {
|
|
324
|
+
stop = true;
|
|
325
|
+
}
|
|
326
|
+
else {
|
|
327
|
+
accept(event, index);
|
|
328
|
+
index++;
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
catch (error) {
|
|
333
|
+
throw new Error("Uncaught error as creating websocket semantic.");
|
|
334
|
+
}
|
|
280
335
|
});
|
|
281
336
|
};
|
package/dist/guard.d.ts
CHANGED
|
@@ -22,4 +22,6 @@ export declare let isStatistics: (t: unknown) => t is Statistics<unknown, number
|
|
|
22
22
|
export declare let isNumericStatistics: (t: unknown) => t is Statistics<unknown, number | bigint>;
|
|
23
23
|
export declare let isBigIntStatistics: (t: unknown) => t is Statistics<unknown, number | bigint>;
|
|
24
24
|
export declare let isPromise: (t: unknown) => t is Promise<unknown>;
|
|
25
|
-
export declare let
|
|
25
|
+
export declare let isAsyncFunction: (t: unknown) => t is AsyncFunction;
|
|
26
|
+
export declare let isGeneratorFunction: (t: unknown) => t is Generator<unknown, unknown, unknown>;
|
|
27
|
+
export declare let isAsyncGeneratorFunction: (t: unknown) => t is AsyncGenerator<unknown, unknown, unknown>;
|
package/dist/guard.js
CHANGED
|
@@ -6,7 +6,7 @@ export let isString = (t) => {
|
|
|
6
6
|
return typeof t === "string";
|
|
7
7
|
};
|
|
8
8
|
export let isNumber = (t) => {
|
|
9
|
-
return typeof t === "number";
|
|
9
|
+
return typeof t === "number" && !Number.isNaN(t) && Number.isFinite(t);
|
|
10
10
|
};
|
|
11
11
|
export let isFunction = (t) => {
|
|
12
12
|
return typeof t === "function";
|
|
@@ -89,9 +89,21 @@ export let isPromise = (t) => {
|
|
|
89
89
|
}
|
|
90
90
|
return false;
|
|
91
91
|
};
|
|
92
|
-
export let
|
|
92
|
+
export let isAsyncFunction = (t) => {
|
|
93
93
|
if (isFunction(t)) {
|
|
94
94
|
return Reflect.get(t, Symbol.toStringTag) === "AsyncFunction" && t.constructor.name === "AsyncFunction";
|
|
95
95
|
}
|
|
96
96
|
return false;
|
|
97
97
|
};
|
|
98
|
+
export let isGeneratorFunction = (t) => {
|
|
99
|
+
if (isObject(t)) {
|
|
100
|
+
return isFunction(t) && Reflect.get(t, "constructor").name === "GeneratorFunction";
|
|
101
|
+
}
|
|
102
|
+
return false;
|
|
103
|
+
};
|
|
104
|
+
export let isAsyncGeneratorFunction = (t) => {
|
|
105
|
+
if (isObject(t)) {
|
|
106
|
+
return isFunction(t) && Reflect.get(t, "constructor").name === "AsyncGeneratorFunction";
|
|
107
|
+
}
|
|
108
|
+
return false;
|
|
109
|
+
};
|
package/dist/hook.d.ts
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
import { type BiPredicate, type DeepPropertyKey, type DeepPropertyValue } from "./utility";
|
|
2
|
+
import type { Comparator, Generator } from "./utility";
|
|
2
3
|
export declare let useCompare: <T>(t1: T, t2: T) => number;
|
|
3
4
|
export declare let useRandom: <T = number | bigint>(index: T) => T;
|
|
4
5
|
export declare let useTraverse: <T extends object>(t: T, callback: BiPredicate<DeepPropertyKey<T>, DeepPropertyValue<T>>) => void;
|
|
6
|
+
export declare let useGenerator: <E>(iterable: Iterable<E>) => Generator<E>;
|
|
7
|
+
interface UseArrange {
|
|
8
|
+
<E>(source: Iterable<E>): Generator<E>;
|
|
9
|
+
<E>(source: Iterable<E>, comparator: Comparator<E>): Generator<E>;
|
|
10
|
+
<E>(source: Generator<E>): Generator<E>;
|
|
11
|
+
<E>(source: Generator<E>, comparator: Comparator<E>): Generator<E>;
|
|
12
|
+
}
|
|
13
|
+
export declare let useArrange: UseArrange;
|
|
14
|
+
export declare let useToNumber: <T = unknown>(target: T) => number;
|
|
15
|
+
export declare let useToBigInt: <T = unknown>(target: T) => bigint;
|
|
16
|
+
export {};
|
package/dist/hook.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useToArray } from "./collector";
|
|
2
|
+
import { isBigInt, isFunction, isIterable, isNumber, isObject, isPrimitive } from "./guard";
|
|
2
3
|
import { validate } from "./utility";
|
|
3
4
|
export let useCompare = (t1, t2) => {
|
|
4
5
|
if (t1 === t2 || Object.is(t1, t2)) {
|
|
@@ -109,3 +110,71 @@ export let useTraverse = (t, callback) => {
|
|
|
109
110
|
traverse(t);
|
|
110
111
|
}
|
|
111
112
|
};
|
|
113
|
+
export let useGenerator = (iterable) => {
|
|
114
|
+
if (isIterable(iterable)) {
|
|
115
|
+
return (accept, interrupt) => {
|
|
116
|
+
let index = 0n;
|
|
117
|
+
for (let element of iterable) {
|
|
118
|
+
if (interrupt(element, index)) {
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
accept(element, index);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
return () => { };
|
|
126
|
+
};
|
|
127
|
+
;
|
|
128
|
+
export let useArrange = (source, comparator) => {
|
|
129
|
+
if (isIterable(source)) {
|
|
130
|
+
let buffer = [...source];
|
|
131
|
+
if (validate(comparator) && isFunction(comparator)) {
|
|
132
|
+
return useGenerator(buffer.sort(comparator));
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
return useGenerator(buffer.map((element, index) => {
|
|
136
|
+
return {
|
|
137
|
+
element: element,
|
|
138
|
+
index: BigInt(((index % buffer.length) + buffer.length) % buffer.length)
|
|
139
|
+
};
|
|
140
|
+
}).sort((a, b) => {
|
|
141
|
+
return Number(a.index - b.index);
|
|
142
|
+
}).map((indexed) => {
|
|
143
|
+
return indexed.element;
|
|
144
|
+
}));
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
else if (isFunction(source)) {
|
|
148
|
+
let collector = useToArray();
|
|
149
|
+
let buffer = collector.collect(source);
|
|
150
|
+
if (validate(comparator) && isFunction(comparator)) {
|
|
151
|
+
return useGenerator(buffer.sort(comparator));
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
return useGenerator(buffer.map((element, index) => {
|
|
155
|
+
return {
|
|
156
|
+
element: element,
|
|
157
|
+
index: BigInt(((index % buffer.length) + buffer.length) % buffer.length)
|
|
158
|
+
};
|
|
159
|
+
}).sort((a, b) => {
|
|
160
|
+
return Number(a.index - b.index);
|
|
161
|
+
}).map((indexed) => {
|
|
162
|
+
return indexed.element;
|
|
163
|
+
}));
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return useGenerator([]);
|
|
167
|
+
};
|
|
168
|
+
export let useToNumber = (target) => {
|
|
169
|
+
if (isNumber(target)) {
|
|
170
|
+
return target;
|
|
171
|
+
}
|
|
172
|
+
let resolved = Reflect.apply(Reflect.get(target, Symbol.toPrimitive), target, ["default"]);
|
|
173
|
+
return isNumber(resolved) ? resolved : 0;
|
|
174
|
+
};
|
|
175
|
+
export let useToBigInt = (target) => {
|
|
176
|
+
if (isBigInt(target)) {
|
|
177
|
+
return target;
|
|
178
|
+
}
|
|
179
|
+
return BigInt(useToNumber(target));
|
|
180
|
+
};
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/semantic.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { Collectable, OrderedCollectable, UnorderedCollectable
|
|
1
|
+
import { Collectable, OrderedCollectable, UnorderedCollectable } from "./collectable";
|
|
2
2
|
import { BigIntStatistics, NumericStatistics } from "./statistics";
|
|
3
3
|
import { type Predicate } from "./utility";
|
|
4
4
|
import type { Generator, Functional, BiFunctional, Consumer, BiConsumer, Comparator } from "./utility";
|
|
5
|
+
import { WindowCollectable } from "./window";
|
|
5
6
|
export declare class Semantic<E> {
|
|
6
7
|
protected generator: Generator<E>;
|
|
7
8
|
protected readonly Semantic: Symbol;
|
|
@@ -40,8 +41,3 @@ export declare class Semantic<E> {
|
|
|
40
41
|
translate(offset: bigint): Semantic<E>;
|
|
41
42
|
translate(translator: BiFunctional<E, bigint, bigint>): Semantic<E>;
|
|
42
43
|
}
|
|
43
|
-
export interface UseTransform {
|
|
44
|
-
<E, R>(generator: Generator<E>, mapper: Functional<E, R>): Generator<R>;
|
|
45
|
-
<E, R>(generator: Generator<E>, mapper: BiFunctional<E, bigint, R>): Generator<R>;
|
|
46
|
-
}
|
|
47
|
-
export declare let useTransform: UseTransform;
|