semantic-typescript 0.3.3 → 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.d.ts +19 -24
- package/dist/collectable.js +373 -175
- package/dist/collector.d.ts +101 -24
- package/dist/collector.js +402 -146
- package/dist/factory.d.ts +38 -8
- package/dist/factory.js +300 -163
- package/dist/guard.d.ts +8 -3
- package/dist/guard.js +29 -5
- package/dist/hook.d.ts +13 -0
- package/dist/hook.js +114 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/optional.js +36 -3
- package/dist/semantic.d.ts +17 -10
- package/dist/semantic.js +355 -195
- package/dist/statistics.d.ts +13 -17
- package/dist/statistics.js +234 -522
- package/dist/utility.d.ts +4 -0
- package/dist/utility.js +2 -1
- package/dist/window.d.ts +12 -0
- package/dist/window.js +70 -0
- package/package.json +1 -1
- package/readme.cn.md +732 -210
- package/readme.md +426 -150
package/dist/utility.d.ts
CHANGED
package/dist/utility.js
CHANGED
|
@@ -2,7 +2,7 @@ export let validate = (t) => {
|
|
|
2
2
|
return t !== null && t !== (void 0);
|
|
3
3
|
};
|
|
4
4
|
export let invalidate = (t) => {
|
|
5
|
-
return t === null || t ===
|
|
5
|
+
return t === null || t === (void 0);
|
|
6
6
|
};
|
|
7
7
|
;
|
|
8
8
|
;
|
|
@@ -15,3 +15,4 @@ export let invalidate = (t) => {
|
|
|
15
15
|
;
|
|
16
16
|
;
|
|
17
17
|
;
|
|
18
|
+
;
|
package/dist/window.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { OrderedCollectable } from "./collectable";
|
|
2
|
+
import type { Semantic } from "./semantic";
|
|
3
|
+
import type { Comparator, Generator } from "./utility";
|
|
4
|
+
export declare class WindowCollectable<E> extends OrderedCollectable<E> {
|
|
5
|
+
protected readonly WindowCollectable: symbol;
|
|
6
|
+
constructor(generator: Generator<E>);
|
|
7
|
+
constructor(generator: Generator<E>, comparator: Comparator<E>);
|
|
8
|
+
[Symbol.iterator](): globalThis.Generator<E, void, undefined>;
|
|
9
|
+
[Symbol.asyncIterator](): globalThis.AsyncGenerator<E, void, undefined>;
|
|
10
|
+
slide(size: bigint, step?: bigint): Semantic<Semantic<E>>;
|
|
11
|
+
tumble(size: bigint): Semantic<Semantic<E>>;
|
|
12
|
+
}
|
package/dist/window.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { OrderedCollectable } from "./collectable";
|
|
2
|
+
import { useToAsyncGeneratorFunction, useToGeneratorFunction } from "./collector";
|
|
3
|
+
import { from } from "./factory";
|
|
4
|
+
import { useCompare } from "./hook";
|
|
5
|
+
import { WindowCollectableSymbol } from "./symbol";
|
|
6
|
+
export class WindowCollectable extends OrderedCollectable {
|
|
7
|
+
WindowCollectable = WindowCollectableSymbol;
|
|
8
|
+
constructor(parameter, comparator = useCompare) {
|
|
9
|
+
super(parameter, comparator);
|
|
10
|
+
Object.defineProperty(this, "WindowCollectable", {
|
|
11
|
+
value: WindowCollectableSymbol,
|
|
12
|
+
enumerable: false,
|
|
13
|
+
writable: false,
|
|
14
|
+
configurable: false
|
|
15
|
+
});
|
|
16
|
+
Object.freeze(this);
|
|
17
|
+
}
|
|
18
|
+
*[Symbol.iterator]() {
|
|
19
|
+
try {
|
|
20
|
+
let collector = useToGeneratorFunction();
|
|
21
|
+
yield* collector.collect(this.source());
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
throw new Error("Uncaught error on Generator.");
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
async *[Symbol.asyncIterator]() {
|
|
28
|
+
try {
|
|
29
|
+
let collector = useToAsyncGeneratorFunction();
|
|
30
|
+
yield* collector.collect(this.source());
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
throw new Error("Uncaught error on AsyncGenerator.");
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
slide(size, step = 1n) {
|
|
37
|
+
if (size > 0n && step > 0n) {
|
|
38
|
+
try {
|
|
39
|
+
let source = this.toArray();
|
|
40
|
+
let windows = [];
|
|
41
|
+
let windowStartIndex = 0n;
|
|
42
|
+
while (windowStartIndex < BigInt(source.length)) {
|
|
43
|
+
let windowEnd = windowStartIndex + size;
|
|
44
|
+
let window = source.slice(Number(windowStartIndex), Number(windowEnd));
|
|
45
|
+
if (window.length > 0) {
|
|
46
|
+
windows.push(window);
|
|
47
|
+
}
|
|
48
|
+
windowStartIndex += step;
|
|
49
|
+
}
|
|
50
|
+
return from(windows).map((window) => from(window));
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
throw new Error("Invalid arguments.");
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
throw new RangeError("Invalid arguments.");
|
|
57
|
+
}
|
|
58
|
+
tumble(size) {
|
|
59
|
+
try {
|
|
60
|
+
return this.slide(size, size);
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
throw new Error("Invalid arguments.");
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
;
|
|
68
|
+
Object.freeze(WindowCollectable);
|
|
69
|
+
Object.freeze(WindowCollectable.prototype);
|
|
70
|
+
Object.freeze(Object.getPrototypeOf(WindowCollectable));
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"url": "https://github.com/eloyhere"
|
|
7
7
|
},
|
|
8
8
|
"description": "A modern type-safe stream processing library inspired by JavaScript Generator, Java Stream, and MySQL Index. Supports lazy evaluation, async streams, statistics, and IO-like operations.",
|
|
9
|
-
"version": "0.3.
|
|
9
|
+
"version": "0.3.8",
|
|
10
10
|
"type": "module",
|
|
11
11
|
"readme": "readme.md",
|
|
12
12
|
"main": "dist/index.js",
|