semantic-typescript 0.4.1 → 0.5.0
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 +108 -2
- package/dist/collectable.js +585 -16
- package/dist/collector.d.ts +3 -0
- package/dist/collector.js +3 -3
- package/dist/factory.d.ts +14 -0
- package/dist/factory.js +159 -1
- package/dist/guard.d.ts +14 -5
- package/dist/guard.js +68 -7
- package/dist/hash.d.ts +1 -2
- package/dist/hash.js +9 -15
- package/dist/index.d.ts +0 -5
- package/dist/index.js +0 -5
- package/dist/map.d.ts +4 -0
- package/dist/map.js +6 -0
- package/dist/node.d.ts +182 -0
- package/dist/node.js +918 -0
- package/dist/optional.d.ts +3 -0
- package/dist/optional.js +18 -0
- package/dist/semantic.d.ts +1 -3
- package/dist/semantic.js +2 -4
- package/dist/set.js +1 -0
- package/dist/statistics.js +7 -7
- package/dist/symbol.d.ts +8 -2
- package/dist/symbol.js +8 -2
- package/dist/tree.d.ts +82 -0
- package/dist/tree.js +257 -0
- package/package.json +1 -1
package/dist/collector.js
CHANGED
|
@@ -297,7 +297,7 @@ export let useGroup = (classifier) => {
|
|
|
297
297
|
}
|
|
298
298
|
throw new TypeError("Classifier must be a function.");
|
|
299
299
|
};
|
|
300
|
-
export let useGroupBy = (keyExtractor, valueExtractor) => {
|
|
300
|
+
export let useGroupBy = (keyExtractor, valueExtractor = (element) => element) => {
|
|
301
301
|
if (isFunction(keyExtractor) && isFunction(valueExtractor)) {
|
|
302
302
|
return Collector.full(() => new Map(), (accumulator, element, index) => {
|
|
303
303
|
let key = keyExtractor(element, index);
|
|
@@ -440,7 +440,7 @@ export let useToArray = () => {
|
|
|
440
440
|
}, (array) => array);
|
|
441
441
|
};
|
|
442
442
|
;
|
|
443
|
-
export let useToMap = (keyExtractor, valueExtractor) => {
|
|
443
|
+
export let useToMap = (keyExtractor, valueExtractor = (element) => element) => {
|
|
444
444
|
if (isFunction(keyExtractor) && isFunction(valueExtractor)) {
|
|
445
445
|
return Collector.full(() => new Map(), (map, element, index) => {
|
|
446
446
|
let key = keyExtractor(element, index);
|
|
@@ -452,7 +452,7 @@ export let useToMap = (keyExtractor, valueExtractor) => {
|
|
|
452
452
|
throw new TypeError("Key extractor and value extractor must be functions.");
|
|
453
453
|
};
|
|
454
454
|
;
|
|
455
|
-
export let useToHashMap = (keyExtractor, valueExtractor) => {
|
|
455
|
+
export let useToHashMap = (keyExtractor, valueExtractor = (element) => element) => {
|
|
456
456
|
if (isFunction(keyExtractor) && isFunction(valueExtractor)) {
|
|
457
457
|
return Collector.full(() => new HashMap(), (map, element, index) => {
|
|
458
458
|
let key = keyExtractor(element, index);
|
package/dist/factory.d.ts
CHANGED
|
@@ -8,6 +8,20 @@ interface Attribute<T> {
|
|
|
8
8
|
export declare let attribute: <T extends object>(target: T) => Semantic<Attribute<T>>;
|
|
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
|
+
type KeyOfEventMap<T extends Window | Document | HTMLElement> = T extends Window ? keyof WindowEventMap : (T extends Document ? keyof DocumentEventMap : (T extends HTMLElement ? keyof HTMLElementEventMap : never));
|
|
12
|
+
type ValueOfEventMap<T extends Window | Document | HTMLElement, K extends KeyOfEventMap<T>> = T extends Window ? (K extends keyof WindowEventMap ? WindowEventMap[K] : never) : (T extends Document ? (K extends keyof DocumentEventMap ? DocumentEventMap[K] : never) : (T extends HTMLElement ? (K extends keyof HTMLElementEventMap ? HTMLElementEventMap[K] : never) : never));
|
|
13
|
+
interface EventFunction {
|
|
14
|
+
<E extends Window, K extends KeyOfEventMap<E>, V = ValueOfEventMap<E, K>>(target: E, key: K): Semantic<V>;
|
|
15
|
+
<E extends Window, K extends KeyOfEventMap<E>, V = ValueOfEventMap<E, K>>(target: E, key: Iterable<K>): Semantic<V>;
|
|
16
|
+
<E extends Document, K extends KeyOfEventMap<E>, V = ValueOfEventMap<E, K>>(target: E, key: K): Semantic<V>;
|
|
17
|
+
<E extends Document, K extends KeyOfEventMap<E>, V = ValueOfEventMap<E, K>>(target: E, key: Iterable<K>): Semantic<V>;
|
|
18
|
+
<E extends Document, K extends KeyOfEventMap<E>, V = ValueOfEventMap<E, K>>(target: E, key: Iterable<K>): Semantic<V>;
|
|
19
|
+
<E extends HTMLElement, K extends KeyOfEventMap<E>, V = ValueOfEventMap<E, K>>(target: E, key: K): Semantic<V>;
|
|
20
|
+
<E extends HTMLElement, K extends KeyOfEventMap<E>, V = ValueOfEventMap<E, K>>(target: E, key: Iterable<K>): Semantic<V>;
|
|
21
|
+
<E extends HTMLElement, K extends KeyOfEventMap<E>, V = ValueOfEventMap<E, K>>(target: Iterable<E>, key: K): Semantic<V>;
|
|
22
|
+
<E extends HTMLElement, K extends KeyOfEventMap<E>, V = ValueOfEventMap<E, K>>(target: Iterable<E>, key: Iterable<K>): Semantic<V>;
|
|
23
|
+
}
|
|
24
|
+
export declare let event: EventFunction;
|
|
11
25
|
export declare let fill: (<E>(element: E, count: bigint) => Semantic<E>) & (<E>(supplier: Supplier<E>, count: bigint) => Semantic<E>);
|
|
12
26
|
export interface From {
|
|
13
27
|
<E>(iterable: Iterable<E>): Semantic<E>;
|
package/dist/factory.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isBigInt, isFunction, isIterable, isNumber, isObject, isPromise, isAsyncIterable } from "./guard";
|
|
1
|
+
import { isBigInt, isFunction, isIterable, isNumber, isObject, isPromise, isAsyncIterable, isWindow, isString, isDocument } from "./guard";
|
|
2
2
|
import { useCompare, useTraverse } from "./hook";
|
|
3
3
|
import { Semantic } from "./semantic";
|
|
4
4
|
import { invalidate, validate } from "./utility";
|
|
@@ -129,6 +129,164 @@ export let blob = (blob, chunk = 64n * 1024n) => {
|
|
|
129
129
|
export let empty = () => {
|
|
130
130
|
return new Semantic(() => { });
|
|
131
131
|
};
|
|
132
|
+
;
|
|
133
|
+
export let event = (argument1, argument2) => {
|
|
134
|
+
if (isWindow(argument1)) {
|
|
135
|
+
let target = argument1;
|
|
136
|
+
if (isString(argument2)) {
|
|
137
|
+
let key = argument2;
|
|
138
|
+
return new Semantic((accept, interrupt) => {
|
|
139
|
+
try {
|
|
140
|
+
let index = 0n;
|
|
141
|
+
let listener = (event) => {
|
|
142
|
+
if (interrupt(event, index)) {
|
|
143
|
+
target.removeEventListener(key, listener);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
accept(event, index);
|
|
147
|
+
index++;
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
target.addEventListener(key, listener);
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
throw new Error("Uncaught error as creating event semantic.");
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
if (isIterable(argument2)) {
|
|
158
|
+
let keys = argument2;
|
|
159
|
+
return new Semantic((accept, interrupt) => {
|
|
160
|
+
try {
|
|
161
|
+
let index = 0n;
|
|
162
|
+
for (let key of keys) {
|
|
163
|
+
if (isString(key)) {
|
|
164
|
+
let listener = (event) => {
|
|
165
|
+
if (interrupt(event, index)) {
|
|
166
|
+
target.removeEventListener(key, listener);
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
accept(event, index);
|
|
170
|
+
index++;
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
target.addEventListener(key, listener);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
catch (error) {
|
|
178
|
+
throw new Error("Uncaught error as creating event semantic.");
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
if (isDocument(argument1)) {
|
|
184
|
+
let target = argument1;
|
|
185
|
+
if (isString(argument2)) {
|
|
186
|
+
let key = argument2;
|
|
187
|
+
return new Semantic((accept, interrupt) => {
|
|
188
|
+
try {
|
|
189
|
+
let index = 0n;
|
|
190
|
+
let listener = (event) => {
|
|
191
|
+
if (interrupt(event, index)) {
|
|
192
|
+
target.removeEventListener(key, listener);
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
accept(event, index);
|
|
196
|
+
index++;
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
target.addEventListener(key, listener);
|
|
200
|
+
}
|
|
201
|
+
catch (error) {
|
|
202
|
+
throw new Error("Uncaught error as creating event semantic.");
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
if (isIterable(argument2)) {
|
|
207
|
+
let keys = argument2;
|
|
208
|
+
return new Semantic((accept, interrupt) => {
|
|
209
|
+
try {
|
|
210
|
+
let index = 0n;
|
|
211
|
+
for (let key of keys) {
|
|
212
|
+
if (isString(key)) {
|
|
213
|
+
let listener = (event) => {
|
|
214
|
+
if (interrupt(event, index)) {
|
|
215
|
+
target.removeEventListener(key, listener);
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
accept(event, index);
|
|
219
|
+
index++;
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
target.addEventListener(key, listener);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
catch (error) {
|
|
227
|
+
throw new Error("Uncaught error as creating event semantic.");
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
if (isIterable(argument1)) {
|
|
233
|
+
let targets = argument1;
|
|
234
|
+
if (isString(argument2)) {
|
|
235
|
+
let key = argument2;
|
|
236
|
+
return new Semantic((accept, interrupt) => {
|
|
237
|
+
try {
|
|
238
|
+
let index = 0n;
|
|
239
|
+
for (let target of targets) {
|
|
240
|
+
if (isObject(target) && isFunction(Reflect.get(target, "addEventListener"))) {
|
|
241
|
+
let listener = (event) => {
|
|
242
|
+
if (interrupt(event, index)) {
|
|
243
|
+
target.removeEventListener(key, listener);
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
accept(event, index);
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
target.addEventListener(key, listener);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
catch (error) {
|
|
254
|
+
throw new Error("Uncaught error as creating event semantic.");
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
if (isIterable(argument2)) {
|
|
259
|
+
let keys = argument2;
|
|
260
|
+
return new Semantic((accept, interrupt) => {
|
|
261
|
+
try {
|
|
262
|
+
let index = 0n;
|
|
263
|
+
for (let target of targets) {
|
|
264
|
+
if (isObject(target) && isFunction(Reflect.get(target, "addEventListener"))) {
|
|
265
|
+
for (let key of keys) {
|
|
266
|
+
if (isString(key)) {
|
|
267
|
+
let listener = (event) => {
|
|
268
|
+
if (interrupt(event, index)) {
|
|
269
|
+
target.removeEventListener(key, listener);
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
accept(event, index);
|
|
273
|
+
index++;
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
target.addEventListener(key, listener);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
catch (error) {
|
|
283
|
+
throw new Error("Uncaught error as creating event semantic.");
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
throw new TypeError("Invalid arguments.");
|
|
289
|
+
};
|
|
132
290
|
export let fill = (element, count) => {
|
|
133
291
|
if (validate(element) && count > 0n) {
|
|
134
292
|
return new Semantic((accept, interrupt) => {
|
package/dist/guard.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import type { Collectable, OrderedCollectable, UnorderedCollectable } from "./collectable";
|
|
1
|
+
import type { Collectable, OrderedCollectable, Statistics, UnorderedCollectable, WindowCollectable } from "./collectable";
|
|
2
2
|
import type { Collector } from "./collector";
|
|
3
|
-
import type { Hashable } from "./hash";
|
|
4
3
|
import type { HashMap, SemanticMap } from "./map";
|
|
4
|
+
import type { BinaryNode, LinearNode, Node } from "./node";
|
|
5
|
+
import type { Optional } from "./optional";
|
|
5
6
|
import type { Semantic } from "./semantic";
|
|
6
7
|
import type { HashSet } from "./set";
|
|
7
|
-
import type { Statistics } from "./statistics";
|
|
8
8
|
import type { AsyncFunction, MaybePrimitive, Primitive } from "./utility";
|
|
9
|
-
import type { WindowCollectable } from "./window";
|
|
10
9
|
export declare let isBoolean: (target: unknown) => target is boolean;
|
|
11
10
|
export declare let isString: (target: unknown) => target is string;
|
|
12
11
|
export declare let isNumber: (target: unknown) => target is number;
|
|
@@ -27,10 +26,20 @@ export declare let isStatistics: (target: unknown) => target is Statistics<unkno
|
|
|
27
26
|
export declare let isNumericStatistics: (target: unknown) => target is Statistics<unknown, number | bigint>;
|
|
28
27
|
export declare let isBigIntStatistics: (target: unknown) => target is Statistics<unknown, number | bigint>;
|
|
29
28
|
export declare let isSemanticMap: (target: unknown) => target is SemanticMap<unknown, unknown>;
|
|
30
|
-
export declare let isHashable: (target: unknown) => target is Hashable;
|
|
31
29
|
export declare let isHashMap: (target: unknown) => target is HashMap<unknown, unknown>;
|
|
32
30
|
export declare let isHashSet: (target: unknown) => target is HashSet<unknown>;
|
|
31
|
+
export declare let isNode: (target: unknown) => target is Node<unknown, any>;
|
|
32
|
+
export declare let isLinearNode: (target: unknown) => target is LinearNode<unknown>;
|
|
33
|
+
export declare let isBinaryNode: (target: unknown) => target is BinaryNode<unknown, any>;
|
|
34
|
+
export declare let isRedBlackNode: (target: unknown) => target is BinaryNode<unknown, any>;
|
|
35
|
+
export declare let isTree: (target: unknown) => target is Node<unknown, any>;
|
|
36
|
+
export declare let isBinaryTree: (target: unknown) => target is Node<unknown, any>;
|
|
37
|
+
export declare let isRedBlackTree: (target: unknown) => target is Node<unknown, any>;
|
|
38
|
+
export declare let isOptional: <T>(target: unknown) => target is Optional<T>;
|
|
33
39
|
export declare let isPromise: (target: unknown) => target is Promise<unknown>;
|
|
34
40
|
export declare let isAsyncFunction: (target: unknown) => target is AsyncFunction;
|
|
35
41
|
export declare let isGeneratorFunction: (target: unknown) => target is Generator<unknown, unknown, unknown>;
|
|
36
42
|
export declare let isAsyncGeneratorFunction: (target: unknown) => target is AsyncGenerator<unknown, unknown, unknown>;
|
|
43
|
+
export declare let isWindow: (target: unknown) => target is Window;
|
|
44
|
+
export declare let isDocument: (target: unknown) => target is Document;
|
|
45
|
+
export declare let isHTMLElemet: (target: unknown) => target is HTMLElement;
|
package/dist/guard.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BigIntStatisticsSymbol, CollectableSymbol, CollectorsSymbol,
|
|
1
|
+
import { BigIntStatisticsSymbol, BinaryNodeSymbol, CollectableSymbol, CollectorsSymbol, LinearNodeSymbol, NodeSymbol, NumericStatisticsSymbol, OptionalSymbol, OrderedCollectableSymbol, RedBlackNodeSymbol, SemanticMapSymbol, SemanticSymbol, StatisticsSymbol, UnorderedCollectableSymbol, WindowCollectableSymbol } from "./symbol";
|
|
2
2
|
export let isBoolean = (target) => {
|
|
3
3
|
return typeof target === "boolean";
|
|
4
4
|
};
|
|
@@ -95,12 +95,6 @@ export let isSemanticMap = (target) => {
|
|
|
95
95
|
}
|
|
96
96
|
return false;
|
|
97
97
|
};
|
|
98
|
-
export let isHashable = (target) => {
|
|
99
|
-
if (isObject(target)) {
|
|
100
|
-
return Reflect.get(target, HashableSymbol) === HashableSymbol;
|
|
101
|
-
}
|
|
102
|
-
return false;
|
|
103
|
-
};
|
|
104
98
|
export let isHashMap = (target) => {
|
|
105
99
|
if (isObject(target)) {
|
|
106
100
|
return Reflect.get(target, "HashMap") === SemanticMapSymbol;
|
|
@@ -113,6 +107,54 @@ export let isHashSet = (target) => {
|
|
|
113
107
|
}
|
|
114
108
|
return false;
|
|
115
109
|
};
|
|
110
|
+
export let isNode = (target) => {
|
|
111
|
+
if (isObject(target)) {
|
|
112
|
+
return Reflect.get(target, "Node") === NodeSymbol;
|
|
113
|
+
}
|
|
114
|
+
return false;
|
|
115
|
+
};
|
|
116
|
+
export let isLinearNode = (target) => {
|
|
117
|
+
if (isObject(target)) {
|
|
118
|
+
return isNode(target) && Reflect.get(target, "LinearNode") === LinearNodeSymbol;
|
|
119
|
+
}
|
|
120
|
+
return false;
|
|
121
|
+
};
|
|
122
|
+
export let isBinaryNode = (target) => {
|
|
123
|
+
if (isObject(target)) {
|
|
124
|
+
return isNode(target) && Reflect.get(target, "BinaryNode") === BinaryNodeSymbol;
|
|
125
|
+
}
|
|
126
|
+
return false;
|
|
127
|
+
};
|
|
128
|
+
export let isRedBlackNode = (target) => {
|
|
129
|
+
if (isObject(target)) {
|
|
130
|
+
return isBinaryNode(target) && Reflect.get(target, "RedBlackNode") === RedBlackNodeSymbol;
|
|
131
|
+
}
|
|
132
|
+
return false;
|
|
133
|
+
};
|
|
134
|
+
export let isTree = (target) => {
|
|
135
|
+
if (isObject(target)) {
|
|
136
|
+
return isNode(target) && (isLinearNode(target) || isBinaryNode(target));
|
|
137
|
+
}
|
|
138
|
+
return false;
|
|
139
|
+
};
|
|
140
|
+
export let isBinaryTree = (target) => {
|
|
141
|
+
if (isObject(target)) {
|
|
142
|
+
return isNode(target) && isBinaryNode(target);
|
|
143
|
+
}
|
|
144
|
+
return false;
|
|
145
|
+
};
|
|
146
|
+
export let isRedBlackTree = (target) => {
|
|
147
|
+
if (isObject(target)) {
|
|
148
|
+
return isNode(target) && isRedBlackNode(target);
|
|
149
|
+
}
|
|
150
|
+
return false;
|
|
151
|
+
};
|
|
152
|
+
export let isOptional = (target) => {
|
|
153
|
+
if (isObject(target)) {
|
|
154
|
+
return Reflect.get(target, "Optional") === OptionalSymbol;
|
|
155
|
+
}
|
|
156
|
+
return false;
|
|
157
|
+
};
|
|
116
158
|
export let isPromise = (target) => {
|
|
117
159
|
if (isObject(target)) {
|
|
118
160
|
return isFunction(Reflect.get(target, "then")) && isFunction(Reflect.get(target, "catch"));
|
|
@@ -137,3 +179,22 @@ export let isAsyncGeneratorFunction = (target) => {
|
|
|
137
179
|
}
|
|
138
180
|
return false;
|
|
139
181
|
};
|
|
182
|
+
export let isWindow = (target) => {
|
|
183
|
+
if (isObject(target) && isObject(Reflect.get(target, "window"))) {
|
|
184
|
+
return Object.prototype.toString.call(Reflect.get(target, "window")) === "[object Window]";
|
|
185
|
+
}
|
|
186
|
+
return false;
|
|
187
|
+
};
|
|
188
|
+
export let isDocument = (target) => {
|
|
189
|
+
if (isObject(target) && isObject(Reflect.get(target, "document"))) {
|
|
190
|
+
return Object.prototype.toString.call(Reflect.get(target, "document")) === "[object HTMLDocument]";
|
|
191
|
+
}
|
|
192
|
+
return false;
|
|
193
|
+
};
|
|
194
|
+
export let isHTMLElemet = (target) => {
|
|
195
|
+
if (isObject(target)) {
|
|
196
|
+
let regex = /^\[object HTML\w+Element\]$/;
|
|
197
|
+
return regex.test(Object.prototype.toString.call(target));
|
|
198
|
+
}
|
|
199
|
+
return false;
|
|
200
|
+
};
|
package/dist/hash.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { type Type } from "./utility";
|
|
2
|
-
export interface Hashable {
|
|
3
|
-
}
|
|
4
2
|
export declare let maskOf: (type: Type) => bigint;
|
|
5
3
|
interface Handler<T> {
|
|
6
4
|
(value: T): bigint;
|
|
@@ -9,6 +7,7 @@ export declare let register: <T>(type: Type, handler: Handler<T>) => void;
|
|
|
9
7
|
export declare let unregister: (type: Type) => void;
|
|
10
8
|
interface UseHash {
|
|
11
9
|
<T = unknown>(target: T): bigint;
|
|
10
|
+
(...value: Array<unknown>): bigint;
|
|
12
11
|
}
|
|
13
12
|
export declare let useHash: UseHash;
|
|
14
13
|
export {};
|
package/dist/hash.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { isBigInt, isBoolean, isFunction,
|
|
1
|
+
import { isBigInt, isBoolean, isFunction, isNumber, isObject, isString, isSymbol } from "./guard";
|
|
2
2
|
import { useTraverse } from "./hook";
|
|
3
|
-
import { HashableSymbol } from "./symbol";
|
|
4
3
|
import { typeOf } from "./utility";
|
|
5
|
-
;
|
|
6
4
|
const masks = new Map();
|
|
7
5
|
masks.set("undefined", BigInt(masks.size));
|
|
8
6
|
masks.set("null", BigInt(masks.size));
|
|
@@ -14,7 +12,6 @@ masks.set("string", BigInt(masks.size));
|
|
|
14
12
|
masks.set("function", BigInt(masks.size));
|
|
15
13
|
masks.set("object", BigInt(masks.size));
|
|
16
14
|
Object.freeze(masks);
|
|
17
|
-
const internal = Object.freeze(Array.from(masks.keys()));
|
|
18
15
|
export let maskOf = (type) => {
|
|
19
16
|
return masks.get(type) || masks.get("object") || 0n;
|
|
20
17
|
};
|
|
@@ -27,7 +24,8 @@ export let register = (type, handler) => {
|
|
|
27
24
|
}
|
|
28
25
|
};
|
|
29
26
|
export let unregister = (type) => {
|
|
30
|
-
|
|
27
|
+
let whiteList = ["undefined", "null", "boolean", "number", "bigint", "symbol", "string", "function", "object"];
|
|
28
|
+
if (isString(type) && handlers.has(type) && !whiteList.includes(type)) {
|
|
31
29
|
handlers.delete(type);
|
|
32
30
|
}
|
|
33
31
|
};
|
|
@@ -196,16 +194,12 @@ register("object", (value) => {
|
|
|
196
194
|
return 0n;
|
|
197
195
|
});
|
|
198
196
|
;
|
|
199
|
-
export let useHash = (
|
|
197
|
+
export let useHash = (...value) => {
|
|
198
|
+
let target = value.length === 1 ? value[0] : value;
|
|
200
199
|
let type = typeOf(target);
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
}
|
|
205
|
-
let hash = Reflect.get(target, HashableSymbol)();
|
|
206
|
-
complex.set(target, hash);
|
|
207
|
-
return hash;
|
|
200
|
+
let handler = handlers.get(type);
|
|
201
|
+
if (handler) {
|
|
202
|
+
return handler(target);
|
|
208
203
|
}
|
|
209
|
-
|
|
210
|
-
return handler(target);
|
|
204
|
+
return 0n;
|
|
211
205
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -2,13 +2,8 @@ export * from "./collectable";
|
|
|
2
2
|
export * from "./collector";
|
|
3
3
|
export * from "./factory";
|
|
4
4
|
export * from "./guard";
|
|
5
|
-
export * from "./hash";
|
|
6
5
|
export * from "./hook";
|
|
7
|
-
export * from "./map";
|
|
8
6
|
export * from "./optional";
|
|
9
7
|
export * from "./semantic";
|
|
10
|
-
export * from "./set";
|
|
11
8
|
export * from "./symbol";
|
|
12
|
-
export * from "./statistics";
|
|
13
9
|
export * from "./utility";
|
|
14
|
-
export * from "./window";
|
package/dist/index.js
CHANGED
|
@@ -2,13 +2,8 @@ export * from "./collectable";
|
|
|
2
2
|
export * from "./collector";
|
|
3
3
|
export * from "./factory";
|
|
4
4
|
export * from "./guard";
|
|
5
|
-
export * from "./hash";
|
|
6
5
|
export * from "./hook";
|
|
7
|
-
export * from "./map";
|
|
8
6
|
export * from "./optional";
|
|
9
7
|
export * from "./semantic";
|
|
10
|
-
export * from "./set";
|
|
11
8
|
export * from "./symbol";
|
|
12
|
-
export * from "./statistics";
|
|
13
9
|
export * from "./utility";
|
|
14
|
-
export * from "./window";
|
package/dist/map.d.ts
CHANGED
package/dist/map.js
CHANGED
|
@@ -16,6 +16,7 @@ export class AbstractSemanticMap {
|
|
|
16
16
|
writable: false,
|
|
17
17
|
configurable: false
|
|
18
18
|
});
|
|
19
|
+
Object.freeze(this);
|
|
19
20
|
}
|
|
20
21
|
compute(key, remapping) {
|
|
21
22
|
let value = this.get(key);
|
|
@@ -127,6 +128,7 @@ export class HashMap extends AbstractSemanticMap {
|
|
|
127
128
|
writable: false,
|
|
128
129
|
configurable: false
|
|
129
130
|
});
|
|
131
|
+
Object.freeze(this);
|
|
130
132
|
}
|
|
131
133
|
clear() {
|
|
132
134
|
this.buckets.clear();
|
|
@@ -245,3 +247,7 @@ export class HashMap extends AbstractSemanticMap {
|
|
|
245
247
|
Object.freeze(HashMap);
|
|
246
248
|
Object.freeze(HashMap.prototype);
|
|
247
249
|
Object.freeze(Object.getPrototypeOf(HashMap));
|
|
250
|
+
export class TreeMap {
|
|
251
|
+
key = (void 0);
|
|
252
|
+
value = (void 0);
|
|
253
|
+
}
|
package/dist/node.d.ts
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { Optional } from "./optional";
|
|
2
|
+
import { type Comparator } from "./utility";
|
|
3
|
+
export interface Node<E, N extends Node<E, N>> extends Iterable<N> {
|
|
4
|
+
ancestors(): Iterable<N>;
|
|
5
|
+
children(): Iterable<N>;
|
|
6
|
+
descendants(): Iterable<N>;
|
|
7
|
+
siblings(): Iterable<N>;
|
|
8
|
+
parent(): Optional<N>;
|
|
9
|
+
root(): N;
|
|
10
|
+
previousSibling(): Optional<N>;
|
|
11
|
+
nextSibling(): Optional<N>;
|
|
12
|
+
preorder(): Generator<N>;
|
|
13
|
+
inorder(): Generator<N>;
|
|
14
|
+
postorder(): Generator<N>;
|
|
15
|
+
breadthfirst(): Generator<N>;
|
|
16
|
+
depth(): bigint;
|
|
17
|
+
height(): bigint;
|
|
18
|
+
width(): bigint;
|
|
19
|
+
level(): bigint;
|
|
20
|
+
isLeaf(): boolean;
|
|
21
|
+
isRoot(): boolean;
|
|
22
|
+
[Symbol.iterator](): Iterator<N>;
|
|
23
|
+
}
|
|
24
|
+
export declare abstract class AbstractNode<E, N extends Node<E, N>> implements Node<E, N> {
|
|
25
|
+
protected readonly Node: symbol;
|
|
26
|
+
constructor();
|
|
27
|
+
ancestors(): Iterable<N>;
|
|
28
|
+
abstract children(): Iterable<N>;
|
|
29
|
+
descendants(): Iterable<N>;
|
|
30
|
+
root(): N;
|
|
31
|
+
siblings(): Iterable<N>;
|
|
32
|
+
abstract parent(): Optional<N>;
|
|
33
|
+
previousSibling(): Optional<N>;
|
|
34
|
+
nextSibling(): Optional<N>;
|
|
35
|
+
preorder(): Generator<N>;
|
|
36
|
+
inorder(): Generator<N>;
|
|
37
|
+
postorder(): Generator<N>;
|
|
38
|
+
breadthfirst(): Generator<N>;
|
|
39
|
+
[Symbol.iterator](): Iterator<N>;
|
|
40
|
+
depth(): bigint;
|
|
41
|
+
height(): bigint;
|
|
42
|
+
width(): bigint;
|
|
43
|
+
level(): bigint;
|
|
44
|
+
isLeaf(): boolean;
|
|
45
|
+
isRoot(): boolean;
|
|
46
|
+
}
|
|
47
|
+
export declare class LinearNode<E> extends AbstractNode<E, LinearNode<E>> {
|
|
48
|
+
protected previous: Optional<LinearNode<E>>;
|
|
49
|
+
protected next: Optional<LinearNode<E>>;
|
|
50
|
+
protected element: Optional<E>;
|
|
51
|
+
protected readonly LinearNode: symbol;
|
|
52
|
+
constructor(element: E);
|
|
53
|
+
constructor(element: E, previous: Optional<LinearNode<E>>, next: Optional<LinearNode<E>>);
|
|
54
|
+
ancestors(): Iterable<LinearNode<E>>;
|
|
55
|
+
descendants(): Iterable<LinearNode<E>>;
|
|
56
|
+
root(): LinearNode<E>;
|
|
57
|
+
siblings(): Iterable<LinearNode<E>>;
|
|
58
|
+
children(): Iterable<LinearNode<E>>;
|
|
59
|
+
parent(): Optional<LinearNode<E>>;
|
|
60
|
+
[Symbol.iterator](): Iterator<LinearNode<E>>;
|
|
61
|
+
getElement(): Optional<E>;
|
|
62
|
+
setElement(element: E): void;
|
|
63
|
+
getPrevious(): Optional<LinearNode<E>>;
|
|
64
|
+
setPrevious(previous: LinearNode<E>): void;
|
|
65
|
+
setPrevious(previous: Optional<LinearNode<E>>): void;
|
|
66
|
+
getNext(): Optional<LinearNode<E>>;
|
|
67
|
+
setNext(next: LinearNode<E>): void;
|
|
68
|
+
setNext(next: Optional<LinearNode<E>>): void;
|
|
69
|
+
linkPrevious(previous: LinearNode<E>): void;
|
|
70
|
+
unlinkPrevious(): void;
|
|
71
|
+
linkNext(next: LinearNode<E>): void;
|
|
72
|
+
unlinkNext(): void;
|
|
73
|
+
}
|
|
74
|
+
export declare abstract class BinaryNode<E, N extends BinaryNode<E, N>> extends AbstractNode<E, N> {
|
|
75
|
+
BinaryNode: symbol;
|
|
76
|
+
protected ancestor: Optional<N>;
|
|
77
|
+
protected left: Optional<N>;
|
|
78
|
+
protected right: Optional<N>;
|
|
79
|
+
protected element: Optional<E>;
|
|
80
|
+
constructor(element: E);
|
|
81
|
+
constructor(element: E, ancestor: Optional<N>, left: Optional<N>, right: Optional<N>);
|
|
82
|
+
ancestors(): Iterable<N>;
|
|
83
|
+
compare(other: N): bigint;
|
|
84
|
+
compare(other: N, comparator: Comparator<E>): bigint;
|
|
85
|
+
descendants(): Iterable<N>;
|
|
86
|
+
abstract identity(): N;
|
|
87
|
+
root(): N;
|
|
88
|
+
siblings(): Iterable<N>;
|
|
89
|
+
children(): Iterable<N>;
|
|
90
|
+
parent(): Optional<N>;
|
|
91
|
+
[Symbol.iterator](): Iterator<N>;
|
|
92
|
+
preorder(): Generator<N>;
|
|
93
|
+
inorder(): Generator<N>;
|
|
94
|
+
postorder(): Generator<N>;
|
|
95
|
+
breadthfirst(): Generator<N>;
|
|
96
|
+
getElement(): Optional<E>;
|
|
97
|
+
setElement(element: E): void;
|
|
98
|
+
getLeft(): Optional<N>;
|
|
99
|
+
setLeft(left: N): void;
|
|
100
|
+
setLeft(left: Optional<N>): void;
|
|
101
|
+
getRight(): Optional<N>;
|
|
102
|
+
setRight(right: N): void;
|
|
103
|
+
setRight(right: Optional<N>): void;
|
|
104
|
+
getAncestor(): Optional<N>;
|
|
105
|
+
setAncestor(ancestor: N): void;
|
|
106
|
+
setAncestor(ancestor: Optional<N>): void;
|
|
107
|
+
linkLeft(left: N): void;
|
|
108
|
+
unlinkLeft(): Optional<N>;
|
|
109
|
+
linkRight(right: N): void;
|
|
110
|
+
unlinkRight(): Optional<N>;
|
|
111
|
+
isLeftChild(): boolean;
|
|
112
|
+
isRightChild(): boolean;
|
|
113
|
+
detach(): void;
|
|
114
|
+
isBanlanced(): boolean;
|
|
115
|
+
isFull(): boolean;
|
|
116
|
+
isComplete(): boolean;
|
|
117
|
+
isPerfect(): boolean;
|
|
118
|
+
invert(): void;
|
|
119
|
+
invert(deep: boolean): void;
|
|
120
|
+
}
|
|
121
|
+
type Color = "RED" | "BLACK";
|
|
122
|
+
export declare class RedBlackNode<E> extends BinaryNode<E, RedBlackNode<E>> {
|
|
123
|
+
protected readonly RedBlackNode: symbol;
|
|
124
|
+
protected color: Color;
|
|
125
|
+
constructor(element: E);
|
|
126
|
+
constructor(element: E, color: Color);
|
|
127
|
+
constructor(element: E, color: Color, ancestor: Optional<RedBlackNode<E>>, left: Optional<RedBlackNode<E>>, right: Optional<RedBlackNode<E>>);
|
|
128
|
+
identity(): RedBlackNode<E>;
|
|
129
|
+
getElement(): Optional<E>;
|
|
130
|
+
setElement(element: E): void;
|
|
131
|
+
getLeft(): Optional<RedBlackNode<E>>;
|
|
132
|
+
getRight(): Optional<RedBlackNode<E>>;
|
|
133
|
+
getColor(): Color;
|
|
134
|
+
setColor(color: Color): void;
|
|
135
|
+
isRed(): boolean;
|
|
136
|
+
isBlack(): boolean;
|
|
137
|
+
turnRed(): void;
|
|
138
|
+
turnBlack(): void;
|
|
139
|
+
toggle(): void;
|
|
140
|
+
compareAndLink(other: RedBlackNode<E>): void;
|
|
141
|
+
compareAndLink(other: RedBlackNode<E>, comparator: Comparator<E>): void;
|
|
142
|
+
rotate(): void;
|
|
143
|
+
rotateLeft(): RedBlackNode<E>;
|
|
144
|
+
rotateRight(): RedBlackNode<E>;
|
|
145
|
+
fix(): void;
|
|
146
|
+
uncle(): Optional<RedBlackNode<E>>;
|
|
147
|
+
findMinimum(): RedBlackNode<E>;
|
|
148
|
+
findMaximum(): RedBlackNode<E>;
|
|
149
|
+
}
|
|
150
|
+
export declare class AverageLevelNode<E> extends BinaryNode<E, AverageLevelNode<E>> {
|
|
151
|
+
constructor(element: E);
|
|
152
|
+
constructor(element: E, ancestor: Optional<AverageLevelNode<E>>, left: Optional<AverageLevelNode<E>>, right: Optional<AverageLevelNode<E>>);
|
|
153
|
+
[Symbol.iterator](): Iterator<AverageLevelNode<E>>;
|
|
154
|
+
identity(): AverageLevelNode<E>;
|
|
155
|
+
getElement(): Optional<E>;
|
|
156
|
+
setElement(element: E): void;
|
|
157
|
+
getLeft(): Optional<AverageLevelNode<E>>;
|
|
158
|
+
getRight(): Optional<AverageLevelNode<E>>;
|
|
159
|
+
}
|
|
160
|
+
export declare class BinarySearchNode<E> extends AbstractNode<E, BinarySearchNode<E>> {
|
|
161
|
+
protected left: Optional<BinarySearchNode<E>>;
|
|
162
|
+
protected right: Optional<BinarySearchNode<E>>;
|
|
163
|
+
protected element: Optional<E>;
|
|
164
|
+
constructor(element: E);
|
|
165
|
+
constructor(element: E, left: Optional<BinarySearchNode<E>>, right: Optional<BinarySearchNode<E>>);
|
|
166
|
+
ancestors(): Iterable<BinarySearchNode<E>>;
|
|
167
|
+
descendants(): Iterable<BinarySearchNode<E>>;
|
|
168
|
+
root(): BinarySearchNode<E>;
|
|
169
|
+
siblings(): Iterable<BinarySearchNode<E>>;
|
|
170
|
+
children(): Iterable<BinarySearchNode<E>>;
|
|
171
|
+
parent(): Optional<BinarySearchNode<E>>;
|
|
172
|
+
[Symbol.iterator](): Iterator<BinarySearchNode<E>>;
|
|
173
|
+
inorder(): Generator<BinarySearchNode<E>>;
|
|
174
|
+
preorder(): Generator<BinarySearchNode<E>>;
|
|
175
|
+
postorder(): Generator<BinarySearchNode<E>>;
|
|
176
|
+
breadthfirst(): Generator<BinarySearchNode<E>>;
|
|
177
|
+
getElement(): Optional<E>;
|
|
178
|
+
setElement(element: E): void;
|
|
179
|
+
getLeft(): Optional<BinarySearchNode<E>>;
|
|
180
|
+
getRight(): Optional<BinarySearchNode<E>>;
|
|
181
|
+
}
|
|
182
|
+
export {};
|