@cspell/cspell-pipe 6.18.0 → 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.
Files changed (196) hide show
  1. package/dist/cjs/helpers/distribute.d.ts +13 -0
  2. package/dist/cjs/helpers/index.d.ts +7 -0
  3. package/dist/cjs/helpers/interleave.d.ts +2 -0
  4. package/dist/cjs/helpers/iteratorToIterable.d.ts +3 -0
  5. package/dist/cjs/helpers/toArray.d.ts +6 -0
  6. package/dist/cjs/helpers/toAsyncIterable.d.ts +11 -0
  7. package/dist/cjs/helpers/util.d.ts +4 -0
  8. package/dist/cjs/index.cjs +644 -0
  9. package/dist/cjs/index.d.ts +9 -0
  10. package/dist/cjs/internalTypes.d.ts +17 -0
  11. package/dist/{operators/append.js → cjs/operators/append.cjs} +10 -8
  12. package/dist/cjs/operators/append.d.ts +15 -0
  13. package/dist/{operators/await.js → cjs/operators/await.cjs} +3 -4
  14. package/dist/cjs/operators/await.d.ts +2 -0
  15. package/dist/{operators/combine.js → cjs/operators/combine.cjs} +4 -5
  16. package/dist/cjs/operators/combine.d.ts +23 -0
  17. package/dist/{operators/concatMap.js → cjs/operators/concatMap.cjs} +16 -8
  18. package/dist/cjs/operators/concatMap.d.ts +4 -0
  19. package/dist/{operators/filter.js → cjs/operators/filter.cjs} +10 -8
  20. package/dist/cjs/operators/filter.d.ts +10 -0
  21. package/dist/{operators/first.js → cjs/operators/first.cjs} +10 -8
  22. package/dist/cjs/operators/first.d.ts +10 -0
  23. package/dist/{operators/flatten.js → cjs/operators/flatten.cjs} +16 -8
  24. package/dist/cjs/operators/flatten.d.ts +4 -0
  25. package/dist/cjs/operators/helpers/distribute.d.ts +13 -0
  26. package/dist/cjs/operators/helpers/index.d.ts +7 -0
  27. package/dist/cjs/operators/helpers/interleave.d.ts +2 -0
  28. package/dist/cjs/operators/helpers/iteratorToIterable.d.ts +3 -0
  29. package/dist/cjs/operators/helpers/toArray.d.ts +6 -0
  30. package/dist/cjs/operators/helpers/toAsyncIterable.d.ts +11 -0
  31. package/dist/cjs/operators/helpers/util.d.ts +4 -0
  32. package/dist/cjs/operators/index.cjs +508 -0
  33. package/dist/cjs/operators/index.d.ts +17 -0
  34. package/dist/cjs/operators/internalTypes.d.ts +17 -0
  35. package/dist/cjs/operators/joinStrings.cjs +49 -0
  36. package/dist/cjs/operators/joinStrings.d.ts +4 -0
  37. package/dist/{operators/last.js → cjs/operators/last.cjs} +10 -8
  38. package/dist/cjs/operators/last.d.ts +10 -0
  39. package/dist/{operators/map.js → cjs/operators/map.cjs} +16 -8
  40. package/dist/cjs/operators/map.d.ts +4 -0
  41. package/dist/cjs/operators/operators/append.d.ts +15 -0
  42. package/dist/cjs/operators/operators/await.d.ts +2 -0
  43. package/dist/cjs/operators/operators/combine.d.ts +23 -0
  44. package/dist/cjs/operators/operators/concatMap.d.ts +4 -0
  45. package/dist/cjs/operators/operators/filter.d.ts +10 -0
  46. package/dist/cjs/operators/operators/first.d.ts +10 -0
  47. package/dist/cjs/operators/operators/flatten.d.ts +4 -0
  48. package/dist/cjs/operators/operators/index.d.ts +17 -0
  49. package/dist/cjs/operators/operators/joinStrings.d.ts +4 -0
  50. package/dist/cjs/operators/operators/last.d.ts +10 -0
  51. package/dist/cjs/operators/operators/map.d.ts +4 -0
  52. package/dist/cjs/operators/operators/reduce.d.ts +7 -0
  53. package/dist/cjs/operators/operators/skip.d.ts +4 -0
  54. package/dist/cjs/operators/operators/take.d.ts +8 -0
  55. package/dist/cjs/operators/operators/tap.d.ts +19 -0
  56. package/dist/cjs/operators/operators/types.d.ts +4 -0
  57. package/dist/cjs/operators/operators/unique.d.ts +4 -0
  58. package/dist/cjs/operators/pipe.d.ts +20 -0
  59. package/dist/{operators/reduce.js → cjs/operators/reduce.cjs} +22 -11
  60. package/dist/cjs/operators/reduce.d.ts +7 -0
  61. package/dist/{operators/skip.js → cjs/operators/skip.cjs} +16 -8
  62. package/dist/cjs/operators/skip.d.ts +4 -0
  63. package/dist/cjs/operators/sync/index.d.ts +6 -0
  64. package/dist/{operators/take.js → cjs/operators/take.cjs} +16 -8
  65. package/dist/cjs/operators/take.d.ts +8 -0
  66. package/dist/{operators/tap.js → cjs/operators/tap.cjs} +16 -8
  67. package/dist/cjs/operators/tap.d.ts +19 -0
  68. package/dist/cjs/operators/types.cjs +2 -0
  69. package/dist/cjs/operators/types.d.ts +4 -0
  70. package/dist/{operators/unique.js → cjs/operators/unique.cjs} +16 -8
  71. package/dist/cjs/operators/unique.d.ts +4 -0
  72. package/dist/cjs/pipe.d.ts +20 -0
  73. package/dist/cjs/reduce.d.ts +16 -0
  74. package/dist/cjs/sync/helpers/distribute.d.ts +13 -0
  75. package/dist/cjs/sync/helpers/index.d.ts +7 -0
  76. package/dist/cjs/sync/helpers/interleave.d.ts +2 -0
  77. package/dist/cjs/sync/helpers/iteratorToIterable.d.ts +3 -0
  78. package/dist/cjs/sync/helpers/toArray.d.ts +6 -0
  79. package/dist/cjs/sync/helpers/toAsyncIterable.d.ts +11 -0
  80. package/dist/cjs/sync/helpers/util.d.ts +4 -0
  81. package/dist/cjs/sync/index.cjs +245 -0
  82. package/dist/cjs/sync/index.d.ts +6 -0
  83. package/dist/cjs/sync/internalTypes.d.ts +17 -0
  84. package/dist/cjs/sync/operators/append.d.ts +15 -0
  85. package/dist/cjs/sync/operators/await.d.ts +2 -0
  86. package/dist/cjs/sync/operators/combine.d.ts +23 -0
  87. package/dist/cjs/sync/operators/concatMap.d.ts +4 -0
  88. package/dist/cjs/sync/operators/filter.d.ts +10 -0
  89. package/dist/cjs/sync/operators/first.d.ts +10 -0
  90. package/dist/cjs/sync/operators/flatten.d.ts +4 -0
  91. package/dist/cjs/sync/operators/index.d.ts +17 -0
  92. package/dist/cjs/sync/operators/joinStrings.d.ts +4 -0
  93. package/dist/cjs/sync/operators/last.d.ts +10 -0
  94. package/dist/cjs/sync/operators/map.d.ts +4 -0
  95. package/dist/cjs/sync/operators/reduce.d.ts +7 -0
  96. package/dist/cjs/sync/operators/skip.d.ts +4 -0
  97. package/dist/cjs/sync/operators/take.d.ts +8 -0
  98. package/dist/cjs/sync/operators/tap.d.ts +19 -0
  99. package/dist/cjs/sync/operators/types.d.ts +4 -0
  100. package/dist/cjs/sync/operators/unique.d.ts +4 -0
  101. package/dist/cjs/sync/pipe.d.ts +20 -0
  102. package/dist/cjs/sync/reduce.d.ts +16 -0
  103. package/dist/cjs/sync/sync/index.d.ts +6 -0
  104. package/dist/esm/helpers/distribute.d.ts +13 -0
  105. package/dist/{helpers → esm/helpers}/distribute.js +2 -6
  106. package/dist/esm/helpers/index.d.ts +7 -0
  107. package/dist/esm/helpers/index.js +7 -0
  108. package/dist/esm/helpers/interleave.d.ts +2 -0
  109. package/dist/{helpers → esm/helpers}/interleave.js +1 -5
  110. package/dist/esm/helpers/iteratorToIterable.d.ts +3 -0
  111. package/dist/esm/helpers/iteratorToIterable.js +13 -0
  112. package/dist/esm/helpers/toArray.d.ts +6 -0
  113. package/dist/esm/helpers/toArray.js +15 -0
  114. package/dist/esm/helpers/toAsyncIterable.d.ts +11 -0
  115. package/dist/esm/helpers/toAsyncIterable.js +15 -0
  116. package/dist/esm/helpers/util.d.ts +4 -0
  117. package/dist/esm/helpers/util.js +10 -0
  118. package/dist/esm/index.d.ts +9 -0
  119. package/dist/esm/index.js +11 -0
  120. package/dist/esm/internalTypes.d.ts +17 -0
  121. package/dist/esm/internalTypes.js +2 -0
  122. package/dist/esm/operators/append.d.ts +15 -0
  123. package/dist/esm/operators/append.js +36 -0
  124. package/dist/esm/operators/await.d.ts +2 -0
  125. package/dist/esm/operators/await.js +9 -0
  126. package/dist/esm/operators/combine.d.ts +23 -0
  127. package/dist/esm/operators/combine.js +19 -0
  128. package/dist/esm/operators/concatMap.d.ts +4 -0
  129. package/dist/esm/operators/concatMap.js +19 -0
  130. package/dist/esm/operators/filter.d.ts +10 -0
  131. package/dist/esm/operators/filter.js +30 -0
  132. package/dist/esm/operators/first.d.ts +10 -0
  133. package/dist/esm/operators/first.js +34 -0
  134. package/dist/esm/operators/flatten.d.ts +4 -0
  135. package/dist/esm/operators/flatten.js +19 -0
  136. package/dist/esm/operators/index.d.ts +17 -0
  137. package/dist/esm/operators/index.js +16 -0
  138. package/dist/esm/operators/joinStrings.d.ts +4 -0
  139. package/dist/esm/operators/joinStrings.js +22 -0
  140. package/dist/esm/operators/last.d.ts +10 -0
  141. package/dist/esm/operators/last.js +39 -0
  142. package/dist/esm/operators/map.d.ts +4 -0
  143. package/dist/esm/operators/map.js +19 -0
  144. package/dist/esm/operators/reduce.d.ts +7 -0
  145. package/dist/esm/operators/reduce.js +49 -0
  146. package/dist/esm/operators/skip.d.ts +4 -0
  147. package/dist/esm/operators/skip.js +27 -0
  148. package/dist/esm/operators/take.d.ts +8 -0
  149. package/dist/esm/operators/take.js +31 -0
  150. package/dist/esm/operators/tap.d.ts +19 -0
  151. package/dist/esm/operators/tap.js +36 -0
  152. package/dist/esm/operators/types.d.ts +4 -0
  153. package/dist/esm/operators/types.js +2 -0
  154. package/dist/esm/operators/unique.d.ts +4 -0
  155. package/dist/esm/operators/unique.js +53 -0
  156. package/dist/esm/pipe.d.ts +20 -0
  157. package/dist/esm/pipe.js +10 -0
  158. package/dist/esm/reduce.d.ts +16 -0
  159. package/dist/esm/reduce.js +21 -0
  160. package/dist/esm/sync/index.d.ts +6 -0
  161. package/dist/esm/sync/index.js +5 -0
  162. package/dist/helpers/index.d.ts +6 -6
  163. package/dist/helpers/toAsyncIterable.d.ts +1 -1
  164. package/dist/helpers/util.d.ts +1 -1
  165. package/dist/index.d.ts +6 -6
  166. package/dist/operators/append.d.ts +1 -1
  167. package/dist/operators/combine.d.ts +2 -2
  168. package/dist/operators/concatMap.d.ts +1 -1
  169. package/dist/operators/filter.d.ts +1 -1
  170. package/dist/operators/first.d.ts +1 -1
  171. package/dist/operators/flatten.d.ts +1 -1
  172. package/dist/operators/index.d.ts +16 -16
  173. package/dist/operators/joinStrings.d.ts +1 -1
  174. package/dist/operators/last.d.ts +1 -1
  175. package/dist/operators/map.d.ts +1 -1
  176. package/dist/operators/skip.d.ts +1 -1
  177. package/dist/operators/take.d.ts +1 -1
  178. package/dist/operators/tap.d.ts +1 -1
  179. package/dist/operators/unique.d.ts +1 -1
  180. package/dist/pipe.d.ts +1 -1
  181. package/dist/reduce.d.ts +1 -1
  182. package/dist/sync/index.d.ts +5 -5
  183. package/package.json +59 -25
  184. package/dist/helpers/index.js +0 -17
  185. package/dist/helpers/iteratorToIterable.js +0 -18
  186. package/dist/helpers/toArray.js +0 -21
  187. package/dist/helpers/toAsyncIterable.js +0 -19
  188. package/dist/helpers/util.js +0 -15
  189. package/dist/index.js +0 -58
  190. package/dist/internalTypes.js +0 -3
  191. package/dist/operators/index.js +0 -60
  192. package/dist/operators/joinStrings.js +0 -28
  193. package/dist/operators/types.js +0 -3
  194. package/dist/pipe.js +0 -15
  195. package/dist/reduce.js +0 -26
  196. package/dist/sync/index.js +0 -26
@@ -0,0 +1,508 @@
1
+ 'use strict';
2
+
3
+ function* iteratorToIterable(iterator) {
4
+ let n;
5
+ while (!(n = iterator.next()).done) {
6
+ yield n.value;
7
+ }
8
+ }
9
+ async function* asyncIteratorToAsyncIterable(iterator) {
10
+ let n;
11
+ while (!(n = await iterator.next()).done) {
12
+ yield n.value;
13
+ }
14
+ }
15
+
16
+ function toPipeFn(syncFn, asyncFn) {
17
+ function _(i) {
18
+ return isAsyncIterable(i) ? asyncFn(i) : syncFn(i);
19
+ }
20
+ return _;
21
+ }
22
+ function isAsyncIterable(i) {
23
+ return typeof i[Symbol.asyncIterator] === 'function';
24
+ }
25
+
26
+ function toArray(i) {
27
+ return isAsyncIterable(i) ? toArrayAsync(i) : toArraySync(i);
28
+ }
29
+ function toArraySync(iter) {
30
+ return [...iter];
31
+ }
32
+ async function toArrayAsync(iter) {
33
+ const collection = [];
34
+ for await (const i of iter) {
35
+ collection.push(i);
36
+ }
37
+ return collection;
38
+ }
39
+
40
+ /**
41
+ * Append values onto the end of an iterable.
42
+ * @param iterablesToAppend - the iterables in the order to be appended.
43
+ * @returns
44
+ */
45
+ function opAppendAsync(...iterablesToAppend) {
46
+ async function* fn(iter) {
47
+ yield* iter;
48
+ for (const i of iterablesToAppend) {
49
+ yield* i;
50
+ }
51
+ }
52
+ return fn;
53
+ }
54
+ /**
55
+ * Append values onto the end of an iterable.
56
+ * @param iterablesToAppend - the iterables in the order to be appended.
57
+ * @returns
58
+ */
59
+ function opAppendSync(...iterablesToAppend) {
60
+ function* fn(iter) {
61
+ yield* iter;
62
+ for (const i of iterablesToAppend) {
63
+ yield* i;
64
+ }
65
+ }
66
+ return fn;
67
+ }
68
+ function opAppend(...iterablesToAppend) {
69
+ function _(i) {
70
+ return isAsyncIterable(i) ? opAppendAsync(...iterablesToAppend)(i) : opAppendSync(...iterablesToAppend)(i);
71
+ }
72
+ return _;
73
+ }
74
+
75
+ async function* _asyncAwait(iter) {
76
+ for await (const v of iter) {
77
+ yield v;
78
+ }
79
+ }
80
+ function opAwaitAsync() {
81
+ return _asyncAwait;
82
+ }
83
+
84
+ function opCombineAsync(...fns) {
85
+ function combine(iter) {
86
+ for (const fn of fns) {
87
+ iter = fn(iter);
88
+ }
89
+ return iter;
90
+ }
91
+ return combine;
92
+ }
93
+ function opCombineSync(...fns) {
94
+ function combine(iter) {
95
+ for (const fn of fns) {
96
+ iter = fn(iter);
97
+ }
98
+ return iter;
99
+ }
100
+ return combine;
101
+ }
102
+
103
+ function opConcatMapAsync(mapFn) {
104
+ async function* fn(iter) {
105
+ for await (const v of iter) {
106
+ yield* mapFn(v);
107
+ }
108
+ }
109
+ return fn;
110
+ }
111
+ function opConcatMapSync(mapFn) {
112
+ function* fn(iter) {
113
+ for (const v of iter) {
114
+ yield* mapFn(v);
115
+ }
116
+ }
117
+ return fn;
118
+ }
119
+ const opConcatMap = (fn) => toPipeFn(opConcatMapSync(fn), opConcatMapAsync(fn));
120
+
121
+ // prettier-ignore
122
+ function opFilterAsync(filterFn) {
123
+ async function* fn(iter) {
124
+ for await (const v of iter) {
125
+ const pass = await filterFn(v);
126
+ if (pass)
127
+ yield v;
128
+ }
129
+ }
130
+ return fn;
131
+ }
132
+ function opFilterSync(filterFn) {
133
+ function* fn(iter) {
134
+ for (const v of iter) {
135
+ if (filterFn(v))
136
+ yield v;
137
+ }
138
+ }
139
+ return fn;
140
+ }
141
+ function opFilter(fn) {
142
+ const asyncFn = opFilterAsync(fn);
143
+ const syncFn = opFilterSync(fn);
144
+ function _(i) {
145
+ return isAsyncIterable(i) ? asyncFn(i) : syncFn(i);
146
+ }
147
+ return _;
148
+ }
149
+
150
+ // prettier-ignore
151
+ function opFirstAsync(firstFn) {
152
+ async function* fn(iter) {
153
+ for await (const v of iter) {
154
+ const pass = await firstFn(v);
155
+ if (pass) {
156
+ yield v;
157
+ break;
158
+ }
159
+ }
160
+ }
161
+ return fn;
162
+ }
163
+ function opFirstSync(firstFn) {
164
+ function* fn(iter) {
165
+ for (const v of iter) {
166
+ if (firstFn(v)) {
167
+ yield v;
168
+ break;
169
+ }
170
+ }
171
+ }
172
+ return fn;
173
+ }
174
+ function opFirst(fn) {
175
+ const asyncFn = opFirstAsync(fn);
176
+ const syncFn = opFirstSync(fn);
177
+ function _(i) {
178
+ return isAsyncIterable(i) ? asyncFn(i) : syncFn(i);
179
+ }
180
+ return _;
181
+ }
182
+
183
+ function opFlattenAsync() {
184
+ async function* fn(iter) {
185
+ for await (const v of iter) {
186
+ yield* v;
187
+ }
188
+ }
189
+ return fn;
190
+ }
191
+ function opFlattenSync() {
192
+ function* fn(iter) {
193
+ for (const v of iter) {
194
+ yield* v;
195
+ }
196
+ }
197
+ return fn;
198
+ }
199
+ const opFlatten = () => toPipeFn(opFlattenSync(), opFlattenAsync());
200
+
201
+ function opJoinStringsAsync(joinCharacter = ',') {
202
+ async function* fn(iter) {
203
+ for await (const v of iter) {
204
+ const a = await toArray(v);
205
+ yield a.join(joinCharacter);
206
+ }
207
+ }
208
+ return fn;
209
+ }
210
+ function opJoinStringsSync(joinCharacter = ',') {
211
+ function* fn(iter) {
212
+ for (const v of iter) {
213
+ const a = toArray(v);
214
+ yield a.join(joinCharacter);
215
+ }
216
+ }
217
+ return fn;
218
+ }
219
+ const opJoinStrings = (joinCharacter) => toPipeFn(opJoinStringsSync(joinCharacter), opJoinStringsAsync(joinCharacter));
220
+
221
+ const symNotFound = Symbol('LastNotFound');
222
+ // prettier-ignore
223
+ function opLastAsync(lastFn) {
224
+ async function* fn(iter) {
225
+ let last = symNotFound;
226
+ for await (const v of iter) {
227
+ const pass = await lastFn(v);
228
+ if (pass) {
229
+ last = v;
230
+ }
231
+ }
232
+ if (last !== symNotFound)
233
+ yield last;
234
+ }
235
+ return fn;
236
+ }
237
+ function opLastSync(lastFn) {
238
+ function* fn(iter) {
239
+ let last = symNotFound;
240
+ for (const v of iter) {
241
+ if (lastFn(v)) {
242
+ last = v;
243
+ }
244
+ }
245
+ if (last !== symNotFound)
246
+ yield last;
247
+ }
248
+ return fn;
249
+ }
250
+ function opLast(fn) {
251
+ const asyncFn = opLastAsync(fn);
252
+ const syncFn = opLastSync(fn);
253
+ function _(i) {
254
+ return isAsyncIterable(i) ? asyncFn(i) : syncFn(i);
255
+ }
256
+ return _;
257
+ }
258
+
259
+ function opMapAsync(mapFn) {
260
+ async function* fn(iter) {
261
+ for await (const v of iter) {
262
+ yield mapFn(v);
263
+ }
264
+ }
265
+ return fn;
266
+ }
267
+ function opMapSync(mapFn) {
268
+ function* fn(iter) {
269
+ for (const v of iter) {
270
+ yield mapFn(v);
271
+ }
272
+ }
273
+ return fn;
274
+ }
275
+ const opMap = (fn) => toPipeFn(opMapSync(fn), opMapAsync(fn));
276
+
277
+ function opReduceAsync(reduceFn, initialValue) {
278
+ async function* reduce(head, tail) {
279
+ for await (const v of tail) {
280
+ head = reduceFn(head, v);
281
+ }
282
+ yield head;
283
+ }
284
+ async function* fn(iter) {
285
+ const ht = initialValue === undefined ? await headTailAsync(iter) : { head: await initialValue, tail: iter };
286
+ if (!ht)
287
+ return;
288
+ yield* reduce(ht.head, ht.tail);
289
+ }
290
+ return fn;
291
+ }
292
+ function opReduceSync(reduceFn, initialValue) {
293
+ function* reduce(head, tail) {
294
+ for (const v of tail) {
295
+ head = reduceFn(head, v);
296
+ }
297
+ yield head;
298
+ }
299
+ function* fn(iter) {
300
+ const ht = initialValue === undefined ? headTail(iter) : { head: initialValue, tail: iter };
301
+ if (!ht)
302
+ return;
303
+ yield* reduce(ht.head, ht.tail);
304
+ }
305
+ return fn;
306
+ }
307
+ function headTail(iter) {
308
+ const iterator = iter[Symbol.iterator]();
309
+ const first = iterator.next();
310
+ if (first.done)
311
+ return undefined;
312
+ return { head: first.value, tail: iteratorToIterable(iterator) };
313
+ }
314
+ async function headTailAsync(iter) {
315
+ const iterator = isIterable(iter) ? iter[Symbol.iterator]() : iter[Symbol.asyncIterator]();
316
+ const first = await iterator.next();
317
+ if (first.done)
318
+ return undefined;
319
+ return { head: first.value, tail: asyncIteratorToAsyncIterable(iterator) };
320
+ }
321
+ function isIterable(i) {
322
+ return typeof i[Symbol.iterator] === 'function';
323
+ }
324
+
325
+ function opSkipAsync(count) {
326
+ async function* fn(iter) {
327
+ for await (const v of iter) {
328
+ if (count > 0) {
329
+ --count;
330
+ continue;
331
+ }
332
+ yield v;
333
+ }
334
+ }
335
+ return fn;
336
+ }
337
+ function opSkipSync(count) {
338
+ function* fn(iter) {
339
+ for (const v of iter) {
340
+ if (count > 0) {
341
+ --count;
342
+ continue;
343
+ }
344
+ yield v;
345
+ }
346
+ }
347
+ return fn;
348
+ }
349
+ const opSkip = (count) => toPipeFn(opSkipSync(count), opSkipAsync(count));
350
+
351
+ function opTakeAsync(count) {
352
+ async function* fn(iter) {
353
+ if (count <= 0)
354
+ return;
355
+ for await (const v of iter) {
356
+ yield v;
357
+ if (--count <= 0)
358
+ return;
359
+ }
360
+ }
361
+ return fn;
362
+ }
363
+ function opTakeSync(count) {
364
+ function* fn(iter) {
365
+ if (count <= 0)
366
+ return;
367
+ for (const v of iter) {
368
+ yield v;
369
+ if (--count <= 0)
370
+ return;
371
+ }
372
+ }
373
+ return fn;
374
+ }
375
+ /**
376
+ * Consume only the first `count` number from the iterable.
377
+ * @param count - number to take
378
+ */
379
+ const opTake = (count) => toPipeFn(opTakeSync(count), opTakeAsync(count));
380
+
381
+ /**
382
+ * Tap allows you to listen on values, without modifying them.
383
+ *
384
+ * @param fn - function to call for each value.
385
+ */
386
+ function opTapAsync(tapFn) {
387
+ async function* fn(iter) {
388
+ for await (const v of iter) {
389
+ tapFn(v);
390
+ yield v;
391
+ }
392
+ }
393
+ return fn;
394
+ }
395
+ /**
396
+ * Tap allows you to listen on values, without modifying them.
397
+ *
398
+ * @param fn - function to call for each value.
399
+ */
400
+ function opTapSync(tapFn) {
401
+ function* fn(iter) {
402
+ for (const v of iter) {
403
+ tapFn(v);
404
+ yield v;
405
+ }
406
+ }
407
+ return fn;
408
+ }
409
+ /**
410
+ * Tap allows you to listen on values, without modifying them.
411
+ *
412
+ * @param fn - function to call for each value.
413
+ */
414
+ const opTap = (fn) => toPipeFn(opTapSync(fn), opTapAsync(fn));
415
+
416
+ function opUniqueAsync(k) {
417
+ function fnK(k) {
418
+ async function* fn(iter) {
419
+ const s = new Set();
420
+ for await (const v of iter) {
421
+ const kk = k(v);
422
+ if (s.has(kk))
423
+ continue;
424
+ s.add(kk);
425
+ yield v;
426
+ }
427
+ }
428
+ return fn;
429
+ }
430
+ async function* fn(iter) {
431
+ const s = new Set();
432
+ for await (const v of iter) {
433
+ if (s.has(v))
434
+ continue;
435
+ s.add(v);
436
+ yield v;
437
+ }
438
+ }
439
+ return k ? fnK(k) : fn;
440
+ }
441
+ function opUniqueSync(k) {
442
+ function fnK(key) {
443
+ function* fn(iter) {
444
+ const s = new Set();
445
+ for (const v of iter) {
446
+ const kk = key(v);
447
+ if (s.has(kk))
448
+ continue;
449
+ s.add(kk);
450
+ yield v;
451
+ }
452
+ }
453
+ return fn;
454
+ }
455
+ function* fn(iter) {
456
+ const s = new Set();
457
+ for (const v of iter) {
458
+ if (s.has(v))
459
+ continue;
460
+ s.add(v);
461
+ yield v;
462
+ }
463
+ }
464
+ return k ? fnK(k) : fn;
465
+ }
466
+ const opUnique = (getKey) => toPipeFn(opUniqueSync(getKey), opUniqueAsync(getKey));
467
+
468
+ exports.opAppend = opAppend;
469
+ exports.opAppendAsync = opAppendAsync;
470
+ exports.opAppendSync = opAppendSync;
471
+ exports.opAwaitAsync = opAwaitAsync;
472
+ exports.opCombineAsync = opCombineAsync;
473
+ exports.opCombineSync = opCombineSync;
474
+ exports.opConcatMap = opConcatMap;
475
+ exports.opConcatMapAsync = opConcatMapAsync;
476
+ exports.opConcatMapSync = opConcatMapSync;
477
+ exports.opFilter = opFilter;
478
+ exports.opFilterAsync = opFilterAsync;
479
+ exports.opFilterSync = opFilterSync;
480
+ exports.opFirst = opFirst;
481
+ exports.opFirstAsync = opFirstAsync;
482
+ exports.opFirstSync = opFirstSync;
483
+ exports.opFlatten = opFlatten;
484
+ exports.opFlattenAsync = opFlattenAsync;
485
+ exports.opFlattenSync = opFlattenSync;
486
+ exports.opJoinStrings = opJoinStrings;
487
+ exports.opJoinStringsAsync = opJoinStringsAsync;
488
+ exports.opJoinStringsSync = opJoinStringsSync;
489
+ exports.opLast = opLast;
490
+ exports.opLastAsync = opLastAsync;
491
+ exports.opLastSync = opLastSync;
492
+ exports.opMap = opMap;
493
+ exports.opMapAsync = opMapAsync;
494
+ exports.opMapSync = opMapSync;
495
+ exports.opReduceAsync = opReduceAsync;
496
+ exports.opReduceSync = opReduceSync;
497
+ exports.opSkip = opSkip;
498
+ exports.opSkipAsync = opSkipAsync;
499
+ exports.opSkipSync = opSkipSync;
500
+ exports.opTake = opTake;
501
+ exports.opTakeAsync = opTakeAsync;
502
+ exports.opTakeSync = opTakeSync;
503
+ exports.opTap = opTap;
504
+ exports.opTapAsync = opTapAsync;
505
+ exports.opTapSync = opTapSync;
506
+ exports.opUnique = opUnique;
507
+ exports.opUniqueAsync = opUniqueAsync;
508
+ exports.opUniqueSync = opUniqueSync;
@@ -0,0 +1,17 @@
1
+ export { opAppend, opAppendAsync, opAppendSync } from './append.js';
2
+ export { opAwaitAsync } from './await.js';
3
+ export { opCombineAsync, opCombineSync } from './combine.js';
4
+ export { opConcatMap, opConcatMapAsync, opConcatMapSync } from './concatMap.js';
5
+ export { opFilter, opFilterAsync, opFilterSync } from './filter.js';
6
+ export { opFirst, opFirstAsync, opFirstSync } from './first.js';
7
+ export { opFlatten, opFlattenAsync, opFlattenSync } from './flatten.js';
8
+ export { opJoinStrings, opJoinStringsAsync, opJoinStringsSync } from './joinStrings.js';
9
+ export { opLast, opLastAsync, opLastSync } from './last.js';
10
+ export { opMap, opMapAsync, opMapSync } from './map.js';
11
+ export { opReduceAsync, opReduceSync } from './reduce.js';
12
+ export { opSkip, opSkipAsync, opSkipSync } from './skip.js';
13
+ export { opTake, opTakeAsync, opTakeSync } from './take.js';
14
+ export { opTap, opTapAsync, opTapSync } from './tap.js';
15
+ export type { OperatorAsync, OperatorSync, OperatorSyncToAsync } from './types.js';
16
+ export { opUnique, opUniqueAsync, opUniqueSync } from './unique.js';
17
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,17 @@
1
+ export interface PipeFnSync<T, U> {
2
+ (iter: Iterable<T>): Iterable<U>;
3
+ /** This is just to help TypeScript figure out the type. */
4
+ __PipeFnSync__?: [T, U];
5
+ }
6
+ export interface PipeFnAsync<T, U> {
7
+ (iter: AsyncIterable<T>): AsyncIterable<U>;
8
+ /** This is just to help TypeScript figure out the type. */
9
+ __PipeFnAsync__?: [T, U];
10
+ }
11
+ export type PipeFn<T, U> = PipeFnSync<T, U> & PipeFnAsync<T, U>;
12
+ export type PsFn<T, U> = PipeFnSync<T, U> | ((i: Iterable<T>) => Iterable<U>);
13
+ export type AnyIterable<T> = Iterable<T> | AsyncIterable<T> | Promise<Iterable<T>> | Iterable<Promise<T>>;
14
+ export type PaFn<T, U> = PipeFnAsync<T, U> | ((i: AsyncIterable<T>) => AsyncIterable<U>);
15
+ export type PipeAsyncTx<T extends [...any]> = T extends [infer Left, infer Right, ...infer Rest] ? Rest extends [any, ...any] ? [PaFn<Left, Right>, ...PipeAsyncTx<[Right, ...Rest]>] : [PaFn<Left, Right>] : never;
16
+ export type PipeSyncTx<T extends [...any]> = T extends [infer Left, infer Right, ...infer Rest] ? Rest extends [any, ...any] ? [PsFn<Left, Right>, ...PipeSyncTx<[Right, ...Rest]>] : [PsFn<Left, Right>] : never;
17
+ //# sourceMappingURL=internalTypes.d.ts.map
@@ -0,0 +1,49 @@
1
+ 'use strict';
2
+
3
+ function toPipeFn(syncFn, asyncFn) {
4
+ function _(i) {
5
+ return isAsyncIterable(i) ? asyncFn(i) : syncFn(i);
6
+ }
7
+ return _;
8
+ }
9
+ function isAsyncIterable(i) {
10
+ return typeof i[Symbol.asyncIterator] === 'function';
11
+ }
12
+
13
+ function toArray(i) {
14
+ return isAsyncIterable(i) ? toArrayAsync(i) : toArraySync(i);
15
+ }
16
+ function toArraySync(iter) {
17
+ return [...iter];
18
+ }
19
+ async function toArrayAsync(iter) {
20
+ const collection = [];
21
+ for await (const i of iter) {
22
+ collection.push(i);
23
+ }
24
+ return collection;
25
+ }
26
+
27
+ function opJoinStringsAsync(joinCharacter = ',') {
28
+ async function* fn(iter) {
29
+ for await (const v of iter) {
30
+ const a = await toArray(v);
31
+ yield a.join(joinCharacter);
32
+ }
33
+ }
34
+ return fn;
35
+ }
36
+ function opJoinStringsSync(joinCharacter = ',') {
37
+ function* fn(iter) {
38
+ for (const v of iter) {
39
+ const a = toArray(v);
40
+ yield a.join(joinCharacter);
41
+ }
42
+ }
43
+ return fn;
44
+ }
45
+ const opJoinStrings = (joinCharacter) => toPipeFn(opJoinStringsSync(joinCharacter), opJoinStringsAsync(joinCharacter));
46
+
47
+ exports.opJoinStrings = opJoinStrings;
48
+ exports.opJoinStringsAsync = opJoinStringsAsync;
49
+ exports.opJoinStringsSync = opJoinStringsSync;
@@ -0,0 +1,4 @@
1
+ export declare function opJoinStringsAsync(joinCharacter?: string): (iter: AsyncIterable<AsyncIterable<string> | Iterable<string>>) => AsyncIterable<string>;
2
+ export declare function opJoinStringsSync(joinCharacter?: string): (iter: Iterable<Iterable<string>>) => Iterable<string>;
3
+ export declare const opJoinStrings: (joinCharacter?: string) => import("../internalTypes.js").PipeFn<Iterable<string>, string>;
4
+ //# sourceMappingURL=joinStrings.d.ts.map
@@ -1,7 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.opLast = exports.opLastSync = exports.opLastAsync = void 0;
4
- const util_1 = require("../helpers/util");
1
+ 'use strict';
2
+
3
+ function isAsyncIterable(i) {
4
+ return typeof i[Symbol.asyncIterator] === 'function';
5
+ }
6
+
5
7
  const symNotFound = Symbol('LastNotFound');
6
8
  // prettier-ignore
7
9
  function opLastAsync(lastFn) {
@@ -18,7 +20,6 @@ function opLastAsync(lastFn) {
18
20
  }
19
21
  return fn;
20
22
  }
21
- exports.opLastAsync = opLastAsync;
22
23
  function opLastSync(lastFn) {
23
24
  function* fn(iter) {
24
25
  let last = symNotFound;
@@ -32,14 +33,15 @@ function opLastSync(lastFn) {
32
33
  }
33
34
  return fn;
34
35
  }
35
- exports.opLastSync = opLastSync;
36
36
  function opLast(fn) {
37
37
  const asyncFn = opLastAsync(fn);
38
38
  const syncFn = opLastSync(fn);
39
39
  function _(i) {
40
- return (0, util_1.isAsyncIterable)(i) ? asyncFn(i) : syncFn(i);
40
+ return isAsyncIterable(i) ? asyncFn(i) : syncFn(i);
41
41
  }
42
42
  return _;
43
43
  }
44
+
44
45
  exports.opLast = opLast;
45
- //# sourceMappingURL=last.js.map
46
+ exports.opLastAsync = opLastAsync;
47
+ exports.opLastSync = opLastSync;
@@ -0,0 +1,10 @@
1
+ import type { PipeFn } from '../internalTypes.js';
2
+ export declare function opLastAsync<T, S extends T>(lastFn: (v: T) => v is S): (iter: AsyncIterable<T>) => AsyncIterable<S>;
3
+ export declare function opLastAsync<T, S extends Awaited<T>>(lastFn: (v: Awaited<T>) => v is S): (iter: AsyncIterable<T>) => AsyncIterable<S>;
4
+ export declare function opLastAsync<T>(lastFn: (v: Awaited<T>) => boolean): (iter: AsyncIterable<T>) => AsyncIterable<Awaited<T>>;
5
+ export declare function opLastAsync<T>(lastFn: (v: Awaited<T>) => Promise<boolean>): (iter: AsyncIterable<T>) => AsyncIterable<Awaited<T>>;
6
+ export declare function opLastSync<T, S extends T>(lastFn: (v: T) => v is S): (iter: Iterable<T>) => Iterable<S>;
7
+ export declare function opLastSync<T>(lastFn: (v: T) => boolean): (iter: Iterable<T>) => Iterable<T>;
8
+ export declare function opLast<T, S extends T>(fn: (v: T) => v is S): PipeFn<T, S>;
9
+ export declare function opLast<T>(fn: (v: T) => boolean): PipeFn<T, T>;
10
+ //# sourceMappingURL=last.d.ts.map
@@ -1,7 +1,15 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.opMap = exports.opMapSync = exports.opMapAsync = void 0;
4
- const util_1 = require("../helpers/util");
1
+ 'use strict';
2
+
3
+ function toPipeFn(syncFn, asyncFn) {
4
+ function _(i) {
5
+ return isAsyncIterable(i) ? asyncFn(i) : syncFn(i);
6
+ }
7
+ return _;
8
+ }
9
+ function isAsyncIterable(i) {
10
+ return typeof i[Symbol.asyncIterator] === 'function';
11
+ }
12
+
5
13
  function opMapAsync(mapFn) {
6
14
  async function* fn(iter) {
7
15
  for await (const v of iter) {
@@ -10,7 +18,6 @@ function opMapAsync(mapFn) {
10
18
  }
11
19
  return fn;
12
20
  }
13
- exports.opMapAsync = opMapAsync;
14
21
  function opMapSync(mapFn) {
15
22
  function* fn(iter) {
16
23
  for (const v of iter) {
@@ -19,7 +26,8 @@ function opMapSync(mapFn) {
19
26
  }
20
27
  return fn;
21
28
  }
22
- exports.opMapSync = opMapSync;
23
- const opMap = (fn) => (0, util_1.toPipeFn)(opMapSync(fn), opMapAsync(fn));
29
+ const opMap = (fn) => toPipeFn(opMapSync(fn), opMapAsync(fn));
30
+
24
31
  exports.opMap = opMap;
25
- //# sourceMappingURL=map.js.map
32
+ exports.opMapAsync = opMapAsync;
33
+ exports.opMapSync = opMapSync;
@@ -0,0 +1,4 @@
1
+ export declare function opMapAsync<T, U = T>(mapFn: (v: T) => U): (iter: AsyncIterable<T>) => AsyncIterable<U>;
2
+ export declare function opMapSync<T, U = T>(mapFn: (v: T) => U): (iter: Iterable<T>) => Iterable<U>;
3
+ export declare const opMap: <T, U>(fn: (v: T) => U) => import("../internalTypes.js").PipeFn<T, U>;
4
+ //# sourceMappingURL=map.d.ts.map