semantic-typescript 0.3.8 → 0.4.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/dist/collectable.d.ts +12 -0
- package/dist/collectable.js +41 -7
- package/dist/collector.d.ts +91 -50
- package/dist/collector.js +126 -108
- package/dist/factory.d.ts +9 -35
- package/dist/factory.js +4 -68
- package/dist/guard.d.ts +31 -25
- package/dist/guard.js +83 -65
- package/dist/hash.d.ts +14 -0
- package/dist/hash.js +211 -0
- package/dist/hook.d.ts +16 -4
- package/dist/hook.js +19 -15
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/map.d.ts +72 -0
- package/dist/map.js +247 -0
- package/dist/optional.js +8 -23
- package/dist/semantic.js +42 -47
- package/dist/set.d.ts +19 -0
- package/dist/set.js +64 -0
- package/dist/statistics.js +28 -22
- package/dist/symbol.d.ts +8 -0
- package/dist/symbol.js +8 -0
- package/dist/utility.d.ts +8 -1
- package/dist/utility.js +9 -0
- package/dist/window.js +7 -5
- package/package.json +1 -5
- package/readme.cn.md +381 -636
- package/readme.md +3 -1
package/dist/collector.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { isBigInt, isBoolean, isCollectable, isFunction, isIterable, isNumber, isObject, isSemantic, isString } from "./guard";
|
|
2
2
|
import { useCompare, useToBigInt, useToNumber } from "./hook";
|
|
3
|
+
import { HashMap } from "./map";
|
|
3
4
|
import { Optional } from "./optional";
|
|
5
|
+
import { HashSet } from "./set";
|
|
4
6
|
import { CollectableSymbol } from "./symbol";
|
|
5
7
|
import { validate, invalidate } from "./utility";
|
|
6
8
|
export class Collector {
|
|
@@ -17,34 +19,34 @@ export class Collector {
|
|
|
17
19
|
this.finisher = finisher;
|
|
18
20
|
Object.defineProperties(this, {
|
|
19
21
|
"identity": {
|
|
20
|
-
enumerable: false,
|
|
21
|
-
writable: false,
|
|
22
|
-
configurable: false,
|
|
23
22
|
value: identity,
|
|
23
|
+
writable: false,
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: false
|
|
24
26
|
},
|
|
25
27
|
"interrupt": {
|
|
26
|
-
enumerable: false,
|
|
27
|
-
writable: false,
|
|
28
|
-
configurable: false,
|
|
29
28
|
value: interrupt,
|
|
29
|
+
writable: false,
|
|
30
|
+
enumerable: true,
|
|
31
|
+
configurable: false
|
|
30
32
|
},
|
|
31
33
|
"accumulator": {
|
|
32
|
-
enumerable: false,
|
|
33
|
-
writable: false,
|
|
34
|
-
configurable: false,
|
|
35
34
|
value: accumulator,
|
|
35
|
+
writable: false,
|
|
36
|
+
enumerable: true,
|
|
37
|
+
configurable: false
|
|
36
38
|
},
|
|
37
39
|
"finisher": {
|
|
38
|
-
enumerable: false,
|
|
39
|
-
writable: false,
|
|
40
|
-
configurable: false,
|
|
41
40
|
value: finisher,
|
|
41
|
+
writable: false,
|
|
42
|
+
enumerable: true,
|
|
43
|
+
configurable: false
|
|
42
44
|
},
|
|
43
45
|
"Collector": {
|
|
44
|
-
enumerable: false,
|
|
45
|
-
writable: false,
|
|
46
|
-
configurable: false,
|
|
47
46
|
value: CollectableSymbol,
|
|
47
|
+
writable: false,
|
|
48
|
+
enumerable: false,
|
|
49
|
+
configurable: false
|
|
48
50
|
}
|
|
49
51
|
});
|
|
50
52
|
Object.freeze(this);
|
|
@@ -57,98 +59,68 @@ export class Collector {
|
|
|
57
59
|
let accumulator = this.identity();
|
|
58
60
|
let count = 0n;
|
|
59
61
|
if (isFunction(argument1)) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}, (element, index) => this.interrupt(element, index, accumulator));
|
|
66
|
-
}
|
|
67
|
-
catch (error) {
|
|
68
|
-
throw new Error("Uncaught error on collect.");
|
|
69
|
-
}
|
|
62
|
+
let generator = argument1;
|
|
63
|
+
generator((element, index) => {
|
|
64
|
+
accumulator = this.accumulator(accumulator, element, index);
|
|
65
|
+
count++;
|
|
66
|
+
}, (element, index) => this.interrupt(element, index, accumulator));
|
|
70
67
|
}
|
|
71
68
|
else if (isIterable(argument1)) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
break;
|
|
78
|
-
}
|
|
79
|
-
accumulator = this.accumulator(accumulator, element, count);
|
|
80
|
-
count++;
|
|
81
|
-
index++;
|
|
69
|
+
let iterable = argument1;
|
|
70
|
+
let index = 0n;
|
|
71
|
+
for (let element of iterable) {
|
|
72
|
+
if (this.interrupt(element, index, accumulator)) {
|
|
73
|
+
break;
|
|
82
74
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
75
|
+
accumulator = this.accumulator(accumulator, element, count);
|
|
76
|
+
count++;
|
|
77
|
+
index++;
|
|
86
78
|
}
|
|
87
79
|
}
|
|
88
80
|
else if (isSemantic(argument1)) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}, (element, index) => this.interrupt(element, index, accumulator));
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
throw new TypeError("Invalid arguments");
|
|
100
|
-
}
|
|
81
|
+
let semantic = argument1;
|
|
82
|
+
let generator = Reflect.get(semantic, "generator");
|
|
83
|
+
if (isFunction(generator)) {
|
|
84
|
+
generator((element, index) => {
|
|
85
|
+
accumulator = this.accumulator(accumulator, element, index);
|
|
86
|
+
count++;
|
|
87
|
+
}, (element, index) => this.interrupt(element, index, accumulator));
|
|
101
88
|
}
|
|
102
|
-
|
|
103
|
-
throw new
|
|
89
|
+
else {
|
|
90
|
+
throw new TypeError("Invalid arguments");
|
|
104
91
|
}
|
|
105
92
|
}
|
|
106
93
|
else if (isCollectable(argument1)) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}, (element, index) => this.interrupt(element, index, accumulator));
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
catch (error) {
|
|
119
|
-
throw new Error("Uncaught error on collect.");
|
|
94
|
+
let collectable = argument1;
|
|
95
|
+
let source = collectable.source();
|
|
96
|
+
if (isFunction(source)) {
|
|
97
|
+
let generator = source;
|
|
98
|
+
generator((element, index) => {
|
|
99
|
+
accumulator = this.accumulator(accumulator, element, index);
|
|
100
|
+
count++;
|
|
101
|
+
}, (element, index) => this.interrupt(element, index, accumulator));
|
|
120
102
|
}
|
|
121
103
|
}
|
|
122
104
|
else if (isNumber(argument1) && isNumber(argument2)) {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
break;
|
|
129
|
-
}
|
|
130
|
-
accumulator = this.accumulator(accumulator, i, count);
|
|
131
|
-
count++;
|
|
105
|
+
let start = argument1 < argument2 ? argument1 : argument2;
|
|
106
|
+
let end = argument1 > argument2 ? argument1 : argument2;
|
|
107
|
+
for (let i = start; i < end; i++) {
|
|
108
|
+
if (this.interrupt(i, count, accumulator)) {
|
|
109
|
+
break;
|
|
132
110
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
throw new Error("Uncaught error on collect.");
|
|
111
|
+
accumulator = this.accumulator(accumulator, i, count);
|
|
112
|
+
count++;
|
|
136
113
|
}
|
|
137
114
|
}
|
|
138
115
|
else if (isBigInt(argument1) && isBigInt(argument2)) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
break;
|
|
145
|
-
}
|
|
146
|
-
accumulator = this.accumulator(accumulator, i, count);
|
|
147
|
-
count++;
|
|
116
|
+
let start = argument1 < argument2 ? argument1 : argument2;
|
|
117
|
+
let end = argument1 > argument2 ? argument1 : argument2;
|
|
118
|
+
for (let i = start; i < end; i++) {
|
|
119
|
+
if (this.interrupt(i, count, accumulator)) {
|
|
120
|
+
break;
|
|
148
121
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
throw new Error("Uncaught error on collect.");
|
|
122
|
+
accumulator = this.accumulator(accumulator, i, count);
|
|
123
|
+
count++;
|
|
152
124
|
}
|
|
153
125
|
}
|
|
154
126
|
return this.finisher(accumulator);
|
|
@@ -156,23 +128,22 @@ export class Collector {
|
|
|
156
128
|
static full(identity, accumulator, finisher) {
|
|
157
129
|
return new Collector(identity, () => false, accumulator, finisher);
|
|
158
130
|
}
|
|
159
|
-
static shortable(identity,
|
|
160
|
-
return new Collector(identity,
|
|
131
|
+
static shortable(identity, interrupt, accumulator, finisher) {
|
|
132
|
+
return new Collector(identity, interrupt, accumulator, finisher);
|
|
161
133
|
}
|
|
162
134
|
}
|
|
163
135
|
;
|
|
164
|
-
|
|
165
|
-
Object.freeze(Collector.prototype);
|
|
166
|
-
Object.freeze(Object.getPrototypeOf(Collector));
|
|
136
|
+
;
|
|
167
137
|
export let useAnyMatch = (predicate) => {
|
|
168
138
|
if (isFunction(predicate)) {
|
|
169
|
-
return Collector.shortable(() => false, (_element, _index, accumulator) => isBoolean(accumulator) && accumulator, (accumulator, element) => accumulator || predicate(element), (accumulator) => accumulator);
|
|
139
|
+
return Collector.shortable(() => false, (_element, _index, accumulator) => isBoolean(accumulator) && accumulator, (accumulator, element, index) => accumulator || predicate(element, index), (accumulator) => accumulator);
|
|
170
140
|
}
|
|
171
141
|
throw new TypeError("Predicate must be a function.");
|
|
172
142
|
};
|
|
143
|
+
;
|
|
173
144
|
export let useAllMatch = (predicate) => {
|
|
174
145
|
if (isFunction(predicate)) {
|
|
175
|
-
return Collector.shortable(() => true, (_element, _index, accumulator) => isBoolean(accumulator) && !accumulator, (accumulator, element) => accumulator && predicate(element), (accumulator) => accumulator);
|
|
146
|
+
return Collector.shortable(() => true, (_element, _index, accumulator) => isBoolean(accumulator) && !accumulator, (accumulator, element, index) => accumulator && predicate(element, index), (accumulator) => accumulator);
|
|
176
147
|
}
|
|
177
148
|
throw new TypeError("Predicate must be a function.");
|
|
178
149
|
};
|
|
@@ -231,6 +202,31 @@ export let useError = (argument1, argument2, argument3) => {
|
|
|
231
202
|
});
|
|
232
203
|
}
|
|
233
204
|
};
|
|
205
|
+
;
|
|
206
|
+
export let useFindAt = (index) => {
|
|
207
|
+
let target = useToBigInt(index);
|
|
208
|
+
if (target < 0n) {
|
|
209
|
+
return Collector.full(() => [], (accumulator, element) => {
|
|
210
|
+
accumulator.push(element);
|
|
211
|
+
return accumulator;
|
|
212
|
+
}, (accumulator) => {
|
|
213
|
+
if (accumulator.length === 0) {
|
|
214
|
+
return Optional.empty();
|
|
215
|
+
}
|
|
216
|
+
let limited = (((BigInt(accumulator.length)) % target) + target) % target;
|
|
217
|
+
return Optional.ofNullable(accumulator[Number(limited)]);
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
return Collector.shortable(() => [], (_element, _index, accumulator) => BigInt(accumulator.length) - 1n === target, (accumulator, element) => {
|
|
221
|
+
accumulator.push(element);
|
|
222
|
+
return accumulator;
|
|
223
|
+
}, (accumulator) => {
|
|
224
|
+
if (accumulator.length === 0) {
|
|
225
|
+
return Optional.empty();
|
|
226
|
+
}
|
|
227
|
+
return Optional.ofNullable(accumulator[Number(target)]);
|
|
228
|
+
});
|
|
229
|
+
};
|
|
234
230
|
export let useFindFirst = () => {
|
|
235
231
|
return Collector.shortable(() => Optional.empty(), (_element, _index, accumulator) => validate(accumulator) && accumulator.isPresent(), (accumulator, element) => {
|
|
236
232
|
if (validate(accumulator) && accumulator.isPresent()) {
|
|
@@ -281,16 +277,18 @@ export let useForEach = (action) => {
|
|
|
281
277
|
}
|
|
282
278
|
throw new TypeError("Action must be a function.");
|
|
283
279
|
};
|
|
280
|
+
;
|
|
284
281
|
export let useNoneMatch = (predicate) => {
|
|
285
282
|
if (isFunction(predicate)) {
|
|
286
|
-
return Collector.shortable(() => true, (_element, _index, accumulator) => !accumulator, (accumulator, element) => accumulator && !predicate(element), (accumulator) => !accumulator);
|
|
283
|
+
return Collector.shortable(() => true, (_element, _index, accumulator) => !accumulator, (accumulator, element, index) => accumulator && !predicate(element, index), (accumulator) => !accumulator);
|
|
287
284
|
}
|
|
288
285
|
throw new TypeError("Predicate must be a function.");
|
|
289
286
|
};
|
|
287
|
+
;
|
|
290
288
|
export let useGroup = (classifier) => {
|
|
291
289
|
if (isFunction(classifier)) {
|
|
292
|
-
return Collector.full(() => new Map(), (accumulator, element) => {
|
|
293
|
-
let key = classifier(element);
|
|
290
|
+
return Collector.full(() => new Map(), (accumulator, element, index) => {
|
|
291
|
+
let key = classifier(element, index);
|
|
294
292
|
let group = accumulator.get(key) || [];
|
|
295
293
|
group.push(element);
|
|
296
294
|
accumulator.set(key, group);
|
|
@@ -301,10 +299,10 @@ export let useGroup = (classifier) => {
|
|
|
301
299
|
};
|
|
302
300
|
export let useGroupBy = (keyExtractor, valueExtractor) => {
|
|
303
301
|
if (isFunction(keyExtractor) && isFunction(valueExtractor)) {
|
|
304
|
-
return Collector.full(() => new Map(), (accumulator, element) => {
|
|
305
|
-
let key = keyExtractor(element);
|
|
302
|
+
return Collector.full(() => new Map(), (accumulator, element, index) => {
|
|
303
|
+
let key = keyExtractor(element, index);
|
|
306
304
|
let group = accumulator.get(key) || [];
|
|
307
|
-
group.push(valueExtractor(element));
|
|
305
|
+
group.push(valueExtractor(element, index));
|
|
308
306
|
accumulator.set(key, group);
|
|
309
307
|
return accumulator;
|
|
310
308
|
}, (accumulator) => accumulator);
|
|
@@ -388,13 +386,14 @@ export let usePartition = (count) => {
|
|
|
388
386
|
}
|
|
389
387
|
throw new TypeError("Count must be a BigInt.");
|
|
390
388
|
};
|
|
389
|
+
;
|
|
391
390
|
export let usePartitionBy = (classifier) => {
|
|
392
391
|
if (isFunction(classifier)) {
|
|
393
392
|
return Collector.full(() => {
|
|
394
393
|
return [];
|
|
395
|
-
}, (array, element) => {
|
|
396
|
-
let
|
|
397
|
-
while (
|
|
394
|
+
}, (array, element, index) => {
|
|
395
|
+
let resolved = classifier(element, index);
|
|
396
|
+
while (resolved > BigInt(array.length) - 1n) {
|
|
398
397
|
array.push([]);
|
|
399
398
|
}
|
|
400
399
|
array[Number(index)].push(element);
|
|
@@ -440,11 +439,24 @@ export let useToArray = () => {
|
|
|
440
439
|
return array;
|
|
441
440
|
}, (array) => array);
|
|
442
441
|
};
|
|
442
|
+
;
|
|
443
443
|
export let useToMap = (keyExtractor, valueExtractor) => {
|
|
444
444
|
if (isFunction(keyExtractor) && isFunction(valueExtractor)) {
|
|
445
|
-
return Collector.full(() => new Map(), (map, element) => {
|
|
446
|
-
let key = keyExtractor(element);
|
|
447
|
-
let value = valueExtractor(element);
|
|
445
|
+
return Collector.full(() => new Map(), (map, element, index) => {
|
|
446
|
+
let key = keyExtractor(element, index);
|
|
447
|
+
let value = valueExtractor(element, index);
|
|
448
|
+
map.set(key, value);
|
|
449
|
+
return map;
|
|
450
|
+
}, (map) => map);
|
|
451
|
+
}
|
|
452
|
+
throw new TypeError("Key extractor and value extractor must be functions.");
|
|
453
|
+
};
|
|
454
|
+
;
|
|
455
|
+
export let useToHashMap = (keyExtractor, valueExtractor) => {
|
|
456
|
+
if (isFunction(keyExtractor) && isFunction(valueExtractor)) {
|
|
457
|
+
return Collector.full(() => new HashMap(), (map, element, index) => {
|
|
458
|
+
let key = keyExtractor(element, index);
|
|
459
|
+
let value = valueExtractor(element, index);
|
|
448
460
|
map.set(key, value);
|
|
449
461
|
return map;
|
|
450
462
|
}, (map) => map);
|
|
@@ -457,6 +469,12 @@ export let useToSet = () => {
|
|
|
457
469
|
return set;
|
|
458
470
|
}, (set) => set);
|
|
459
471
|
};
|
|
472
|
+
export let useToHashSet = () => {
|
|
473
|
+
return Collector.full(() => new HashSet(), (set, element) => {
|
|
474
|
+
set.add(element);
|
|
475
|
+
return set;
|
|
476
|
+
}, (set) => set);
|
|
477
|
+
};
|
|
460
478
|
;
|
|
461
479
|
export let useWrite = (argument1, argument2) => {
|
|
462
480
|
if (isObject(argument1)) {
|
package/dist/factory.d.ts
CHANGED
|
@@ -1,49 +1,23 @@
|
|
|
1
1
|
import { Semantic } from "./semantic";
|
|
2
|
-
import type { BiPredicate, Functional, Predicate, Supplier, Generator } from "./utility";
|
|
3
|
-
|
|
4
|
-
(period: number): Semantic<number>;
|
|
5
|
-
(period: number, delay: number): Semantic<number>;
|
|
6
|
-
}
|
|
7
|
-
export declare let animationFrame: AnimationFrameFunction;
|
|
2
|
+
import type { BiFunctional, BiPredicate, Functional, Predicate, Supplier, TriFunctional, Generator } from "./utility";
|
|
3
|
+
export declare let animationFrame: Functional<number, Semantic<number>> & BiFunctional<number, number, Semantic<number>>;
|
|
8
4
|
interface Attribute<T> {
|
|
9
5
|
key: keyof T;
|
|
10
6
|
value: T[keyof T];
|
|
11
7
|
}
|
|
12
8
|
export declare let attribute: <T extends object>(target: T) => Semantic<Attribute<T>>;
|
|
13
|
-
|
|
14
|
-
(blob: Blob): Semantic<Uint8Array>;
|
|
15
|
-
(blob: Blob, chunk: bigint): Semantic<Uint8Array>;
|
|
16
|
-
}
|
|
17
|
-
export declare let blob: BlobFunction;
|
|
9
|
+
export declare let blob: Functional<Blob, Semantic<Uint8Array>> & BiFunctional<Blob, bigint, Semantic<Uint8Array>>;
|
|
18
10
|
export declare let empty: <E>() => Semantic<E>;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
<E>(supplier: Supplier<E>, count: bigint): Semantic<E>;
|
|
22
|
-
}
|
|
23
|
-
export declare let fill: FillFunction;
|
|
24
|
-
export interface FromFunction {
|
|
11
|
+
export declare let fill: (<E>(element: E, count: bigint) => Semantic<E>) & (<E>(supplier: Supplier<E>, count: bigint) => Semantic<E>);
|
|
12
|
+
export interface From {
|
|
25
13
|
<E>(iterable: Iterable<E>): Semantic<E>;
|
|
26
14
|
<E>(iterable: AsyncIterable<E>): Semantic<E>;
|
|
27
15
|
}
|
|
28
|
-
export declare let from:
|
|
29
|
-
|
|
30
|
-
|
|
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;
|
|
16
|
+
export declare let from: From;
|
|
17
|
+
export declare let generate: (<E>(supplier: Supplier<E>, interrupt: Predicate<E>) => Semantic<E>) & (<E>(supplier: Supplier<E>, interrupt: BiPredicate<E, bigint>) => Semantic<E>);
|
|
18
|
+
export declare let interval: Functional<number, Semantic<number>> & BiFunctional<number, number, Semantic<number>>;
|
|
41
19
|
export declare let iterate: <E>(generator: Generator<E>) => Semantic<E>;
|
|
42
20
|
export declare let promise: (<T>(promise: Promise<T>) => Semantic<T>);
|
|
43
|
-
|
|
44
|
-
(start: number, end: number): Semantic<number>;
|
|
45
|
-
(start: number, end: number, step: number): Semantic<number>;
|
|
46
|
-
}
|
|
47
|
-
export declare let range: RangeFunction;
|
|
21
|
+
export declare let range: BiFunctional<number, number, Semantic<number>> & TriFunctional<number, number, number, Semantic<number>>;
|
|
48
22
|
export declare let websocket: Functional<WebSocket, Semantic<MessageEvent | CloseEvent | Event>>;
|
|
49
23
|
export {};
|
package/dist/factory.js
CHANGED
|
@@ -2,7 +2,6 @@ import { isBigInt, isFunction, isIterable, isNumber, isObject, isPromise, isAsyn
|
|
|
2
2
|
import { useCompare, useTraverse } from "./hook";
|
|
3
3
|
import { Semantic } from "./semantic";
|
|
4
4
|
import { invalidate, validate } from "./utility";
|
|
5
|
-
;
|
|
6
5
|
export let animationFrame = (period, delay = 0) => {
|
|
7
6
|
if (period <= 0 || !Number.isFinite(period) || delay < 0 || !Number.isFinite(delay)) {
|
|
8
7
|
throw new TypeError("Period must be positive finite number and delay must be non-negative finite number.");
|
|
@@ -57,7 +56,6 @@ export let attribute = (target) => {
|
|
|
57
56
|
}
|
|
58
57
|
throw new TypeError("Target must be an object.");
|
|
59
58
|
};
|
|
60
|
-
;
|
|
61
59
|
export let blob = (blob, chunk = 64n * 1024n) => {
|
|
62
60
|
let size = Number(chunk);
|
|
63
61
|
if (size <= 0 || !Number.isSafeInteger(size)) {
|
|
@@ -131,7 +129,6 @@ export let blob = (blob, chunk = 64n * 1024n) => {
|
|
|
131
129
|
export let empty = () => {
|
|
132
130
|
return new Semantic(() => { });
|
|
133
131
|
};
|
|
134
|
-
;
|
|
135
132
|
export let fill = (element, count) => {
|
|
136
133
|
if (validate(element) && count > 0n) {
|
|
137
134
|
return new Semantic((accept, interrupt) => {
|
|
@@ -189,72 +186,13 @@ export let from = (iterable) => {
|
|
|
189
186
|
}
|
|
190
187
|
throw new TypeError("Invalid arguments");
|
|
191
188
|
};
|
|
192
|
-
|
|
193
|
-
|
|
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;
|
|
189
|
+
export let generate = (supplier, interrupt) => {
|
|
190
|
+
if (isFunction(supplier) && isFunction(interrupt)) {
|
|
236
191
|
return new Semantic((accept, interrupt) => {
|
|
237
192
|
try {
|
|
238
193
|
let index = 0n;
|
|
239
194
|
while (true) {
|
|
240
|
-
|
|
241
|
-
break;
|
|
242
|
-
}
|
|
243
|
-
accept(element, index);
|
|
244
|
-
index++;
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
catch (error) {
|
|
248
|
-
throw new Error("Uncaught error as creating generate semantic.");
|
|
249
|
-
}
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
|
-
if (isBigInt(argument2)) {
|
|
253
|
-
let limit = argument2;
|
|
254
|
-
return new Semantic((accept, interrupt) => {
|
|
255
|
-
try {
|
|
256
|
-
let index = 0n;
|
|
257
|
-
while (index < limit) {
|
|
195
|
+
let element = supplier();
|
|
258
196
|
if (interrupt(element, index)) {
|
|
259
197
|
break;
|
|
260
198
|
}
|
|
@@ -267,9 +205,8 @@ export let generate = (argument1, argument2) => {
|
|
|
267
205
|
}
|
|
268
206
|
});
|
|
269
207
|
}
|
|
270
|
-
throw new TypeError("Invalid arguments
|
|
208
|
+
throw new TypeError("Invalid arguments");
|
|
271
209
|
};
|
|
272
|
-
;
|
|
273
210
|
export let interval = (period, delay = 0) => {
|
|
274
211
|
if (period > 0 && delay >= 0) {
|
|
275
212
|
return new Semantic((accept, interrupt) => {
|
|
@@ -341,7 +278,6 @@ export let promise = (promise) => {
|
|
|
341
278
|
throw new TypeError("Invalid arguments.");
|
|
342
279
|
}
|
|
343
280
|
};
|
|
344
|
-
;
|
|
345
281
|
export let range = (start, end, step = 1) => {
|
|
346
282
|
if ((!isNumber(step) && !isBigInt(step)) || (isNumber(step) && useCompare(step, 0) === 0) || (isBigInt(step) && useCompare(step, 0n) === 0)) {
|
|
347
283
|
throw new TypeError("Step must be numeric and cannot be zero.");
|
package/dist/guard.d.ts
CHANGED
|
@@ -1,30 +1,36 @@
|
|
|
1
1
|
import type { Collectable, OrderedCollectable, UnorderedCollectable } from "./collectable";
|
|
2
2
|
import type { Collector } from "./collector";
|
|
3
|
+
import type { Hashable } from "./hash";
|
|
4
|
+
import type { HashMap, SemanticMap } from "./map";
|
|
3
5
|
import type { Semantic } from "./semantic";
|
|
6
|
+
import type { HashSet } from "./set";
|
|
4
7
|
import type { Statistics } from "./statistics";
|
|
5
|
-
import type { AsyncFunction,
|
|
8
|
+
import type { AsyncFunction, MaybePrimitive, Primitive } from "./utility";
|
|
6
9
|
import type { WindowCollectable } from "./window";
|
|
7
|
-
export declare let isBoolean: (
|
|
8
|
-
export declare let isString: (
|
|
9
|
-
export declare let isNumber: (
|
|
10
|
-
export declare let isFunction: (
|
|
11
|
-
export declare let isObject: (
|
|
12
|
-
export declare let isSymbol: (
|
|
13
|
-
export declare let isBigInt: (
|
|
14
|
-
export declare let isPrimitive: (
|
|
15
|
-
export declare let isAsyncIterable: (
|
|
16
|
-
export declare let isIterable: (
|
|
17
|
-
export declare let isSemantic: (
|
|
18
|
-
export declare let isCollector: (
|
|
19
|
-
export declare let isCollectable: (
|
|
20
|
-
export declare let isOrderedCollectable: (
|
|
21
|
-
export declare let isWindowCollectable: (
|
|
22
|
-
export declare let isUnorderedCollectable: (
|
|
23
|
-
export declare let isStatistics: (
|
|
24
|
-
export declare let isNumericStatistics: (
|
|
25
|
-
export declare let isBigIntStatistics: (
|
|
26
|
-
export declare let
|
|
27
|
-
export declare let
|
|
28
|
-
export declare let
|
|
29
|
-
export declare let
|
|
30
|
-
export declare let
|
|
10
|
+
export declare let isBoolean: (target: unknown) => target is boolean;
|
|
11
|
+
export declare let isString: (target: unknown) => target is string;
|
|
12
|
+
export declare let isNumber: (target: unknown) => target is number;
|
|
13
|
+
export declare let isFunction: (target: unknown) => target is Function;
|
|
14
|
+
export declare let isObject: (target: unknown) => target is object;
|
|
15
|
+
export declare let isSymbol: (target: unknown) => target is symbol;
|
|
16
|
+
export declare let isBigInt: (target: unknown) => target is bigint;
|
|
17
|
+
export declare let isPrimitive: (target: MaybePrimitive<unknown>) => target is Primitive;
|
|
18
|
+
export declare let isAsyncIterable: (target: unknown) => target is Iterable<unknown>;
|
|
19
|
+
export declare let isIterable: (target: unknown) => target is Iterable<unknown>;
|
|
20
|
+
export declare let isSemantic: (target: unknown) => target is Semantic<unknown>;
|
|
21
|
+
export declare let isCollector: (target: unknown) => target is Collector<unknown, unknown, unknown>;
|
|
22
|
+
export declare let isCollectable: (target: unknown) => target is Collectable<unknown>;
|
|
23
|
+
export declare let isOrderedCollectable: (target: unknown) => target is OrderedCollectable<unknown>;
|
|
24
|
+
export declare let isWindowCollectable: (target: unknown) => target is WindowCollectable<unknown>;
|
|
25
|
+
export declare let isUnorderedCollectable: (target: unknown) => target is UnorderedCollectable<unknown>;
|
|
26
|
+
export declare let isStatistics: (target: unknown) => target is Statistics<unknown, number | bigint>;
|
|
27
|
+
export declare let isNumericStatistics: (target: unknown) => target is Statistics<unknown, number | bigint>;
|
|
28
|
+
export declare let isBigIntStatistics: (target: unknown) => target is Statistics<unknown, number | bigint>;
|
|
29
|
+
export declare let isSemanticMap: (target: unknown) => target is SemanticMap<unknown, unknown>;
|
|
30
|
+
export declare let isHashable: (target: unknown) => target is Hashable;
|
|
31
|
+
export declare let isHashMap: (target: unknown) => target is HashMap<unknown, unknown>;
|
|
32
|
+
export declare let isHashSet: (target: unknown) => target is HashSet<unknown>;
|
|
33
|
+
export declare let isPromise: (target: unknown) => target is Promise<unknown>;
|
|
34
|
+
export declare let isAsyncFunction: (target: unknown) => target is AsyncFunction;
|
|
35
|
+
export declare let isGeneratorFunction: (target: unknown) => target is Generator<unknown, unknown, unknown>;
|
|
36
|
+
export declare let isAsyncGeneratorFunction: (target: unknown) => target is AsyncGenerator<unknown, unknown, unknown>;
|