semantic-typescript 0.3.7 → 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.js +46 -0
- package/dist/collector.d.ts +8 -8
- package/dist/collector.js +113 -47
- package/dist/factory.d.ts +38 -8
- package/dist/factory.js +87 -5
- package/dist/guard.d.ts +7 -4
- package/dist/guard.js +19 -7
- package/dist/hook.d.ts +1 -0
- package/dist/hook.js +51 -8
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/optional.js +36 -3
- package/dist/semantic.d.ts +15 -4
- package/dist/semantic.js +69 -59
- package/dist/statistics.js +30 -0
- package/dist/window.js +10 -0
- package/package.json +1 -1
- package/readme.cn.md +732 -210
- package/readme.md +339 -240
package/dist/collectable.js
CHANGED
|
@@ -8,6 +8,13 @@ import { invalidate, validate } from "./utility";
|
|
|
8
8
|
export class Collectable {
|
|
9
9
|
Collectable = CollectableSymbol;
|
|
10
10
|
constructor() {
|
|
11
|
+
Object.defineProperty(this, "Collectable", {
|
|
12
|
+
value: CollectableSymbol,
|
|
13
|
+
enumerable: false,
|
|
14
|
+
writable: false,
|
|
15
|
+
configurable: false
|
|
16
|
+
});
|
|
17
|
+
Object.freeze(this);
|
|
11
18
|
}
|
|
12
19
|
anyMatch(predicate) {
|
|
13
20
|
if (isFunction(predicate)) {
|
|
@@ -363,6 +370,9 @@ export class Collectable {
|
|
|
363
370
|
}
|
|
364
371
|
}
|
|
365
372
|
;
|
|
373
|
+
Object.freeze(Collectable);
|
|
374
|
+
Object.freeze(Collectable.prototype);
|
|
375
|
+
Object.freeze(Object.getPrototypeOf(Collectable.prototype));
|
|
366
376
|
export class UnorderedCollectable extends Collectable {
|
|
367
377
|
UnorderedCollectable = UnorderedCollectableSymbol;
|
|
368
378
|
generator;
|
|
@@ -370,6 +380,21 @@ export class UnorderedCollectable extends Collectable {
|
|
|
370
380
|
super();
|
|
371
381
|
if (isFunction(argument1)) {
|
|
372
382
|
this.generator = argument1;
|
|
383
|
+
Object.defineProperties(this, {
|
|
384
|
+
"UnorderedCollectable": {
|
|
385
|
+
value: UnorderedCollectableSymbol,
|
|
386
|
+
writable: false,
|
|
387
|
+
enumerable: false,
|
|
388
|
+
configurable: false
|
|
389
|
+
},
|
|
390
|
+
"generator": {
|
|
391
|
+
value: this.generator,
|
|
392
|
+
writable: false,
|
|
393
|
+
enumerable: false,
|
|
394
|
+
configurable: false
|
|
395
|
+
}
|
|
396
|
+
});
|
|
397
|
+
Object.freeze(this);
|
|
373
398
|
}
|
|
374
399
|
else {
|
|
375
400
|
throw new TypeError("Source must be an iterable or a generator function.");
|
|
@@ -398,6 +423,9 @@ export class UnorderedCollectable extends Collectable {
|
|
|
398
423
|
}
|
|
399
424
|
}
|
|
400
425
|
;
|
|
426
|
+
Object.freeze(UnorderedCollectable);
|
|
427
|
+
Object.freeze(UnorderedCollectable.prototype);
|
|
428
|
+
Object.freeze(Object.getPrototypeOf(UnorderedCollectable.prototype));
|
|
401
429
|
export class OrderedCollectable extends Collectable {
|
|
402
430
|
OrderedCollectable = OrderedCollectableSymbol;
|
|
403
431
|
buffer;
|
|
@@ -425,6 +453,21 @@ export class OrderedCollectable extends Collectable {
|
|
|
425
453
|
return Number(a.index - b.index);
|
|
426
454
|
});
|
|
427
455
|
}
|
|
456
|
+
Object.defineProperties(this, {
|
|
457
|
+
"OrderedCollectable": {
|
|
458
|
+
value: OrderedCollectableSymbol,
|
|
459
|
+
writable: false,
|
|
460
|
+
enumerable: false,
|
|
461
|
+
configurable: false
|
|
462
|
+
},
|
|
463
|
+
"buffer": {
|
|
464
|
+
value: this.buffer,
|
|
465
|
+
writable: false,
|
|
466
|
+
enumerable: false,
|
|
467
|
+
configurable: false
|
|
468
|
+
}
|
|
469
|
+
});
|
|
470
|
+
Object.freeze(this);
|
|
428
471
|
}
|
|
429
472
|
catch (error) {
|
|
430
473
|
throw new Error("Uncaught error on creating buffer.");
|
|
@@ -472,3 +515,6 @@ export class OrderedCollectable extends Collectable {
|
|
|
472
515
|
}
|
|
473
516
|
}
|
|
474
517
|
;
|
|
518
|
+
Object.freeze(OrderedCollectable);
|
|
519
|
+
Object.freeze(OrderedCollectable.prototype);
|
|
520
|
+
Object.freeze(Object.getPrototypeOf(OrderedCollectable.prototype));
|
package/dist/collector.d.ts
CHANGED
|
@@ -3,15 +3,15 @@ import { Optional } from "./optional";
|
|
|
3
3
|
import type { Semantic } from "./semantic";
|
|
4
4
|
import { type BiFunctional, type BiPredicate, type Functional, type Predicate, type Supplier, type TriFunctional, type Generator, type TriPredicate, type Consumer, type BiConsumer, type Comparator } from "./utility";
|
|
5
5
|
export declare class Collector<E, A, R> {
|
|
6
|
-
protected identity: Supplier<A>;
|
|
7
|
-
protected interrupt: Predicate<E> | BiPredicate<E, bigint> | TriPredicate<E, bigint, A>;
|
|
8
|
-
protected accumulator: BiFunctional<A, E, A> | TriFunctional<A, E, bigint, A>;
|
|
9
|
-
protected finisher: Functional<A, R>;
|
|
6
|
+
protected readonly identity: Supplier<A>;
|
|
7
|
+
protected readonly interrupt: Predicate<E> | BiPredicate<E, bigint> | TriPredicate<E, bigint, A>;
|
|
8
|
+
protected readonly accumulator: BiFunctional<A, E, A> | TriFunctional<A, E, bigint, A>;
|
|
9
|
+
protected readonly finisher: Functional<A, R>;
|
|
10
10
|
protected readonly Collector: symbol;
|
|
11
|
-
protected constructor(identity: Supplier<A>,
|
|
12
|
-
protected constructor(identity: Supplier<A>,
|
|
13
|
-
protected constructor(identity: Supplier<A>,
|
|
14
|
-
protected constructor(identity: Supplier<A>,
|
|
11
|
+
protected constructor(identity: Supplier<A>, interrupt: Predicate<E>, accumulator: BiFunctional<A, E, A>, finisher: Functional<A, R>);
|
|
12
|
+
protected constructor(identity: Supplier<A>, interrupt: BiPredicate<E, bigint>, accumulator: BiFunctional<A, E, A>, finisher: Functional<A, R>);
|
|
13
|
+
protected constructor(identity: Supplier<A>, interrupt: Predicate<E>, accumulator: TriFunctional<A, E, bigint, A>, finisher: Functional<A, R>);
|
|
14
|
+
protected constructor(identity: Supplier<A>, interrupt: BiPredicate<E, bigint>, accumulator: TriFunctional<A, E, bigint, A>, finisher: Functional<A, R>);
|
|
15
15
|
collect(generator: Generator<E>): R;
|
|
16
16
|
collect(iterable: Iterable<E>): R;
|
|
17
17
|
collect(semantic: Semantic<E>): R;
|
package/dist/collector.js
CHANGED
|
@@ -9,12 +9,45 @@ export class Collector {
|
|
|
9
9
|
accumulator;
|
|
10
10
|
finisher;
|
|
11
11
|
Collector = CollectableSymbol;
|
|
12
|
-
constructor(identity,
|
|
13
|
-
if (isFunction(identity) && isFunction(
|
|
12
|
+
constructor(identity, interrupt, accumulator, finisher) {
|
|
13
|
+
if (isFunction(identity) && isFunction(interrupt) && isFunction(accumulator) && isFunction(finisher)) {
|
|
14
14
|
this.identity = identity;
|
|
15
|
-
this.interrupt =
|
|
15
|
+
this.interrupt = interrupt;
|
|
16
16
|
this.accumulator = accumulator;
|
|
17
17
|
this.finisher = finisher;
|
|
18
|
+
Object.defineProperties(this, {
|
|
19
|
+
"identity": {
|
|
20
|
+
enumerable: false,
|
|
21
|
+
writable: false,
|
|
22
|
+
configurable: false,
|
|
23
|
+
value: identity,
|
|
24
|
+
},
|
|
25
|
+
"interrupt": {
|
|
26
|
+
enumerable: false,
|
|
27
|
+
writable: false,
|
|
28
|
+
configurable: false,
|
|
29
|
+
value: interrupt,
|
|
30
|
+
},
|
|
31
|
+
"accumulator": {
|
|
32
|
+
enumerable: false,
|
|
33
|
+
writable: false,
|
|
34
|
+
configurable: false,
|
|
35
|
+
value: accumulator,
|
|
36
|
+
},
|
|
37
|
+
"finisher": {
|
|
38
|
+
enumerable: false,
|
|
39
|
+
writable: false,
|
|
40
|
+
configurable: false,
|
|
41
|
+
value: finisher,
|
|
42
|
+
},
|
|
43
|
+
"Collector": {
|
|
44
|
+
enumerable: false,
|
|
45
|
+
writable: false,
|
|
46
|
+
configurable: false,
|
|
47
|
+
value: CollectableSymbol,
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
Object.freeze(this);
|
|
18
51
|
}
|
|
19
52
|
else {
|
|
20
53
|
throw new TypeError("Invalid arguments");
|
|
@@ -24,68 +57,98 @@ export class Collector {
|
|
|
24
57
|
let accumulator = this.identity();
|
|
25
58
|
let count = 0n;
|
|
26
59
|
if (isFunction(argument1)) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
60
|
+
try {
|
|
61
|
+
let generator = argument1;
|
|
62
|
+
generator((element, index) => {
|
|
63
|
+
accumulator = this.accumulator(accumulator, element, index);
|
|
64
|
+
count++;
|
|
65
|
+
}, (element, index) => this.interrupt(element, index, accumulator));
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
throw new Error("Uncaught error on collect.");
|
|
69
|
+
}
|
|
32
70
|
}
|
|
33
71
|
else if (isIterable(argument1)) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
72
|
+
try {
|
|
73
|
+
let iterable = argument1;
|
|
74
|
+
let index = 0n;
|
|
75
|
+
for (let element of iterable) {
|
|
76
|
+
if (this.interrupt(element, index, accumulator)) {
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
accumulator = this.accumulator(accumulator, element, count);
|
|
80
|
+
count++;
|
|
81
|
+
index++;
|
|
39
82
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
throw new Error("Uncaught error on collect.");
|
|
43
86
|
}
|
|
44
87
|
}
|
|
45
88
|
else if (isSemantic(argument1)) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
89
|
+
try {
|
|
90
|
+
let semantic = argument1;
|
|
91
|
+
let generator = Reflect.get(semantic, "generator");
|
|
92
|
+
if (isFunction(generator)) {
|
|
93
|
+
generator((element, index) => {
|
|
94
|
+
accumulator = this.accumulator(accumulator, element, index);
|
|
95
|
+
count++;
|
|
96
|
+
}, (element, index) => this.interrupt(element, index, accumulator));
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
throw new TypeError("Invalid arguments");
|
|
100
|
+
}
|
|
53
101
|
}
|
|
54
|
-
|
|
55
|
-
throw new
|
|
102
|
+
catch (error) {
|
|
103
|
+
throw new Error("Uncaught error on collect.");
|
|
56
104
|
}
|
|
57
105
|
}
|
|
58
106
|
else if (isCollectable(argument1)) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
107
|
+
try {
|
|
108
|
+
let collectable = argument1;
|
|
109
|
+
let source = collectable.source();
|
|
110
|
+
if (isFunction(source)) {
|
|
111
|
+
let generator = source;
|
|
112
|
+
generator((element, index) => {
|
|
113
|
+
accumulator = this.accumulator(accumulator, element, index);
|
|
114
|
+
count++;
|
|
115
|
+
}, (element, index) => this.interrupt(element, index, accumulator));
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
throw new Error("Uncaught error on collect.");
|
|
67
120
|
}
|
|
68
121
|
}
|
|
69
122
|
else if (isNumber(argument1) && isNumber(argument2)) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
123
|
+
try {
|
|
124
|
+
let start = argument1 < argument2 ? argument1 : argument2;
|
|
125
|
+
let end = argument1 > argument2 ? argument1 : argument2;
|
|
126
|
+
for (let i = start; i < end; i++) {
|
|
127
|
+
if (this.interrupt(i, count, accumulator)) {
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
accumulator = this.accumulator(accumulator, i, count);
|
|
131
|
+
count++;
|
|
75
132
|
}
|
|
76
|
-
|
|
77
|
-
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
throw new Error("Uncaught error on collect.");
|
|
78
136
|
}
|
|
79
137
|
}
|
|
80
138
|
else if (isBigInt(argument1) && isBigInt(argument2)) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
139
|
+
try {
|
|
140
|
+
let start = argument1 < argument2 ? argument1 : argument2;
|
|
141
|
+
let end = argument1 > argument2 ? argument1 : argument2;
|
|
142
|
+
for (let i = start; i < end; i++) {
|
|
143
|
+
if (this.interrupt(i, count, accumulator)) {
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
accumulator = this.accumulator(accumulator, i, count);
|
|
147
|
+
count++;
|
|
86
148
|
}
|
|
87
|
-
|
|
88
|
-
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
throw new Error("Uncaught error on collect.");
|
|
89
152
|
}
|
|
90
153
|
}
|
|
91
154
|
return this.finisher(accumulator);
|
|
@@ -98,6 +161,9 @@ export class Collector {
|
|
|
98
161
|
}
|
|
99
162
|
}
|
|
100
163
|
;
|
|
164
|
+
Object.freeze(Collector);
|
|
165
|
+
Object.freeze(Collector.prototype);
|
|
166
|
+
Object.freeze(Object.getPrototypeOf(Collector));
|
|
101
167
|
export let useAnyMatch = (predicate) => {
|
|
102
168
|
if (isFunction(predicate)) {
|
|
103
169
|
return Collector.shortable(() => false, (_element, _index, accumulator) => isBoolean(accumulator) && accumulator, (accumulator, element) => accumulator || predicate(element), (accumulator) => accumulator);
|
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,7 +1,8 @@
|
|
|
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.");
|
|
@@ -56,6 +57,7 @@ export let attribute = (target) => {
|
|
|
56
57
|
}
|
|
57
58
|
throw new TypeError("Target must be an object.");
|
|
58
59
|
};
|
|
60
|
+
;
|
|
59
61
|
export let blob = (blob, chunk = 64n * 1024n) => {
|
|
60
62
|
let size = Number(chunk);
|
|
61
63
|
if (size <= 0 || !Number.isSafeInteger(size)) {
|
|
@@ -129,6 +131,7 @@ export let blob = (blob, chunk = 64n * 1024n) => {
|
|
|
129
131
|
export let empty = () => {
|
|
130
132
|
return new Semantic(() => { });
|
|
131
133
|
};
|
|
134
|
+
;
|
|
132
135
|
export let fill = (element, count) => {
|
|
133
136
|
if (validate(element) && count > 0n) {
|
|
134
137
|
return new Semantic((accept, interrupt) => {
|
|
@@ -148,6 +151,7 @@ export let fill = (element, count) => {
|
|
|
148
151
|
}
|
|
149
152
|
throw new TypeError("Invalid arguments.");
|
|
150
153
|
};
|
|
154
|
+
;
|
|
151
155
|
export let from = (iterable) => {
|
|
152
156
|
if (isIterable(iterable)) {
|
|
153
157
|
return new Semantic((accept, interrupt) => {
|
|
@@ -166,15 +170,91 @@ export let from = (iterable) => {
|
|
|
166
170
|
}
|
|
167
171
|
});
|
|
168
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.");
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
}
|
|
169
190
|
throw new TypeError("Invalid arguments");
|
|
170
191
|
};
|
|
171
|
-
|
|
172
|
-
|
|
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;
|
|
173
236
|
return new Semantic((accept, interrupt) => {
|
|
174
237
|
try {
|
|
175
238
|
let index = 0n;
|
|
176
239
|
while (true) {
|
|
177
|
-
|
|
240
|
+
if (interrupt(element, index) || shutdown(element, index)) {
|
|
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) {
|
|
178
258
|
if (interrupt(element, index)) {
|
|
179
259
|
break;
|
|
180
260
|
}
|
|
@@ -187,8 +267,9 @@ export let generate = (supplier, interrupt) => {
|
|
|
187
267
|
}
|
|
188
268
|
});
|
|
189
269
|
}
|
|
190
|
-
throw new TypeError("Invalid arguments");
|
|
270
|
+
throw new TypeError("Invalid arguments.");
|
|
191
271
|
};
|
|
272
|
+
;
|
|
192
273
|
export let interval = (period, delay = 0) => {
|
|
193
274
|
if (period > 0 && delay >= 0) {
|
|
194
275
|
return new Semantic((accept, interrupt) => {
|
|
@@ -260,6 +341,7 @@ export let promise = (promise) => {
|
|
|
260
341
|
throw new TypeError("Invalid arguments.");
|
|
261
342
|
}
|
|
262
343
|
};
|
|
344
|
+
;
|
|
263
345
|
export let range = (start, end, step = 1) => {
|
|
264
346
|
if ((!isNumber(step) && !isBigInt(step)) || (isNumber(step) && useCompare(step, 0) === 0) || (isBigInt(step) && useCompare(step, 0n) === 0)) {
|
|
265
347
|
throw new TypeError("Step must be numeric and cannot be zero.");
|
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,17 +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>;
|
|
27
|
+
export declare let isGenerator: (t: unknown) => t is Generator<unknown>;
|
|
25
28
|
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>;
|
|
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>;
|
package/dist/guard.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BigIntStatisticsSymbol, CollectableSymbol, CollectorsSymbol, NumericStatisticsSymbol, OrderedCollectableSymbol, SemanticSymbol, StatisticsSymbol, UnorderedCollectableSymbol } from "./symbol";
|
|
1
|
+
import { BigIntStatisticsSymbol, CollectableSymbol, CollectorsSymbol, NumericStatisticsSymbol, OrderedCollectableSymbol, SemanticSymbol, StatisticsSymbol, UnorderedCollectableSymbol, WindowCollectableSymbol } from "./symbol";
|
|
2
2
|
export let isBoolean = (t) => {
|
|
3
3
|
return typeof t === "boolean";
|
|
4
4
|
};
|
|
@@ -23,6 +23,12 @@ export let isBigInt = (t) => {
|
|
|
23
23
|
export let isPrimitive = (t) => {
|
|
24
24
|
return isBoolean(t) || isString(t) || isNumber(t) || isSymbol(t) || isBigInt(t) || isFunction(t);
|
|
25
25
|
};
|
|
26
|
+
export let isAsyncIterable = (t) => {
|
|
27
|
+
if (isObject(t)) {
|
|
28
|
+
return isFunction(Reflect.get(t, Symbol.asyncIterator));
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
};
|
|
26
32
|
export let isIterable = (t) => {
|
|
27
33
|
if (isObject(t)) {
|
|
28
34
|
return isFunction(Reflect.get(t, Symbol.iterator));
|
|
@@ -55,7 +61,7 @@ export let isOrderedCollectable = (t) => {
|
|
|
55
61
|
};
|
|
56
62
|
export let isWindowCollectable = (t) => {
|
|
57
63
|
if (isObject(t)) {
|
|
58
|
-
return Reflect.get(t, "WindowCollectable") ===
|
|
64
|
+
return Reflect.get(t, "WindowCollectable") === WindowCollectableSymbol;
|
|
59
65
|
}
|
|
60
66
|
return false;
|
|
61
67
|
};
|
|
@@ -89,21 +95,27 @@ export let isPromise = (t) => {
|
|
|
89
95
|
}
|
|
90
96
|
return false;
|
|
91
97
|
};
|
|
98
|
+
export let isGenerator = (t) => {
|
|
99
|
+
if (isFunction(t)) {
|
|
100
|
+
return t.length === 2;
|
|
101
|
+
}
|
|
102
|
+
return false;
|
|
103
|
+
};
|
|
92
104
|
export let isAsyncFunction = (t) => {
|
|
93
105
|
if (isFunction(t)) {
|
|
94
|
-
return Reflect.get(t, Symbol.toStringTag) === "AsyncFunction"
|
|
106
|
+
return Reflect.get(t, Symbol.toStringTag) === "AsyncFunction";
|
|
95
107
|
}
|
|
96
108
|
return false;
|
|
97
109
|
};
|
|
98
110
|
export let isGeneratorFunction = (t) => {
|
|
99
|
-
if (
|
|
100
|
-
return
|
|
111
|
+
if (isFunction(t)) {
|
|
112
|
+
return Reflect.get(t, Symbol.toStringTag) === "GeneratorFunction";
|
|
101
113
|
}
|
|
102
114
|
return false;
|
|
103
115
|
};
|
|
104
116
|
export let isAsyncGeneratorFunction = (t) => {
|
|
105
|
-
if (
|
|
106
|
-
return
|
|
117
|
+
if (isFunction(t)) {
|
|
118
|
+
return Reflect.get(t, Symbol.toStringTag) === "AsyncGeneratorFunction";
|
|
107
119
|
}
|
|
108
120
|
return false;
|
|
109
121
|
};
|
package/dist/hook.d.ts
CHANGED
|
@@ -13,4 +13,5 @@ interface UseArrange {
|
|
|
13
13
|
export declare let useArrange: UseArrange;
|
|
14
14
|
export declare let useToNumber: <T = unknown>(target: T) => number;
|
|
15
15
|
export declare let useToBigInt: <T = unknown>(target: T) => bigint;
|
|
16
|
+
export declare let useFunction: <T extends ((...args: any[]) => any)>(target: T) => T;
|
|
16
17
|
export {};
|