semantic-typescript 0.3.7 → 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 +82 -2
- package/dist/collector.d.ts +91 -50
- package/dist/collector.js +103 -19
- package/dist/factory.d.ts +5 -1
- package/dist/factory.js +19 -1
- package/dist/guard.d.ts +31 -22
- package/dist/guard.js +89 -59
- package/dist/hash.d.ts +14 -0
- package/dist/hash.js +211 -0
- package/dist/hook.d.ts +16 -3
- package/dist/hook.js +59 -12
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/map.d.ts +72 -0
- package/dist/map.js +247 -0
- package/dist/optional.js +18 -0
- package/dist/semantic.d.ts +15 -4
- package/dist/semantic.js +34 -29
- package/dist/set.d.ts +19 -0
- package/dist/set.js +64 -0
- package/dist/statistics.js +43 -7
- 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 +12 -0
- package/package.json +1 -5
- package/readme.cn.md +400 -133
- package/readme.md +342 -241
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 {
|
|
@@ -9,12 +11,45 @@ export class Collector {
|
|
|
9
11
|
accumulator;
|
|
10
12
|
finisher;
|
|
11
13
|
Collector = CollectableSymbol;
|
|
12
|
-
constructor(identity,
|
|
13
|
-
if (isFunction(identity) && isFunction(
|
|
14
|
+
constructor(identity, interrupt, accumulator, finisher) {
|
|
15
|
+
if (isFunction(identity) && isFunction(interrupt) && isFunction(accumulator) && isFunction(finisher)) {
|
|
14
16
|
this.identity = identity;
|
|
15
|
-
this.interrupt =
|
|
17
|
+
this.interrupt = interrupt;
|
|
16
18
|
this.accumulator = accumulator;
|
|
17
19
|
this.finisher = finisher;
|
|
20
|
+
Object.defineProperties(this, {
|
|
21
|
+
"identity": {
|
|
22
|
+
value: identity,
|
|
23
|
+
writable: false,
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: false
|
|
26
|
+
},
|
|
27
|
+
"interrupt": {
|
|
28
|
+
value: interrupt,
|
|
29
|
+
writable: false,
|
|
30
|
+
enumerable: true,
|
|
31
|
+
configurable: false
|
|
32
|
+
},
|
|
33
|
+
"accumulator": {
|
|
34
|
+
value: accumulator,
|
|
35
|
+
writable: false,
|
|
36
|
+
enumerable: true,
|
|
37
|
+
configurable: false
|
|
38
|
+
},
|
|
39
|
+
"finisher": {
|
|
40
|
+
value: finisher,
|
|
41
|
+
writable: false,
|
|
42
|
+
enumerable: true,
|
|
43
|
+
configurable: false
|
|
44
|
+
},
|
|
45
|
+
"Collector": {
|
|
46
|
+
value: CollectableSymbol,
|
|
47
|
+
writable: false,
|
|
48
|
+
enumerable: false,
|
|
49
|
+
configurable: false
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
Object.freeze(this);
|
|
18
53
|
}
|
|
19
54
|
else {
|
|
20
55
|
throw new TypeError("Invalid arguments");
|
|
@@ -93,20 +128,22 @@ export class Collector {
|
|
|
93
128
|
static full(identity, accumulator, finisher) {
|
|
94
129
|
return new Collector(identity, () => false, accumulator, finisher);
|
|
95
130
|
}
|
|
96
|
-
static shortable(identity,
|
|
97
|
-
return new Collector(identity,
|
|
131
|
+
static shortable(identity, interrupt, accumulator, finisher) {
|
|
132
|
+
return new Collector(identity, interrupt, accumulator, finisher);
|
|
98
133
|
}
|
|
99
134
|
}
|
|
100
135
|
;
|
|
136
|
+
;
|
|
101
137
|
export let useAnyMatch = (predicate) => {
|
|
102
138
|
if (isFunction(predicate)) {
|
|
103
|
-
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);
|
|
104
140
|
}
|
|
105
141
|
throw new TypeError("Predicate must be a function.");
|
|
106
142
|
};
|
|
143
|
+
;
|
|
107
144
|
export let useAllMatch = (predicate) => {
|
|
108
145
|
if (isFunction(predicate)) {
|
|
109
|
-
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);
|
|
110
147
|
}
|
|
111
148
|
throw new TypeError("Predicate must be a function.");
|
|
112
149
|
};
|
|
@@ -165,6 +202,31 @@ export let useError = (argument1, argument2, argument3) => {
|
|
|
165
202
|
});
|
|
166
203
|
}
|
|
167
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
|
+
};
|
|
168
230
|
export let useFindFirst = () => {
|
|
169
231
|
return Collector.shortable(() => Optional.empty(), (_element, _index, accumulator) => validate(accumulator) && accumulator.isPresent(), (accumulator, element) => {
|
|
170
232
|
if (validate(accumulator) && accumulator.isPresent()) {
|
|
@@ -215,16 +277,18 @@ export let useForEach = (action) => {
|
|
|
215
277
|
}
|
|
216
278
|
throw new TypeError("Action must be a function.");
|
|
217
279
|
};
|
|
280
|
+
;
|
|
218
281
|
export let useNoneMatch = (predicate) => {
|
|
219
282
|
if (isFunction(predicate)) {
|
|
220
|
-
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);
|
|
221
284
|
}
|
|
222
285
|
throw new TypeError("Predicate must be a function.");
|
|
223
286
|
};
|
|
287
|
+
;
|
|
224
288
|
export let useGroup = (classifier) => {
|
|
225
289
|
if (isFunction(classifier)) {
|
|
226
|
-
return Collector.full(() => new Map(), (accumulator, element) => {
|
|
227
|
-
let key = classifier(element);
|
|
290
|
+
return Collector.full(() => new Map(), (accumulator, element, index) => {
|
|
291
|
+
let key = classifier(element, index);
|
|
228
292
|
let group = accumulator.get(key) || [];
|
|
229
293
|
group.push(element);
|
|
230
294
|
accumulator.set(key, group);
|
|
@@ -235,10 +299,10 @@ export let useGroup = (classifier) => {
|
|
|
235
299
|
};
|
|
236
300
|
export let useGroupBy = (keyExtractor, valueExtractor) => {
|
|
237
301
|
if (isFunction(keyExtractor) && isFunction(valueExtractor)) {
|
|
238
|
-
return Collector.full(() => new Map(), (accumulator, element) => {
|
|
239
|
-
let key = keyExtractor(element);
|
|
302
|
+
return Collector.full(() => new Map(), (accumulator, element, index) => {
|
|
303
|
+
let key = keyExtractor(element, index);
|
|
240
304
|
let group = accumulator.get(key) || [];
|
|
241
|
-
group.push(valueExtractor(element));
|
|
305
|
+
group.push(valueExtractor(element, index));
|
|
242
306
|
accumulator.set(key, group);
|
|
243
307
|
return accumulator;
|
|
244
308
|
}, (accumulator) => accumulator);
|
|
@@ -322,13 +386,14 @@ export let usePartition = (count) => {
|
|
|
322
386
|
}
|
|
323
387
|
throw new TypeError("Count must be a BigInt.");
|
|
324
388
|
};
|
|
389
|
+
;
|
|
325
390
|
export let usePartitionBy = (classifier) => {
|
|
326
391
|
if (isFunction(classifier)) {
|
|
327
392
|
return Collector.full(() => {
|
|
328
393
|
return [];
|
|
329
|
-
}, (array, element) => {
|
|
330
|
-
let
|
|
331
|
-
while (
|
|
394
|
+
}, (array, element, index) => {
|
|
395
|
+
let resolved = classifier(element, index);
|
|
396
|
+
while (resolved > BigInt(array.length) - 1n) {
|
|
332
397
|
array.push([]);
|
|
333
398
|
}
|
|
334
399
|
array[Number(index)].push(element);
|
|
@@ -374,11 +439,24 @@ export let useToArray = () => {
|
|
|
374
439
|
return array;
|
|
375
440
|
}, (array) => array);
|
|
376
441
|
};
|
|
442
|
+
;
|
|
377
443
|
export let useToMap = (keyExtractor, valueExtractor) => {
|
|
378
444
|
if (isFunction(keyExtractor) && isFunction(valueExtractor)) {
|
|
379
|
-
return Collector.full(() => new Map(), (map, element) => {
|
|
380
|
-
let key = keyExtractor(element);
|
|
381
|
-
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);
|
|
382
460
|
map.set(key, value);
|
|
383
461
|
return map;
|
|
384
462
|
}, (map) => map);
|
|
@@ -391,6 +469,12 @@ export let useToSet = () => {
|
|
|
391
469
|
return set;
|
|
392
470
|
}, (set) => set);
|
|
393
471
|
};
|
|
472
|
+
export let useToHashSet = () => {
|
|
473
|
+
return Collector.full(() => new HashSet(), (set, element) => {
|
|
474
|
+
set.add(element);
|
|
475
|
+
return set;
|
|
476
|
+
}, (set) => set);
|
|
477
|
+
};
|
|
394
478
|
;
|
|
395
479
|
export let useWrite = (argument1, argument2) => {
|
|
396
480
|
if (isObject(argument1)) {
|
package/dist/factory.d.ts
CHANGED
|
@@ -9,7 +9,11 @@ export declare let attribute: <T extends object>(target: T) => Semantic<Attribut
|
|
|
9
9
|
export declare let blob: Functional<Blob, Semantic<Uint8Array>> & BiFunctional<Blob, bigint, Semantic<Uint8Array>>;
|
|
10
10
|
export declare let empty: <E>() => Semantic<E>;
|
|
11
11
|
export declare let fill: (<E>(element: E, count: bigint) => Semantic<E>) & (<E>(supplier: Supplier<E>, count: bigint) => Semantic<E>);
|
|
12
|
-
export
|
|
12
|
+
export interface From {
|
|
13
|
+
<E>(iterable: Iterable<E>): Semantic<E>;
|
|
14
|
+
<E>(iterable: AsyncIterable<E>): Semantic<E>;
|
|
15
|
+
}
|
|
16
|
+
export declare let from: From;
|
|
13
17
|
export declare let generate: (<E>(supplier: Supplier<E>, interrupt: Predicate<E>) => Semantic<E>) & (<E>(supplier: Supplier<E>, interrupt: BiPredicate<E, bigint>) => Semantic<E>);
|
|
14
18
|
export declare let interval: Functional<number, Semantic<number>> & BiFunctional<number, number, Semantic<number>>;
|
|
15
19
|
export declare let iterate: <E>(generator: Generator<E>) => Semantic<E>;
|
package/dist/factory.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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";
|
|
@@ -148,6 +148,7 @@ export let fill = (element, count) => {
|
|
|
148
148
|
}
|
|
149
149
|
throw new TypeError("Invalid arguments.");
|
|
150
150
|
};
|
|
151
|
+
;
|
|
151
152
|
export let from = (iterable) => {
|
|
152
153
|
if (isIterable(iterable)) {
|
|
153
154
|
return new Semantic((accept, interrupt) => {
|
|
@@ -166,6 +167,23 @@ export let from = (iterable) => {
|
|
|
166
167
|
}
|
|
167
168
|
});
|
|
168
169
|
}
|
|
170
|
+
else if (isAsyncIterable(iterable)) {
|
|
171
|
+
return new Semantic(async (accept, interrupt) => {
|
|
172
|
+
try {
|
|
173
|
+
let index = 0n;
|
|
174
|
+
for await (let element of iterable) {
|
|
175
|
+
if (interrupt(element, index)) {
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
accept(element, index);
|
|
179
|
+
index++;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
throw new Error("Uncaught error as creating from semantic.");
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
}
|
|
169
187
|
throw new TypeError("Invalid arguments");
|
|
170
188
|
};
|
|
171
189
|
export let generate = (supplier, interrupt) => {
|
package/dist/guard.d.ts
CHANGED
|
@@ -1,27 +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
8
|
import type { AsyncFunction, MaybePrimitive, Primitive } from "./utility";
|
|
6
|
-
|
|
7
|
-
export declare let
|
|
8
|
-
export declare let
|
|
9
|
-
export declare let
|
|
10
|
-
export declare let
|
|
11
|
-
export declare let
|
|
12
|
-
export declare let
|
|
13
|
-
export declare let
|
|
14
|
-
export declare let
|
|
15
|
-
export declare let
|
|
16
|
-
export declare let
|
|
17
|
-
export declare let
|
|
18
|
-
export declare let
|
|
19
|
-
export declare let
|
|
20
|
-
export declare let
|
|
21
|
-
export declare let
|
|
22
|
-
export declare let
|
|
23
|
-
export declare let
|
|
24
|
-
export declare let
|
|
25
|
-
export declare let
|
|
26
|
-
export declare let
|
|
27
|
-
export declare let
|
|
9
|
+
import type { WindowCollectable } from "./window";
|
|
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>;
|
package/dist/guard.js
CHANGED
|
@@ -1,109 +1,139 @@
|
|
|
1
|
-
import { BigIntStatisticsSymbol, CollectableSymbol, CollectorsSymbol, NumericStatisticsSymbol, OrderedCollectableSymbol, SemanticSymbol, StatisticsSymbol, UnorderedCollectableSymbol } from "./symbol";
|
|
2
|
-
export let isBoolean = (
|
|
3
|
-
return typeof
|
|
1
|
+
import { BigIntStatisticsSymbol, CollectableSymbol, CollectorsSymbol, HashableSymbol, NumericStatisticsSymbol, OrderedCollectableSymbol, SemanticMapSymbol, SemanticSymbol, StatisticsSymbol, UnorderedCollectableSymbol, WindowCollectableSymbol } from "./symbol";
|
|
2
|
+
export let isBoolean = (target) => {
|
|
3
|
+
return typeof target === "boolean";
|
|
4
4
|
};
|
|
5
|
-
export let isString = (
|
|
6
|
-
return typeof
|
|
5
|
+
export let isString = (target) => {
|
|
6
|
+
return typeof target === "string";
|
|
7
7
|
};
|
|
8
|
-
export let isNumber = (
|
|
9
|
-
return typeof
|
|
8
|
+
export let isNumber = (target) => {
|
|
9
|
+
return typeof target === "number" && !Number.isNaN(target) && Number.isFinite(target);
|
|
10
10
|
};
|
|
11
|
-
export let isFunction = (
|
|
12
|
-
return typeof
|
|
11
|
+
export let isFunction = (target) => {
|
|
12
|
+
return typeof target === "function";
|
|
13
13
|
};
|
|
14
|
-
export let isObject = (
|
|
15
|
-
return typeof
|
|
14
|
+
export let isObject = (target) => {
|
|
15
|
+
return typeof target === "object" && target !== null;
|
|
16
16
|
};
|
|
17
|
-
export let isSymbol = (
|
|
18
|
-
return typeof
|
|
17
|
+
export let isSymbol = (target) => {
|
|
18
|
+
return typeof target === "symbol";
|
|
19
19
|
};
|
|
20
|
-
export let isBigInt = (
|
|
21
|
-
return typeof
|
|
20
|
+
export let isBigInt = (target) => {
|
|
21
|
+
return typeof target === "bigint";
|
|
22
22
|
};
|
|
23
|
-
export let isPrimitive = (
|
|
24
|
-
return isBoolean(
|
|
23
|
+
export let isPrimitive = (target) => {
|
|
24
|
+
return isBoolean(target) || isString(target) || isNumber(target) || isSymbol(target) || isBigInt(target) || isFunction(target);
|
|
25
25
|
};
|
|
26
|
-
export let
|
|
27
|
-
if (isObject(
|
|
28
|
-
return isFunction(Reflect.get(
|
|
26
|
+
export let isAsyncIterable = (target) => {
|
|
27
|
+
if (isObject(target)) {
|
|
28
|
+
return isFunction(Reflect.get(target, Symbol.asyncIterator));
|
|
29
29
|
}
|
|
30
30
|
return false;
|
|
31
31
|
};
|
|
32
|
-
export let
|
|
33
|
-
if (isObject(
|
|
34
|
-
return Reflect.get(
|
|
32
|
+
export let isIterable = (target) => {
|
|
33
|
+
if (isObject(target)) {
|
|
34
|
+
return isFunction(Reflect.get(target, Symbol.iterator));
|
|
35
35
|
}
|
|
36
36
|
return false;
|
|
37
37
|
};
|
|
38
|
-
export let
|
|
39
|
-
if (isObject(
|
|
40
|
-
return Reflect.get(
|
|
38
|
+
export let isSemantic = (target) => {
|
|
39
|
+
if (isObject(target)) {
|
|
40
|
+
return Reflect.get(target, "Semantic") === SemanticSymbol;
|
|
41
41
|
}
|
|
42
42
|
return false;
|
|
43
43
|
};
|
|
44
|
-
export let
|
|
45
|
-
if (isObject(
|
|
46
|
-
return Reflect.get(
|
|
44
|
+
export let isCollector = (target) => {
|
|
45
|
+
if (isObject(target)) {
|
|
46
|
+
return Reflect.get(target, "Collector") === CollectorsSymbol;
|
|
47
47
|
}
|
|
48
48
|
return false;
|
|
49
49
|
};
|
|
50
|
-
export let
|
|
51
|
-
if (isObject(
|
|
52
|
-
return Reflect.get(
|
|
50
|
+
export let isCollectable = (target) => {
|
|
51
|
+
if (isObject(target)) {
|
|
52
|
+
return Reflect.get(target, "Collectable") === CollectableSymbol;
|
|
53
53
|
}
|
|
54
54
|
return false;
|
|
55
55
|
};
|
|
56
|
-
export let
|
|
57
|
-
if (isObject(
|
|
58
|
-
return Reflect.get(
|
|
56
|
+
export let isOrderedCollectable = (target) => {
|
|
57
|
+
if (isObject(target)) {
|
|
58
|
+
return Reflect.get(target, "OrderedCollectable") === OrderedCollectableSymbol;
|
|
59
59
|
}
|
|
60
60
|
return false;
|
|
61
61
|
};
|
|
62
|
-
export let
|
|
63
|
-
if (isObject(
|
|
64
|
-
return Reflect.get(
|
|
62
|
+
export let isWindowCollectable = (target) => {
|
|
63
|
+
if (isObject(target)) {
|
|
64
|
+
return Reflect.get(target, "WindowCollectable") === WindowCollectableSymbol;
|
|
65
65
|
}
|
|
66
66
|
return false;
|
|
67
67
|
};
|
|
68
|
-
export let
|
|
69
|
-
if (isObject(
|
|
70
|
-
return Reflect.get(
|
|
68
|
+
export let isUnorderedCollectable = (target) => {
|
|
69
|
+
if (isObject(target)) {
|
|
70
|
+
return Reflect.get(target, "UnorderedCollectable") === UnorderedCollectableSymbol;
|
|
71
71
|
}
|
|
72
72
|
return false;
|
|
73
73
|
};
|
|
74
|
-
export let
|
|
75
|
-
if (isObject(
|
|
76
|
-
return Reflect.get(
|
|
74
|
+
export let isStatistics = (target) => {
|
|
75
|
+
if (isObject(target)) {
|
|
76
|
+
return Reflect.get(target, "Statistics") === StatisticsSymbol;
|
|
77
77
|
}
|
|
78
78
|
return false;
|
|
79
79
|
};
|
|
80
|
-
export let
|
|
81
|
-
if (isObject(
|
|
82
|
-
return Reflect.get(
|
|
80
|
+
export let isNumericStatistics = (target) => {
|
|
81
|
+
if (isObject(target)) {
|
|
82
|
+
return Reflect.get(target, "NumericStatistics") === NumericStatisticsSymbol;
|
|
83
83
|
}
|
|
84
84
|
return false;
|
|
85
85
|
};
|
|
86
|
-
export let
|
|
87
|
-
if (isObject(
|
|
88
|
-
return
|
|
86
|
+
export let isBigIntStatistics = (target) => {
|
|
87
|
+
if (isObject(target)) {
|
|
88
|
+
return Reflect.get(target, "BigIntStatistics") === BigIntStatisticsSymbol;
|
|
89
89
|
}
|
|
90
90
|
return false;
|
|
91
91
|
};
|
|
92
|
-
export let
|
|
93
|
-
if (
|
|
94
|
-
return Reflect.get(
|
|
92
|
+
export let isSemanticMap = (target) => {
|
|
93
|
+
if (isObject(target)) {
|
|
94
|
+
return Reflect.get(target, "SemanticMap") === SemanticMapSymbol;
|
|
95
95
|
}
|
|
96
96
|
return false;
|
|
97
97
|
};
|
|
98
|
-
export let
|
|
99
|
-
if (isObject(
|
|
100
|
-
return
|
|
98
|
+
export let isHashable = (target) => {
|
|
99
|
+
if (isObject(target)) {
|
|
100
|
+
return Reflect.get(target, HashableSymbol) === HashableSymbol;
|
|
101
101
|
}
|
|
102
102
|
return false;
|
|
103
103
|
};
|
|
104
|
-
export let
|
|
105
|
-
if (isObject(
|
|
106
|
-
return
|
|
104
|
+
export let isHashMap = (target) => {
|
|
105
|
+
if (isObject(target)) {
|
|
106
|
+
return Reflect.get(target, "HashMap") === SemanticMapSymbol;
|
|
107
|
+
}
|
|
108
|
+
return false;
|
|
109
|
+
};
|
|
110
|
+
export let isHashSet = (target) => {
|
|
111
|
+
if (isObject(target)) {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
return false;
|
|
115
|
+
};
|
|
116
|
+
export let isPromise = (target) => {
|
|
117
|
+
if (isObject(target)) {
|
|
118
|
+
return isFunction(Reflect.get(target, "then")) && isFunction(Reflect.get(target, "catch"));
|
|
119
|
+
}
|
|
120
|
+
return false;
|
|
121
|
+
};
|
|
122
|
+
export let isAsyncFunction = (target) => {
|
|
123
|
+
if (isFunction(target)) {
|
|
124
|
+
return Reflect.get(target, Symbol.toStringTag) === "AsyncFunction" && target.constructor.name === "AsyncFunction";
|
|
125
|
+
}
|
|
126
|
+
return false;
|
|
127
|
+
};
|
|
128
|
+
export let isGeneratorFunction = (target) => {
|
|
129
|
+
if (isObject(target)) {
|
|
130
|
+
return isFunction(target) && Reflect.get(target, "constructor").name === "GeneratorFunction";
|
|
131
|
+
}
|
|
132
|
+
return false;
|
|
133
|
+
};
|
|
134
|
+
export let isAsyncGeneratorFunction = (target) => {
|
|
135
|
+
if (isObject(target)) {
|
|
136
|
+
return isFunction(target) && Reflect.get(target, "constructor").name === "AsyncGeneratorFunction";
|
|
107
137
|
}
|
|
108
138
|
return false;
|
|
109
139
|
};
|
package/dist/hash.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type Type } from "./utility";
|
|
2
|
+
export interface Hashable {
|
|
3
|
+
}
|
|
4
|
+
export declare let maskOf: (type: Type) => bigint;
|
|
5
|
+
interface Handler<T> {
|
|
6
|
+
(value: T): bigint;
|
|
7
|
+
}
|
|
8
|
+
export declare let register: <T>(type: Type, handler: Handler<T>) => void;
|
|
9
|
+
export declare let unregister: (type: Type) => void;
|
|
10
|
+
interface UseHash {
|
|
11
|
+
<T = unknown>(target: T): bigint;
|
|
12
|
+
}
|
|
13
|
+
export declare let useHash: UseHash;
|
|
14
|
+
export {};
|