@cspell/cspell-pipe 6.18.1 → 6.19.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/cjs/helpers/distribute.d.ts +13 -0
- package/dist/cjs/helpers/index.d.ts +7 -0
- package/dist/cjs/helpers/interleave.d.ts +2 -0
- package/dist/cjs/helpers/iteratorToIterable.d.ts +3 -0
- package/dist/cjs/helpers/toArray.d.ts +6 -0
- package/dist/cjs/helpers/toAsyncIterable.d.ts +11 -0
- package/dist/cjs/helpers/util.d.ts +4 -0
- package/dist/cjs/index.cjs +644 -0
- package/dist/cjs/index.d.ts +9 -0
- package/dist/cjs/internalTypes.d.ts +17 -0
- package/dist/{operators/append.js → cjs/operators/append.cjs} +10 -8
- package/dist/cjs/operators/append.d.ts +15 -0
- package/dist/{operators/await.js → cjs/operators/await.cjs} +3 -4
- package/dist/cjs/operators/await.d.ts +2 -0
- package/dist/{operators/combine.js → cjs/operators/combine.cjs} +4 -5
- package/dist/cjs/operators/combine.d.ts +23 -0
- package/dist/{operators/concatMap.js → cjs/operators/concatMap.cjs} +16 -8
- package/dist/cjs/operators/concatMap.d.ts +4 -0
- package/dist/{operators/filter.js → cjs/operators/filter.cjs} +10 -8
- package/dist/cjs/operators/filter.d.ts +10 -0
- package/dist/{operators/first.js → cjs/operators/first.cjs} +10 -8
- package/dist/cjs/operators/first.d.ts +10 -0
- package/dist/{operators/flatten.js → cjs/operators/flatten.cjs} +16 -8
- package/dist/cjs/operators/flatten.d.ts +4 -0
- package/dist/cjs/operators/helpers/distribute.d.ts +13 -0
- package/dist/cjs/operators/helpers/index.d.ts +7 -0
- package/dist/cjs/operators/helpers/interleave.d.ts +2 -0
- package/dist/cjs/operators/helpers/iteratorToIterable.d.ts +3 -0
- package/dist/cjs/operators/helpers/toArray.d.ts +6 -0
- package/dist/cjs/operators/helpers/toAsyncIterable.d.ts +11 -0
- package/dist/cjs/operators/helpers/util.d.ts +4 -0
- package/dist/cjs/operators/index.cjs +508 -0
- package/dist/cjs/operators/index.d.ts +17 -0
- package/dist/cjs/operators/internalTypes.d.ts +17 -0
- package/dist/cjs/operators/joinStrings.cjs +49 -0
- package/dist/cjs/operators/joinStrings.d.ts +4 -0
- package/dist/{operators/last.js → cjs/operators/last.cjs} +10 -8
- package/dist/cjs/operators/last.d.ts +10 -0
- package/dist/{operators/map.js → cjs/operators/map.cjs} +16 -8
- package/dist/cjs/operators/map.d.ts +4 -0
- package/dist/cjs/operators/operators/append.d.ts +15 -0
- package/dist/cjs/operators/operators/await.d.ts +2 -0
- package/dist/cjs/operators/operators/combine.d.ts +23 -0
- package/dist/cjs/operators/operators/concatMap.d.ts +4 -0
- package/dist/cjs/operators/operators/filter.d.ts +10 -0
- package/dist/cjs/operators/operators/first.d.ts +10 -0
- package/dist/cjs/operators/operators/flatten.d.ts +4 -0
- package/dist/cjs/operators/operators/index.d.ts +17 -0
- package/dist/cjs/operators/operators/joinStrings.d.ts +4 -0
- package/dist/cjs/operators/operators/last.d.ts +10 -0
- package/dist/cjs/operators/operators/map.d.ts +4 -0
- package/dist/cjs/operators/operators/reduce.d.ts +7 -0
- package/dist/cjs/operators/operators/skip.d.ts +4 -0
- package/dist/cjs/operators/operators/take.d.ts +8 -0
- package/dist/cjs/operators/operators/tap.d.ts +19 -0
- package/dist/cjs/operators/operators/types.d.ts +4 -0
- package/dist/cjs/operators/operators/unique.d.ts +4 -0
- package/dist/cjs/operators/pipe.d.ts +20 -0
- package/dist/{operators/reduce.js → cjs/operators/reduce.cjs} +22 -11
- package/dist/cjs/operators/reduce.d.ts +7 -0
- package/dist/{operators/skip.js → cjs/operators/skip.cjs} +16 -8
- package/dist/cjs/operators/skip.d.ts +4 -0
- package/dist/cjs/operators/sync/index.d.ts +6 -0
- package/dist/{operators/take.js → cjs/operators/take.cjs} +16 -8
- package/dist/cjs/operators/take.d.ts +8 -0
- package/dist/{operators/tap.js → cjs/operators/tap.cjs} +16 -8
- package/dist/cjs/operators/tap.d.ts +19 -0
- package/dist/cjs/operators/types.cjs +2 -0
- package/dist/cjs/operators/types.d.ts +4 -0
- package/dist/{operators/unique.js → cjs/operators/unique.cjs} +16 -8
- package/dist/cjs/operators/unique.d.ts +4 -0
- package/dist/cjs/pipe.d.ts +20 -0
- package/dist/cjs/reduce.d.ts +16 -0
- package/dist/cjs/sync/helpers/distribute.d.ts +13 -0
- package/dist/cjs/sync/helpers/index.d.ts +7 -0
- package/dist/cjs/sync/helpers/interleave.d.ts +2 -0
- package/dist/cjs/sync/helpers/iteratorToIterable.d.ts +3 -0
- package/dist/cjs/sync/helpers/toArray.d.ts +6 -0
- package/dist/cjs/sync/helpers/toAsyncIterable.d.ts +11 -0
- package/dist/cjs/sync/helpers/util.d.ts +4 -0
- package/dist/cjs/sync/index.cjs +245 -0
- package/dist/cjs/sync/index.d.ts +6 -0
- package/dist/cjs/sync/internalTypes.d.ts +17 -0
- package/dist/cjs/sync/operators/append.d.ts +15 -0
- package/dist/cjs/sync/operators/await.d.ts +2 -0
- package/dist/cjs/sync/operators/combine.d.ts +23 -0
- package/dist/cjs/sync/operators/concatMap.d.ts +4 -0
- package/dist/cjs/sync/operators/filter.d.ts +10 -0
- package/dist/cjs/sync/operators/first.d.ts +10 -0
- package/dist/cjs/sync/operators/flatten.d.ts +4 -0
- package/dist/cjs/sync/operators/index.d.ts +17 -0
- package/dist/cjs/sync/operators/joinStrings.d.ts +4 -0
- package/dist/cjs/sync/operators/last.d.ts +10 -0
- package/dist/cjs/sync/operators/map.d.ts +4 -0
- package/dist/cjs/sync/operators/reduce.d.ts +7 -0
- package/dist/cjs/sync/operators/skip.d.ts +4 -0
- package/dist/cjs/sync/operators/take.d.ts +8 -0
- package/dist/cjs/sync/operators/tap.d.ts +19 -0
- package/dist/cjs/sync/operators/types.d.ts +4 -0
- package/dist/cjs/sync/operators/unique.d.ts +4 -0
- package/dist/cjs/sync/pipe.d.ts +20 -0
- package/dist/cjs/sync/reduce.d.ts +16 -0
- package/dist/cjs/sync/sync/index.d.ts +6 -0
- package/dist/esm/helpers/distribute.d.ts +13 -0
- package/dist/{helpers → esm/helpers}/distribute.js +2 -6
- package/dist/esm/helpers/index.d.ts +7 -0
- package/dist/esm/helpers/index.js +7 -0
- package/dist/esm/helpers/interleave.d.ts +2 -0
- package/dist/{helpers → esm/helpers}/interleave.js +1 -5
- package/dist/esm/helpers/iteratorToIterable.d.ts +3 -0
- package/dist/esm/helpers/iteratorToIterable.js +13 -0
- package/dist/esm/helpers/toArray.d.ts +6 -0
- package/dist/esm/helpers/toArray.js +15 -0
- package/dist/esm/helpers/toAsyncIterable.d.ts +11 -0
- package/dist/esm/helpers/toAsyncIterable.js +15 -0
- package/dist/esm/helpers/util.d.ts +4 -0
- package/dist/esm/helpers/util.js +10 -0
- package/dist/esm/index.d.ts +9 -0
- package/dist/esm/index.js +11 -0
- package/dist/esm/internalTypes.d.ts +17 -0
- package/dist/esm/internalTypes.js +2 -0
- package/dist/esm/operators/append.d.ts +15 -0
- package/dist/esm/operators/append.js +36 -0
- package/dist/esm/operators/await.d.ts +2 -0
- package/dist/esm/operators/await.js +9 -0
- package/dist/esm/operators/combine.d.ts +23 -0
- package/dist/esm/operators/combine.js +19 -0
- package/dist/esm/operators/concatMap.d.ts +4 -0
- package/dist/esm/operators/concatMap.js +19 -0
- package/dist/esm/operators/filter.d.ts +10 -0
- package/dist/esm/operators/filter.js +30 -0
- package/dist/esm/operators/first.d.ts +10 -0
- package/dist/esm/operators/first.js +34 -0
- package/dist/esm/operators/flatten.d.ts +4 -0
- package/dist/esm/operators/flatten.js +19 -0
- package/dist/esm/operators/index.d.ts +17 -0
- package/dist/esm/operators/index.js +16 -0
- package/dist/esm/operators/joinStrings.d.ts +4 -0
- package/dist/esm/operators/joinStrings.js +22 -0
- package/dist/esm/operators/last.d.ts +10 -0
- package/dist/esm/operators/last.js +39 -0
- package/dist/esm/operators/map.d.ts +4 -0
- package/dist/esm/operators/map.js +19 -0
- package/dist/esm/operators/reduce.d.ts +7 -0
- package/dist/esm/operators/reduce.js +49 -0
- package/dist/esm/operators/skip.d.ts +4 -0
- package/dist/esm/operators/skip.js +27 -0
- package/dist/esm/operators/take.d.ts +8 -0
- package/dist/esm/operators/take.js +31 -0
- package/dist/esm/operators/tap.d.ts +19 -0
- package/dist/esm/operators/tap.js +36 -0
- package/dist/esm/operators/types.d.ts +4 -0
- package/dist/esm/operators/types.js +2 -0
- package/dist/esm/operators/unique.d.ts +4 -0
- package/dist/esm/operators/unique.js +53 -0
- package/dist/esm/pipe.d.ts +20 -0
- package/dist/esm/pipe.js +10 -0
- package/dist/esm/reduce.d.ts +16 -0
- package/dist/esm/reduce.js +21 -0
- package/dist/esm/sync/index.d.ts +6 -0
- package/dist/esm/sync/index.js +5 -0
- package/dist/helpers/index.d.ts +6 -6
- package/dist/helpers/toAsyncIterable.d.ts +1 -1
- package/dist/helpers/util.d.ts +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/operators/append.d.ts +1 -1
- package/dist/operators/combine.d.ts +2 -2
- package/dist/operators/concatMap.d.ts +1 -1
- package/dist/operators/filter.d.ts +1 -1
- package/dist/operators/first.d.ts +1 -1
- package/dist/operators/flatten.d.ts +1 -1
- package/dist/operators/index.d.ts +16 -16
- package/dist/operators/joinStrings.d.ts +1 -1
- package/dist/operators/last.d.ts +1 -1
- package/dist/operators/map.d.ts +1 -1
- package/dist/operators/skip.d.ts +1 -1
- package/dist/operators/take.d.ts +1 -1
- package/dist/operators/tap.d.ts +1 -1
- package/dist/operators/unique.d.ts +1 -1
- package/dist/pipe.d.ts +1 -1
- package/dist/reduce.d.ts +1 -1
- package/dist/sync/index.d.ts +5 -5
- package/package.json +58 -24
- package/dist/helpers/index.js +0 -17
- package/dist/helpers/iteratorToIterable.js +0 -18
- package/dist/helpers/toArray.js +0 -21
- package/dist/helpers/toAsyncIterable.js +0 -19
- package/dist/helpers/util.js +0 -15
- package/dist/index.js +0 -58
- package/dist/internalTypes.js +0 -3
- package/dist/operators/index.js +0 -60
- package/dist/operators/joinStrings.js +0 -28
- package/dist/operators/types.js +0 -3
- package/dist/pipe.js +0 -15
- package/dist/reduce.js +0 -26
- package/dist/sync/index.js +0 -26
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Allows an iterable to be shared by multiple consumers.
|
|
3
|
+
* Each consumer takes from the iterable.
|
|
4
|
+
* @param iterable - the iterable to share
|
|
5
|
+
*/
|
|
6
|
+
export declare function toDistributableIterableSync<T>(iterable: Iterable<T>): Iterable<T>;
|
|
7
|
+
/**
|
|
8
|
+
* Allows an iterable to be shared by multiple consumers.
|
|
9
|
+
* Each consumer takes from the iterable.
|
|
10
|
+
* @param iterable - the iterable to share
|
|
11
|
+
*/
|
|
12
|
+
export declare const toDistributableIterable: typeof toDistributableIterableSync;
|
|
13
|
+
//# sourceMappingURL=distribute.d.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { toDistributableIterable } from './distribute.js';
|
|
2
|
+
export { interleave } from './interleave.js';
|
|
3
|
+
export { asyncIteratorToAsyncIterable, iteratorToIterable } from './iteratorToIterable.js';
|
|
4
|
+
export { toArray } from './toArray.js';
|
|
5
|
+
export { toAsyncIterable } from './toAsyncIterable.js';
|
|
6
|
+
export { isAsyncIterable } from './util.js';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function toArray<T>(i: AsyncIterable<T>): Promise<Awaited<T>[]>;
|
|
2
|
+
export declare function toArray<T>(i: Iterable<T>): T[];
|
|
3
|
+
export declare function toArray<T>(i: Iterable<T> | AsyncIterable<T>): T[] | Promise<Awaited<T>[]>;
|
|
4
|
+
export declare function toArraySync<T>(iter: Iterable<T>): T[];
|
|
5
|
+
export declare function toArrayAsync<T>(iter: AsyncIterable<T>): Promise<Awaited<T>[]>;
|
|
6
|
+
//# sourceMappingURL=toArray.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AnyIterable } from '../internalTypes.js';
|
|
2
|
+
export declare function mergeAsyncIterables<T>(iter: Iterable<T>): AsyncIterable<T>;
|
|
3
|
+
export declare function mergeAsyncIterables<T>(iter: AsyncIterable<T>): AsyncIterable<T>;
|
|
4
|
+
export declare function mergeAsyncIterables<T>(iter: Promise<Iterable<T>>): AsyncIterable<T>;
|
|
5
|
+
export declare function mergeAsyncIterables<T>(iter: AnyIterable<T>): AsyncIterable<T>;
|
|
6
|
+
export declare function mergeAsyncIterables<T>(iter: AnyIterable<T>, ...rest: AnyIterable<T>[]): AsyncIterable<T>;
|
|
7
|
+
/**
|
|
8
|
+
* Convert one or more iterables to an AsyncIterable
|
|
9
|
+
*/
|
|
10
|
+
export declare const toAsyncIterable: typeof mergeAsyncIterables;
|
|
11
|
+
//# sourceMappingURL=toAsyncIterable.d.ts.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { AnyIterable, PipeFn, PipeFnAsync, PipeFnSync } from '../internalTypes.js';
|
|
2
|
+
export declare function toPipeFn<T, U = T>(syncFn: PipeFnSync<T, U>, asyncFn: PipeFnAsync<T, U>): PipeFn<T, U>;
|
|
3
|
+
export declare function isAsyncIterable<T>(i: AnyIterable<T>): i is AsyncIterable<T>;
|
|
4
|
+
//# sourceMappingURL=util.d.ts.map
|
|
@@ -0,0 +1,644 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Allows an iterable to be shared by multiple consumers.
|
|
5
|
+
* Each consumer takes from the iterable.
|
|
6
|
+
* @param iterable - the iterable to share
|
|
7
|
+
*/
|
|
8
|
+
function toDistributableIterableSync(iterable) {
|
|
9
|
+
let lastValue;
|
|
10
|
+
let iter;
|
|
11
|
+
function getNext() {
|
|
12
|
+
if (lastValue && lastValue.done) {
|
|
13
|
+
return { ...lastValue };
|
|
14
|
+
}
|
|
15
|
+
iter = iter || iterable[Symbol.iterator]();
|
|
16
|
+
lastValue = iter.next();
|
|
17
|
+
return lastValue;
|
|
18
|
+
}
|
|
19
|
+
function* iterableFn() {
|
|
20
|
+
let next;
|
|
21
|
+
while (!(next = getNext()).done) {
|
|
22
|
+
yield next.value;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
[Symbol.iterator]: iterableFn,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Allows an iterable to be shared by multiple consumers.
|
|
31
|
+
* Each consumer takes from the iterable.
|
|
32
|
+
* @param iterable - the iterable to share
|
|
33
|
+
*/
|
|
34
|
+
const toDistributableIterable = toDistributableIterableSync;
|
|
35
|
+
|
|
36
|
+
function* interleave(a, b) {
|
|
37
|
+
const ai = a[Symbol.iterator]();
|
|
38
|
+
const bi = b[Symbol.iterator]();
|
|
39
|
+
for (let aNext = ai.next(); !aNext.done; aNext = ai.next()) {
|
|
40
|
+
yield aNext.value;
|
|
41
|
+
const bNext = bi.next();
|
|
42
|
+
if (bNext.done)
|
|
43
|
+
break;
|
|
44
|
+
yield bNext.value;
|
|
45
|
+
}
|
|
46
|
+
for (let aNext = ai.next(); !aNext.done; aNext = ai.next()) {
|
|
47
|
+
yield aNext.value;
|
|
48
|
+
}
|
|
49
|
+
for (let bNext = bi.next(); !bNext.done; bNext = bi.next()) {
|
|
50
|
+
yield bNext.value;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function* iteratorToIterable(iterator) {
|
|
55
|
+
let n;
|
|
56
|
+
while (!(n = iterator.next()).done) {
|
|
57
|
+
yield n.value;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
async function* asyncIteratorToAsyncIterable(iterator) {
|
|
61
|
+
let n;
|
|
62
|
+
while (!(n = await iterator.next()).done) {
|
|
63
|
+
yield n.value;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function toPipeFn(syncFn, asyncFn) {
|
|
68
|
+
function _(i) {
|
|
69
|
+
return isAsyncIterable(i) ? asyncFn(i) : syncFn(i);
|
|
70
|
+
}
|
|
71
|
+
return _;
|
|
72
|
+
}
|
|
73
|
+
function isAsyncIterable(i) {
|
|
74
|
+
return typeof i[Symbol.asyncIterator] === 'function';
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function toArray(i) {
|
|
78
|
+
return isAsyncIterable(i) ? toArrayAsync(i) : toArraySync(i);
|
|
79
|
+
}
|
|
80
|
+
function toArraySync(iter) {
|
|
81
|
+
return [...iter];
|
|
82
|
+
}
|
|
83
|
+
async function toArrayAsync(iter) {
|
|
84
|
+
const collection = [];
|
|
85
|
+
for await (const i of iter) {
|
|
86
|
+
collection.push(i);
|
|
87
|
+
}
|
|
88
|
+
return collection;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Merge multiple iterables into an AsyncIterable
|
|
93
|
+
* @param iter - initial iterable.
|
|
94
|
+
* @param rest - iterables to merge.
|
|
95
|
+
*/
|
|
96
|
+
async function* mergeAsyncIterables(iter, ...rest) {
|
|
97
|
+
for await (const i of [iter, ...rest]) {
|
|
98
|
+
yield* i;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Convert one or more iterables to an AsyncIterable
|
|
103
|
+
*/
|
|
104
|
+
const toAsyncIterable = mergeAsyncIterables;
|
|
105
|
+
|
|
106
|
+
var _helpers = /*#__PURE__*/Object.freeze({
|
|
107
|
+
__proto__: null,
|
|
108
|
+
asyncIteratorToAsyncIterable: asyncIteratorToAsyncIterable,
|
|
109
|
+
interleave: interleave,
|
|
110
|
+
isAsyncIterable: isAsyncIterable,
|
|
111
|
+
iteratorToIterable: iteratorToIterable,
|
|
112
|
+
toArray: toArray,
|
|
113
|
+
toAsyncIterable: toAsyncIterable,
|
|
114
|
+
toDistributableIterable: toDistributableIterable
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Append values onto the end of an iterable.
|
|
119
|
+
* @param iterablesToAppend - the iterables in the order to be appended.
|
|
120
|
+
* @returns
|
|
121
|
+
*/
|
|
122
|
+
function opAppendAsync(...iterablesToAppend) {
|
|
123
|
+
async function* fn(iter) {
|
|
124
|
+
yield* iter;
|
|
125
|
+
for (const i of iterablesToAppend) {
|
|
126
|
+
yield* i;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return fn;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Append values onto the end of an iterable.
|
|
133
|
+
* @param iterablesToAppend - the iterables in the order to be appended.
|
|
134
|
+
* @returns
|
|
135
|
+
*/
|
|
136
|
+
function opAppendSync(...iterablesToAppend) {
|
|
137
|
+
function* fn(iter) {
|
|
138
|
+
yield* iter;
|
|
139
|
+
for (const i of iterablesToAppend) {
|
|
140
|
+
yield* i;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return fn;
|
|
144
|
+
}
|
|
145
|
+
function opAppend(...iterablesToAppend) {
|
|
146
|
+
function _(i) {
|
|
147
|
+
return isAsyncIterable(i) ? opAppendAsync(...iterablesToAppend)(i) : opAppendSync(...iterablesToAppend)(i);
|
|
148
|
+
}
|
|
149
|
+
return _;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
async function* _asyncAwait(iter) {
|
|
153
|
+
for await (const v of iter) {
|
|
154
|
+
yield v;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
function opAwaitAsync() {
|
|
158
|
+
return _asyncAwait;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function opCombineAsync(...fns) {
|
|
162
|
+
function combine(iter) {
|
|
163
|
+
for (const fn of fns) {
|
|
164
|
+
iter = fn(iter);
|
|
165
|
+
}
|
|
166
|
+
return iter;
|
|
167
|
+
}
|
|
168
|
+
return combine;
|
|
169
|
+
}
|
|
170
|
+
function opCombineSync(...fns) {
|
|
171
|
+
function combine(iter) {
|
|
172
|
+
for (const fn of fns) {
|
|
173
|
+
iter = fn(iter);
|
|
174
|
+
}
|
|
175
|
+
return iter;
|
|
176
|
+
}
|
|
177
|
+
return combine;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function opConcatMapAsync(mapFn) {
|
|
181
|
+
async function* fn(iter) {
|
|
182
|
+
for await (const v of iter) {
|
|
183
|
+
yield* mapFn(v);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return fn;
|
|
187
|
+
}
|
|
188
|
+
function opConcatMapSync(mapFn) {
|
|
189
|
+
function* fn(iter) {
|
|
190
|
+
for (const v of iter) {
|
|
191
|
+
yield* mapFn(v);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return fn;
|
|
195
|
+
}
|
|
196
|
+
const opConcatMap = (fn) => toPipeFn(opConcatMapSync(fn), opConcatMapAsync(fn));
|
|
197
|
+
|
|
198
|
+
// prettier-ignore
|
|
199
|
+
function opFilterAsync(filterFn) {
|
|
200
|
+
async function* fn(iter) {
|
|
201
|
+
for await (const v of iter) {
|
|
202
|
+
const pass = await filterFn(v);
|
|
203
|
+
if (pass)
|
|
204
|
+
yield v;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return fn;
|
|
208
|
+
}
|
|
209
|
+
function opFilterSync(filterFn) {
|
|
210
|
+
function* fn(iter) {
|
|
211
|
+
for (const v of iter) {
|
|
212
|
+
if (filterFn(v))
|
|
213
|
+
yield v;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return fn;
|
|
217
|
+
}
|
|
218
|
+
function opFilter(fn) {
|
|
219
|
+
const asyncFn = opFilterAsync(fn);
|
|
220
|
+
const syncFn = opFilterSync(fn);
|
|
221
|
+
function _(i) {
|
|
222
|
+
return isAsyncIterable(i) ? asyncFn(i) : syncFn(i);
|
|
223
|
+
}
|
|
224
|
+
return _;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// prettier-ignore
|
|
228
|
+
function opFirstAsync(firstFn) {
|
|
229
|
+
async function* fn(iter) {
|
|
230
|
+
for await (const v of iter) {
|
|
231
|
+
const pass = await firstFn(v);
|
|
232
|
+
if (pass) {
|
|
233
|
+
yield v;
|
|
234
|
+
break;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return fn;
|
|
239
|
+
}
|
|
240
|
+
function opFirstSync(firstFn) {
|
|
241
|
+
function* fn(iter) {
|
|
242
|
+
for (const v of iter) {
|
|
243
|
+
if (firstFn(v)) {
|
|
244
|
+
yield v;
|
|
245
|
+
break;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return fn;
|
|
250
|
+
}
|
|
251
|
+
function opFirst(fn) {
|
|
252
|
+
const asyncFn = opFirstAsync(fn);
|
|
253
|
+
const syncFn = opFirstSync(fn);
|
|
254
|
+
function _(i) {
|
|
255
|
+
return isAsyncIterable(i) ? asyncFn(i) : syncFn(i);
|
|
256
|
+
}
|
|
257
|
+
return _;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function opFlattenAsync() {
|
|
261
|
+
async function* fn(iter) {
|
|
262
|
+
for await (const v of iter) {
|
|
263
|
+
yield* v;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return fn;
|
|
267
|
+
}
|
|
268
|
+
function opFlattenSync() {
|
|
269
|
+
function* fn(iter) {
|
|
270
|
+
for (const v of iter) {
|
|
271
|
+
yield* v;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
return fn;
|
|
275
|
+
}
|
|
276
|
+
const opFlatten = () => toPipeFn(opFlattenSync(), opFlattenAsync());
|
|
277
|
+
|
|
278
|
+
function opJoinStringsAsync(joinCharacter = ',') {
|
|
279
|
+
async function* fn(iter) {
|
|
280
|
+
for await (const v of iter) {
|
|
281
|
+
const a = await toArray(v);
|
|
282
|
+
yield a.join(joinCharacter);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
return fn;
|
|
286
|
+
}
|
|
287
|
+
function opJoinStringsSync(joinCharacter = ',') {
|
|
288
|
+
function* fn(iter) {
|
|
289
|
+
for (const v of iter) {
|
|
290
|
+
const a = toArray(v);
|
|
291
|
+
yield a.join(joinCharacter);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
return fn;
|
|
295
|
+
}
|
|
296
|
+
const opJoinStrings = (joinCharacter) => toPipeFn(opJoinStringsSync(joinCharacter), opJoinStringsAsync(joinCharacter));
|
|
297
|
+
|
|
298
|
+
const symNotFound = Symbol('LastNotFound');
|
|
299
|
+
// prettier-ignore
|
|
300
|
+
function opLastAsync(lastFn) {
|
|
301
|
+
async function* fn(iter) {
|
|
302
|
+
let last = symNotFound;
|
|
303
|
+
for await (const v of iter) {
|
|
304
|
+
const pass = await lastFn(v);
|
|
305
|
+
if (pass) {
|
|
306
|
+
last = v;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
if (last !== symNotFound)
|
|
310
|
+
yield last;
|
|
311
|
+
}
|
|
312
|
+
return fn;
|
|
313
|
+
}
|
|
314
|
+
function opLastSync(lastFn) {
|
|
315
|
+
function* fn(iter) {
|
|
316
|
+
let last = symNotFound;
|
|
317
|
+
for (const v of iter) {
|
|
318
|
+
if (lastFn(v)) {
|
|
319
|
+
last = v;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
if (last !== symNotFound)
|
|
323
|
+
yield last;
|
|
324
|
+
}
|
|
325
|
+
return fn;
|
|
326
|
+
}
|
|
327
|
+
function opLast(fn) {
|
|
328
|
+
const asyncFn = opLastAsync(fn);
|
|
329
|
+
const syncFn = opLastSync(fn);
|
|
330
|
+
function _(i) {
|
|
331
|
+
return isAsyncIterable(i) ? asyncFn(i) : syncFn(i);
|
|
332
|
+
}
|
|
333
|
+
return _;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
function opMapAsync(mapFn) {
|
|
337
|
+
async function* fn(iter) {
|
|
338
|
+
for await (const v of iter) {
|
|
339
|
+
yield mapFn(v);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
return fn;
|
|
343
|
+
}
|
|
344
|
+
function opMapSync(mapFn) {
|
|
345
|
+
function* fn(iter) {
|
|
346
|
+
for (const v of iter) {
|
|
347
|
+
yield mapFn(v);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
return fn;
|
|
351
|
+
}
|
|
352
|
+
const opMap = (fn) => toPipeFn(opMapSync(fn), opMapAsync(fn));
|
|
353
|
+
|
|
354
|
+
function opReduceAsync(reduceFn, initialValue) {
|
|
355
|
+
async function* reduce(head, tail) {
|
|
356
|
+
for await (const v of tail) {
|
|
357
|
+
head = reduceFn(head, v);
|
|
358
|
+
}
|
|
359
|
+
yield head;
|
|
360
|
+
}
|
|
361
|
+
async function* fn(iter) {
|
|
362
|
+
const ht = initialValue === undefined ? await headTailAsync(iter) : { head: await initialValue, tail: iter };
|
|
363
|
+
if (!ht)
|
|
364
|
+
return;
|
|
365
|
+
yield* reduce(ht.head, ht.tail);
|
|
366
|
+
}
|
|
367
|
+
return fn;
|
|
368
|
+
}
|
|
369
|
+
function opReduceSync(reduceFn, initialValue) {
|
|
370
|
+
function* reduce(head, tail) {
|
|
371
|
+
for (const v of tail) {
|
|
372
|
+
head = reduceFn(head, v);
|
|
373
|
+
}
|
|
374
|
+
yield head;
|
|
375
|
+
}
|
|
376
|
+
function* fn(iter) {
|
|
377
|
+
const ht = initialValue === undefined ? headTail(iter) : { head: initialValue, tail: iter };
|
|
378
|
+
if (!ht)
|
|
379
|
+
return;
|
|
380
|
+
yield* reduce(ht.head, ht.tail);
|
|
381
|
+
}
|
|
382
|
+
return fn;
|
|
383
|
+
}
|
|
384
|
+
function headTail(iter) {
|
|
385
|
+
const iterator = iter[Symbol.iterator]();
|
|
386
|
+
const first = iterator.next();
|
|
387
|
+
if (first.done)
|
|
388
|
+
return undefined;
|
|
389
|
+
return { head: first.value, tail: iteratorToIterable(iterator) };
|
|
390
|
+
}
|
|
391
|
+
async function headTailAsync(iter) {
|
|
392
|
+
const iterator = isIterable(iter) ? iter[Symbol.iterator]() : iter[Symbol.asyncIterator]();
|
|
393
|
+
const first = await iterator.next();
|
|
394
|
+
if (first.done)
|
|
395
|
+
return undefined;
|
|
396
|
+
return { head: first.value, tail: asyncIteratorToAsyncIterable(iterator) };
|
|
397
|
+
}
|
|
398
|
+
function isIterable(i) {
|
|
399
|
+
return typeof i[Symbol.iterator] === 'function';
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
function opSkipAsync(count) {
|
|
403
|
+
async function* fn(iter) {
|
|
404
|
+
for await (const v of iter) {
|
|
405
|
+
if (count > 0) {
|
|
406
|
+
--count;
|
|
407
|
+
continue;
|
|
408
|
+
}
|
|
409
|
+
yield v;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
return fn;
|
|
413
|
+
}
|
|
414
|
+
function opSkipSync(count) {
|
|
415
|
+
function* fn(iter) {
|
|
416
|
+
for (const v of iter) {
|
|
417
|
+
if (count > 0) {
|
|
418
|
+
--count;
|
|
419
|
+
continue;
|
|
420
|
+
}
|
|
421
|
+
yield v;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
return fn;
|
|
425
|
+
}
|
|
426
|
+
const opSkip = (count) => toPipeFn(opSkipSync(count), opSkipAsync(count));
|
|
427
|
+
|
|
428
|
+
function opTakeAsync(count) {
|
|
429
|
+
async function* fn(iter) {
|
|
430
|
+
if (count <= 0)
|
|
431
|
+
return;
|
|
432
|
+
for await (const v of iter) {
|
|
433
|
+
yield v;
|
|
434
|
+
if (--count <= 0)
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
return fn;
|
|
439
|
+
}
|
|
440
|
+
function opTakeSync(count) {
|
|
441
|
+
function* fn(iter) {
|
|
442
|
+
if (count <= 0)
|
|
443
|
+
return;
|
|
444
|
+
for (const v of iter) {
|
|
445
|
+
yield v;
|
|
446
|
+
if (--count <= 0)
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
return fn;
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* Consume only the first `count` number from the iterable.
|
|
454
|
+
* @param count - number to take
|
|
455
|
+
*/
|
|
456
|
+
const opTake = (count) => toPipeFn(opTakeSync(count), opTakeAsync(count));
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* Tap allows you to listen on values, without modifying them.
|
|
460
|
+
*
|
|
461
|
+
* @param fn - function to call for each value.
|
|
462
|
+
*/
|
|
463
|
+
function opTapAsync(tapFn) {
|
|
464
|
+
async function* fn(iter) {
|
|
465
|
+
for await (const v of iter) {
|
|
466
|
+
tapFn(v);
|
|
467
|
+
yield v;
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
return fn;
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* Tap allows you to listen on values, without modifying them.
|
|
474
|
+
*
|
|
475
|
+
* @param fn - function to call for each value.
|
|
476
|
+
*/
|
|
477
|
+
function opTapSync(tapFn) {
|
|
478
|
+
function* fn(iter) {
|
|
479
|
+
for (const v of iter) {
|
|
480
|
+
tapFn(v);
|
|
481
|
+
yield v;
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
return fn;
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Tap allows you to listen on values, without modifying them.
|
|
488
|
+
*
|
|
489
|
+
* @param fn - function to call for each value.
|
|
490
|
+
*/
|
|
491
|
+
const opTap = (fn) => toPipeFn(opTapSync(fn), opTapAsync(fn));
|
|
492
|
+
|
|
493
|
+
function opUniqueAsync(k) {
|
|
494
|
+
function fnK(k) {
|
|
495
|
+
async function* fn(iter) {
|
|
496
|
+
const s = new Set();
|
|
497
|
+
for await (const v of iter) {
|
|
498
|
+
const kk = k(v);
|
|
499
|
+
if (s.has(kk))
|
|
500
|
+
continue;
|
|
501
|
+
s.add(kk);
|
|
502
|
+
yield v;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
return fn;
|
|
506
|
+
}
|
|
507
|
+
async function* fn(iter) {
|
|
508
|
+
const s = new Set();
|
|
509
|
+
for await (const v of iter) {
|
|
510
|
+
if (s.has(v))
|
|
511
|
+
continue;
|
|
512
|
+
s.add(v);
|
|
513
|
+
yield v;
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
return k ? fnK(k) : fn;
|
|
517
|
+
}
|
|
518
|
+
function opUniqueSync(k) {
|
|
519
|
+
function fnK(key) {
|
|
520
|
+
function* fn(iter) {
|
|
521
|
+
const s = new Set();
|
|
522
|
+
for (const v of iter) {
|
|
523
|
+
const kk = key(v);
|
|
524
|
+
if (s.has(kk))
|
|
525
|
+
continue;
|
|
526
|
+
s.add(kk);
|
|
527
|
+
yield v;
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
return fn;
|
|
531
|
+
}
|
|
532
|
+
function* fn(iter) {
|
|
533
|
+
const s = new Set();
|
|
534
|
+
for (const v of iter) {
|
|
535
|
+
if (s.has(v))
|
|
536
|
+
continue;
|
|
537
|
+
s.add(v);
|
|
538
|
+
yield v;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
return k ? fnK(k) : fn;
|
|
542
|
+
}
|
|
543
|
+
const opUnique = (getKey) => toPipeFn(opUniqueSync(getKey), opUniqueAsync(getKey));
|
|
544
|
+
|
|
545
|
+
var _operators = /*#__PURE__*/Object.freeze({
|
|
546
|
+
__proto__: null,
|
|
547
|
+
opAppend: opAppend,
|
|
548
|
+
opAppendAsync: opAppendAsync,
|
|
549
|
+
opAppendSync: opAppendSync,
|
|
550
|
+
opAwaitAsync: opAwaitAsync,
|
|
551
|
+
opCombineAsync: opCombineAsync,
|
|
552
|
+
opCombineSync: opCombineSync,
|
|
553
|
+
opConcatMap: opConcatMap,
|
|
554
|
+
opConcatMapAsync: opConcatMapAsync,
|
|
555
|
+
opConcatMapSync: opConcatMapSync,
|
|
556
|
+
opFilter: opFilter,
|
|
557
|
+
opFilterAsync: opFilterAsync,
|
|
558
|
+
opFilterSync: opFilterSync,
|
|
559
|
+
opFirst: opFirst,
|
|
560
|
+
opFirstAsync: opFirstAsync,
|
|
561
|
+
opFirstSync: opFirstSync,
|
|
562
|
+
opFlatten: opFlatten,
|
|
563
|
+
opFlattenAsync: opFlattenAsync,
|
|
564
|
+
opFlattenSync: opFlattenSync,
|
|
565
|
+
opJoinStrings: opJoinStrings,
|
|
566
|
+
opJoinStringsAsync: opJoinStringsAsync,
|
|
567
|
+
opJoinStringsSync: opJoinStringsSync,
|
|
568
|
+
opLast: opLast,
|
|
569
|
+
opLastAsync: opLastAsync,
|
|
570
|
+
opLastSync: opLastSync,
|
|
571
|
+
opMap: opMap,
|
|
572
|
+
opMapAsync: opMapAsync,
|
|
573
|
+
opMapSync: opMapSync,
|
|
574
|
+
opReduceAsync: opReduceAsync,
|
|
575
|
+
opReduceSync: opReduceSync,
|
|
576
|
+
opSkip: opSkip,
|
|
577
|
+
opSkipAsync: opSkipAsync,
|
|
578
|
+
opSkipSync: opSkipSync,
|
|
579
|
+
opTake: opTake,
|
|
580
|
+
opTakeAsync: opTakeAsync,
|
|
581
|
+
opTakeSync: opTakeSync,
|
|
582
|
+
opTap: opTap,
|
|
583
|
+
opTapAsync: opTapAsync,
|
|
584
|
+
opTapSync: opTapSync,
|
|
585
|
+
opUnique: opUnique,
|
|
586
|
+
opUniqueAsync: opUniqueAsync,
|
|
587
|
+
opUniqueSync: opUniqueSync
|
|
588
|
+
});
|
|
589
|
+
|
|
590
|
+
function pipeAsync(i, ...fns) {
|
|
591
|
+
const iter = toAsyncIterable(i);
|
|
592
|
+
return opCombineAsync(...fns)(iter);
|
|
593
|
+
}
|
|
594
|
+
function pipeSync(i, ...fns) {
|
|
595
|
+
return opCombineSync(...fns)(i);
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
function reduceSync(iter, reduceFn, initialValue) {
|
|
599
|
+
const i = initialValue === undefined
|
|
600
|
+
? pipeSync(iter, opReduceSync(reduceFn))
|
|
601
|
+
: pipeSync(iter, opReduceSync(reduceFn, initialValue));
|
|
602
|
+
return [...i][0];
|
|
603
|
+
}
|
|
604
|
+
async function reduceAsync(iter, reduceFn, initialValue) {
|
|
605
|
+
const i = initialValue === undefined
|
|
606
|
+
? pipeAsync(iter, opReduceAsync(reduceFn))
|
|
607
|
+
: pipeAsync(iter, opReduceAsync(reduceFn, initialValue));
|
|
608
|
+
const arr = await toArrayAsync(i);
|
|
609
|
+
return arr[0];
|
|
610
|
+
}
|
|
611
|
+
function reduce(iter, reduceFn, initialValue) {
|
|
612
|
+
return isAsyncIterable(iter) ? reduceAsync(iter, reduceFn, initialValue) : reduceSync(iter, reduceFn, initialValue);
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
// eslint-disable-next-line unicorn/prefer-export-from
|
|
616
|
+
const operators = _operators;
|
|
617
|
+
// eslint-disable-next-line unicorn/prefer-export-from
|
|
618
|
+
const helpers = _helpers;
|
|
619
|
+
|
|
620
|
+
exports.helpers = helpers;
|
|
621
|
+
exports.interleave = interleave;
|
|
622
|
+
exports.isAsyncIterable = isAsyncIterable;
|
|
623
|
+
exports.opAppend = opAppend;
|
|
624
|
+
exports.opAwaitAsync = opAwaitAsync;
|
|
625
|
+
exports.opConcatMap = opConcatMap;
|
|
626
|
+
exports.opFilter = opFilter;
|
|
627
|
+
exports.opFirst = opFirst;
|
|
628
|
+
exports.opFlatten = opFlatten;
|
|
629
|
+
exports.opJoinStrings = opJoinStrings;
|
|
630
|
+
exports.opLast = opLast;
|
|
631
|
+
exports.opMap = opMap;
|
|
632
|
+
exports.opSkip = opSkip;
|
|
633
|
+
exports.opTake = opTake;
|
|
634
|
+
exports.opTap = opTap;
|
|
635
|
+
exports.opUnique = opUnique;
|
|
636
|
+
exports.operators = operators;
|
|
637
|
+
exports.pipeAsync = pipeAsync;
|
|
638
|
+
exports.pipeSync = pipeSync;
|
|
639
|
+
exports.reduce = reduce;
|
|
640
|
+
exports.reduceAsync = reduceAsync;
|
|
641
|
+
exports.reduceSync = reduceSync;
|
|
642
|
+
exports.toArray = toArray;
|
|
643
|
+
exports.toAsyncIterable = toAsyncIterable;
|
|
644
|
+
exports.toDistributableIterable = toDistributableIterable;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as _helpers from './helpers/index.js';
|
|
2
|
+
import * as _operators from './operators/index.js';
|
|
3
|
+
export { interleave, isAsyncIterable, toArray, toAsyncIterable, toDistributableIterable } from './helpers/index.js';
|
|
4
|
+
export { opAppend, opAwaitAsync, opConcatMap, opFilter, opFirst, opFlatten, opJoinStrings, opLast, opMap, opSkip, opTake, opTap, opUnique, } from './operators/index.js';
|
|
5
|
+
export { pipeAsync, pipeSync } from './pipe.js';
|
|
6
|
+
export { reduce, reduceAsync, reduceSync } from './reduce.js';
|
|
7
|
+
export declare const operators: typeof _operators;
|
|
8
|
+
export declare const helpers: typeof _helpers;
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|