iter-fest 0.1.1-main.b1e260f → 0.1.1-main.cc53108

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 (57) hide show
  1. package/README.md +31 -57
  2. package/dist/{chunk-RVIERPEV.mjs → chunk-EUVK4YM7.mjs} +5 -6
  3. package/dist/chunk-EUVK4YM7.mjs.map +1 -0
  4. package/dist/{chunk-DC2ZV7KQ.mjs → chunk-KYMTQJIJ.mjs} +1 -1
  5. package/dist/chunk-KYMTQJIJ.mjs.map +1 -0
  6. package/dist/{chunk-JVR6BUJA.mjs → chunk-TQCZXEK7.mjs} +1 -1
  7. package/dist/chunk-TQCZXEK7.mjs.map +1 -0
  8. package/dist/{chunk-S2LECQKY.mjs → chunk-YLERARWI.mjs} +1 -1
  9. package/dist/chunk-YLERARWI.mjs.map +1 -0
  10. package/dist/iter-fest.asyncIteratorToArray.d.mts +4 -1
  11. package/dist/iter-fest.asyncIteratorToArray.d.ts +4 -1
  12. package/dist/iter-fest.asyncIteratorToArray.js.map +1 -1
  13. package/dist/iter-fest.asyncIteratorToArray.mjs +1 -1
  14. package/dist/iter-fest.d.mts +1 -3
  15. package/dist/iter-fest.d.ts +1 -3
  16. package/dist/iter-fest.iteratorFrom.d.mts +3 -1
  17. package/dist/iter-fest.iteratorFrom.d.ts +3 -1
  18. package/dist/iter-fest.iteratorFrom.js.map +1 -1
  19. package/dist/iter-fest.iteratorFrom.mjs +1 -1
  20. package/dist/iter-fest.iteratorToArray.d.mts +4 -1
  21. package/dist/iter-fest.iteratorToArray.d.ts +4 -1
  22. package/dist/iter-fest.iteratorToArray.js.map +1 -1
  23. package/dist/iter-fest.iteratorToArray.mjs +1 -1
  24. package/dist/iter-fest.js +29 -67
  25. package/dist/iter-fest.js.map +1 -1
  26. package/dist/iter-fest.mjs +21 -29
  27. package/dist/iter-fest.readerValues.d.mts +3 -0
  28. package/dist/iter-fest.readerValues.d.ts +3 -0
  29. package/dist/{iter-fest.readableStreamValues.js → iter-fest.readerValues.js} +9 -10
  30. package/dist/iter-fest.readerValues.js.map +1 -0
  31. package/dist/iter-fest.readerValues.mjs +7 -0
  32. package/package.json +7 -27
  33. package/dist/chunk-72AEHTPQ.mjs +0 -38
  34. package/dist/chunk-72AEHTPQ.mjs.map +0 -1
  35. package/dist/chunk-DC2ZV7KQ.mjs.map +0 -1
  36. package/dist/chunk-JVR6BUJA.mjs.map +0 -1
  37. package/dist/chunk-NLXKATXE.mjs +0 -10
  38. package/dist/chunk-NLXKATXE.mjs.map +0 -1
  39. package/dist/chunk-RVIERPEV.mjs.map +0 -1
  40. package/dist/chunk-S2LECQKY.mjs.map +0 -1
  41. package/dist/iter-fest.asyncIteratorFrom.d.mts +0 -10
  42. package/dist/iter-fest.asyncIteratorFrom.d.ts +0 -10
  43. package/dist/iter-fest.asyncIteratorFrom.js +0 -44
  44. package/dist/iter-fest.asyncIteratorFrom.js.map +0 -1
  45. package/dist/iter-fest.asyncIteratorFrom.mjs +0 -7
  46. package/dist/iter-fest.observableValues.d.mts +0 -7
  47. package/dist/iter-fest.observableValues.d.ts +0 -7
  48. package/dist/iter-fest.observableValues.js +0 -102
  49. package/dist/iter-fest.observableValues.js.map +0 -1
  50. package/dist/iter-fest.observableValues.mjs +0 -9
  51. package/dist/iter-fest.observableValues.mjs.map +0 -1
  52. package/dist/iter-fest.readableStreamValues.d.mts +0 -3
  53. package/dist/iter-fest.readableStreamValues.d.ts +0 -3
  54. package/dist/iter-fest.readableStreamValues.js.map +0 -1
  55. package/dist/iter-fest.readableStreamValues.mjs +0 -7
  56. package/dist/iter-fest.readableStreamValues.mjs.map +0 -1
  57. /package/dist/{iter-fest.asyncIteratorFrom.mjs.map → iter-fest.readerValues.mjs.map} +0 -0
package/README.md CHANGED
@@ -18,23 +18,18 @@ npm install iter-fest
18
18
 
19
19
  ## Conversions
20
20
 
21
- | From | To | Function |
22
- | -------------------------- | ----------------------- | ------------------------------------------------------------------------------- |
23
- | `Iterator` | `IterableIterator` | [`iteratorToIterable`](#converting-an-iterator-to-iterable) |
24
- | `AsyncIterator` | `AsyncIterableIterator` | [`asyncIteratorToAsyncIterable`](#converting-an-iterator-to-iterable) |
25
- | `Observable` | `ReadableStream` | [`observableSubscribeAsReadable`](#converting-an-observable-to-readablestream) |
26
- | `ReadableStream` | `AsyncIterableIterator` | [`readableStreamValues`](#converting-a-readablestream-to-asynciterableiterator) |
27
- | `AsyncIterable` | `Observable` | [`observableFromAsync`](#converting-an-asynciterable-to-observable) |
28
- | `AsyncIterable`/`Iterable` | `ReadableStream` | [`readableStreamFrom`](#converting-an-asynciterableiterable-to-readablestream) |
29
- | `Observable` | `AsyncIterableIterator` | [`observableValues`](#converting-an-observable-to-asynciterableiterator) |
21
+ | From | To | Function signature |
22
+ | ----------------------------- | ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
23
+ | `Iterator` | `IterableIterator` | [`iteratorToIterable<T>(iterator: Iterator<T>): IterableIterator<T>`](#converting-an-iterator-to-iterable) |
24
+ | `AsyncIterator` | `AsyncIterableIterator` | [`asyncIteratorToAsyncIterable<T>(asyncIterator: AsyncIterator<T>): AsyncIterableIterator<T>`](#converting-an-iterator-to-iterable) |
25
+ | `Observable` | `ReadableStream` | [`observableSubscribeAsReadable<T>(observable: Observable<T>): ReadableStream<T>`](#converting-an-observable-to-readablestream) |
26
+ | `ReadableStreamDefaultReader` | `AsyncIterableIterator` | [`readerValues`<T>(reader: ReadableStreamDefaultReader<T>): AsyncIterableIterator<T>`](#converting-a-readablestreamdefaultreader-to-asynciterableiterator) |
27
+ | `AsyncIterable` | `Observable` | [`observableFromAsync<T>(iterable: AsyncIterable<T>): Observable<T>`](#converting-an-asynciterable-to-observable) |
28
+ | `AsyncIterable`/`Iterable` | `ReadableStream` | [`readableStreamFrom<T>(anyIterable: AsyncIterable<T> \| Iterable<T>): ReadableStream<T>`](#converting-an-asynciterableiterable-to-readablestream) |
30
29
 
31
- ### Converting an iterator to iterable
32
-
33
- ```ts
34
- function iteratorToIterable<T>(iterator: Iterator<T>): IterableIterator<T>
30
+ To convert `Observable` to `AsyncIterableIterator`, [use `ReadableStream` as intermediate format](#converting-an-observable-to-asynciterableiterator).
35
31
 
36
- function asyncIteratorToAsyncIterable<T>(asyncIterator: AsyncIterator<T>): AsyncIterableIterator<T>
37
- ```
32
+ ### Converting an iterator to iterable
38
33
 
39
34
  `iteratorToIterable` and `asyncIteratorToAsyncIterable` enable a [pure iterator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator) to be iterable using a for-loop statement.
40
35
 
@@ -60,12 +55,26 @@ for (const value of iteratorToIterable(iterate())) {
60
55
 
61
56
  Note: calling `[Symbol.iterator]()` or `[Symbol.asyncIterator]()` will not restart the iteration. This is because iterator is an instance of iteration and is not restartable.
62
57
 
63
- ### Converting an `AsyncIterable` to `Observable`
58
+ ### Converting an `Observable` to `AsyncIterableIterator`
59
+
60
+ `ReadableStream` can be used as an intermediate format when converting an `Observable` to `AsyncIterableIterator`.
61
+
62
+ Note: `Observable` is push-based and it does not support flow control. When converting to `AsyncIterableIteratorrr`, the internal buffer of `ReadableStream` could build up quickly.
64
63
 
65
64
  ```ts
66
- function observableFromAsync<T>(iterable: AsyncIterable<T>): Observable<T>
65
+ const observable = Observable.from([1, 2, 3]);
66
+ const readable = observableSubscribeAsReadable(observable);
67
+ const iterable = readerValues(readable.getReader());
68
+
69
+ for await (const value of iterable) {
70
+ console.log(value); // Prints "1", "2", "3".
71
+ }
67
72
  ```
68
73
 
74
+ Note: calling `[Symbol.asyncIterator]()` will not resubscribe and read from the start of the observable. This is because the intermediate format does not support restart.
75
+
76
+ ### Converting an `AsyncIterable` to `Observable`
77
+
69
78
  `Observable.from` converts `Iterable` into `Observable`. However, it does not convert `AsyncIterable`.
70
79
 
71
80
  `observableFromAsync` will convert `AsyncIterable` into `Observable`. It will try to restart the iteration by calling `[Symbol.asyncIterator]()`.
@@ -89,10 +98,6 @@ Note: It is not recommended to convert `AsyncGenerator` to an `Observable`. `Asy
89
98
 
90
99
  ### Converting an `Observable` to `ReadableStream`
91
100
 
92
- ```ts
93
- function observableSubscribeAsReadable<T>(observable: Observable<T>): ReadableStream<T>
94
- ```
95
-
96
101
  `ReadableStream` is powerful for transforming and piping stream of data. It can be formed using data from both push-based and pull-based source with backpressuree.
97
102
 
98
103
  Note: `Observable` is push-based and it does not support flow control. When converting to `ReadableStream`, the internal buffer could build up quickly.
@@ -104,16 +109,12 @@ const readable = observableSubscribeAsReadable(observable);
104
109
  readable.pipeTo(stream.writable); // Will write 1, 2, 3.
105
110
  ```
106
111
 
107
- ### Converting a `ReadableStream` to `AsyncIterableIterator`
108
-
109
- ```ts
110
- function readableStreamValues`<T>(readable: ReadableStream<T>): AsyncIterableIterator<T>
111
- ```
112
+ ### Converting a `ReadableStreamDefaultReader` to `AsyncIterableIterator`
112
113
 
113
- `readableStreamValues` allow iteration of `ReadableStream` as an `AsyncIterableIterator`.
114
+ `readerValues` will convert default reader of `ReadableStream` into an `AsyncIterableIterator` to use in for-loop.
114
115
 
115
116
  ```ts
116
- const readable = new ReadableStream({
117
+ const readableStream = new ReadableStream({
117
118
  start(controller) {
118
119
  controller.enqueue(1);
119
120
  controller.enqueue(2);
@@ -124,23 +125,17 @@ const readable = new ReadableStream({
124
125
  }
125
126
  });
126
127
 
127
- const iterable = readableStreamValues(readable);
128
+ const iterable = readerValues(readableStream.getReader());
128
129
 
129
130
  for await (const value of iterable) {
130
131
  console.log(value); // Prints "1", "2", "3".
131
132
  }
132
133
  ```
133
134
 
134
- Note: The stream will be locked as soon as the iterable is created. When using iterating outside of for-loop, make sure to call `AsyncIterator.return` when the iteration is done to release the lock on the stream.
135
-
136
- Note: `[Symbol.asyncIterator]()` will not restart the stream.
135
+ Note: `[Symbol.asyncIterator]()` will not restart the reader and read from start of the stream. Reader is not restartable and streams are not seekable.
137
136
 
138
137
  ### Converting an `AsyncIterable`/`Iterable` to `ReadableStream`
139
138
 
140
- ```ts
141
- function readableStreamFrom<T>(anyIterable: AsyncIterable<T> | Iterable<T>): ReadableStream<T>
142
- ```
143
-
144
139
  > Notes: this feature is part of [Streams Standard](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/from_static).
145
140
 
146
141
  ```ts
@@ -152,27 +147,6 @@ readable.pipeTo(stream.writable); // Will write 1, 2, 3.
152
147
 
153
148
  Note: `readableStreamFrom()` will call `[Symbol.iterator]()` initially to restart the iteration where possible.
154
149
 
155
- ### Converting an `Observable` to `AsyncIterableIterator`
156
-
157
- ```ts
158
- function observableValues<T>(observable: Observable<T>): AsyncIterableIterator<T>
159
- ```
160
-
161
- `Observable` can be converted to `AsyncIterableIterator` for easier consumption.
162
-
163
- ```ts
164
- const observable = Observable.from([1, 2, 3]);
165
- const iterable = observableValues(readable);
166
-
167
- for await (const value of iterable) {
168
- console.log(value); // Prints "1", "2", "3".
169
- }
170
- ```
171
-
172
- Note: `Observable` is push-based and it does not support flow control. When converting to `AsyncIterableIterator`, the internal buffer could build up quickly.
173
-
174
- Note: when the observable throw an exception via `observer.error()`, it will become rejection of `AsyncIterator.next()`. The exception will be hoisted back to the caller.
175
-
176
150
  ## Others
177
151
 
178
152
  ### Typed `Observable`
@@ -1,6 +1,5 @@
1
- // src/readableStreamValues.ts
2
- function readableStreamValues(readable) {
3
- const reader = readable.getReader();
1
+ // src/readerValues.ts
2
+ function readerValues(reader) {
4
3
  const iterable = {
5
4
  [Symbol.asyncIterator]() {
6
5
  return iterable;
@@ -13,7 +12,7 @@ function readableStreamValues(readable) {
13
12
  return { value: result.value };
14
13
  },
15
14
  async return() {
16
- reader.releaseLock();
15
+ reader.cancel();
17
16
  return { done: true, value: void 0 };
18
17
  }
19
18
  };
@@ -21,6 +20,6 @@ function readableStreamValues(readable) {
21
20
  }
22
21
 
23
22
  export {
24
- readableStreamValues
23
+ readerValues
25
24
  };
26
- //# sourceMappingURL=chunk-RVIERPEV.mjs.map
25
+ //# sourceMappingURL=chunk-EUVK4YM7.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/readerValues.ts"],"sourcesContent":["export function readerValues<T>(reader: ReadableStreamDefaultReader<T>): AsyncIterableIterator<T> {\n const iterable: AsyncIterableIterator<T> = {\n [Symbol.asyncIterator]() {\n return iterable;\n },\n async next(): Promise<IteratorResult<T>> {\n const result = await Promise.race([reader.read(), reader.closed]);\n\n if (!result || result.done) {\n return { done: true, value: undefined };\n }\n\n return { value: result.value };\n },\n async return() {\n // Throw inside for-loop is return().\n reader.cancel();\n\n return { done: true, value: undefined };\n }\n };\n\n return iterable;\n}\n"],"mappings":";AAAO,SAAS,aAAgB,QAAkE;AAChG,QAAM,WAAqC;AAAA,IACzC,CAAC,OAAO,aAAa,IAAI;AACvB,aAAO;AAAA,IACT;AAAA,IACA,MAAM,OAAmC;AACvC,YAAM,SAAS,MAAM,QAAQ,KAAK,CAAC,OAAO,KAAK,GAAG,OAAO,MAAM,CAAC;AAEhE,UAAI,CAAC,UAAU,OAAO,MAAM;AAC1B,eAAO,EAAE,MAAM,MAAM,OAAO,OAAU;AAAA,MACxC;AAEA,aAAO,EAAE,OAAO,OAAO,MAAM;AAAA,IAC/B;AAAA,IACA,MAAM,SAAS;AAEb,aAAO,OAAO;AAEd,aAAO,EAAE,MAAM,MAAM,OAAO,OAAU;AAAA,IACxC;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
@@ -7,4 +7,4 @@ function iteratorFrom(iteratorLike) {
7
7
  export {
8
8
  iteratorFrom
9
9
  };
10
- //# sourceMappingURL=chunk-DC2ZV7KQ.mjs.map
10
+ //# sourceMappingURL=chunk-KYMTQJIJ.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/iteratorFrom.ts"],"sourcesContent":["// @ts-expect-error core-js-pure is not typed.\nimport from from 'core-js-pure/full/iterator/from';\n\n/**\n * `.from` is a static method (unlike the others listed above) which takes an object as an argument. This method allows wrapping \"iterator-like\" objects with an iterator.\n *\n * @param limit\n *\n * @return Returns the object if it is already an iterator, returns a wrapping iterator if the passed object implements a callable @@iterator property.\n *\n * @link https://github.com/tc39/proposal-iterator-helpers/blob/main/README.md\n */\nexport function iteratorFrom<T>(iteratorLike: Iterator<T>): Iterator<T> {\n return from(iteratorLike);\n}\n"],"mappings":";AACA,OAAO,UAAU;AAWV,SAAS,aAAgB,cAAwC;AACtE,SAAO,KAAK,YAAY;AAC1B;","names":[]}
@@ -7,4 +7,4 @@ function asyncIteratorToArray(asyncIteratorLike) {
7
7
  export {
8
8
  asyncIteratorToArray
9
9
  };
10
- //# sourceMappingURL=chunk-JVR6BUJA.mjs.map
10
+ //# sourceMappingURL=chunk-TQCZXEK7.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/asyncIteratorToArray.ts"],"sourcesContent":["// @ts-expect-error core-js-pure is not typed.\nimport toArray from 'core-js-pure/full/async-iterator/to-array';\n\ntype AsyncIteratorLike<T> = Pick<AsyncIterator<T>, 'next'>;\n\n/**\n * When you have a non-infinite iterator which you wish to transform into an array, you can do so with the builtin toArray method.\n *\n * @param limit\n *\n * @return Returns an Array containing the values from the iterator.\n *\n * @link https://github.com/tc39/proposal-iterator-helpers/blob/main/README.md\n */\nexport function asyncIteratorToArray<T>(asyncIteratorLike: AsyncIteratorLike<T>): Promise<T[]> {\n return toArray(asyncIteratorLike);\n}\n"],"mappings":";AACA,OAAO,aAAa;AAab,SAAS,qBAAwB,mBAAuD;AAC7F,SAAO,QAAQ,iBAAiB;AAClC;","names":[]}
@@ -7,4 +7,4 @@ function iteratorToArray(iteratorLike) {
7
7
  export {
8
8
  iteratorToArray
9
9
  };
10
- //# sourceMappingURL=chunk-S2LECQKY.mjs.map
10
+ //# sourceMappingURL=chunk-YLERARWI.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/iteratorToArray.ts"],"sourcesContent":["// @ts-expect-error core-js-pure is not typed.\nimport toArray from 'core-js-pure/full/iterator/to-array';\n\ntype IteratorLike<T> = Pick<Iterator<T>, 'next'>;\n\n/**\n * When you have a non-infinite iterator which you wish to transform into an array, you can do so with the builtin toArray method.\n *\n * @param limit\n *\n * @return Returns an Array containing the values from the iterator.\n *\n * @link https://github.com/tc39/proposal-iterator-helpers/blob/main/README.md\n */\nexport function iteratorToArray<T>(iteratorLike: IteratorLike<T>): T[] {\n return toArray(iteratorLike);\n}\n"],"mappings":";AACA,OAAO,aAAa;AAab,SAAS,gBAAmB,cAAoC;AACrE,SAAO,QAAQ,YAAY;AAC7B;","names":[]}
@@ -1,10 +1,13 @@
1
+ type AsyncIteratorLike<T> = Pick<AsyncIterator<T>, 'next'>;
1
2
  /**
2
3
  * When you have a non-infinite iterator which you wish to transform into an array, you can do so with the builtin toArray method.
3
4
  *
5
+ * @param limit
6
+ *
4
7
  * @return Returns an Array containing the values from the iterator.
5
8
  *
6
9
  * @link https://github.com/tc39/proposal-iterator-helpers/blob/main/README.md
7
10
  */
8
- declare function asyncIteratorToArray<T>(asyncIteratorLike: Pick<AsyncIterator<T>, 'next'>): Promise<T[]>;
11
+ declare function asyncIteratorToArray<T>(asyncIteratorLike: AsyncIteratorLike<T>): Promise<T[]>;
9
12
 
10
13
  export { asyncIteratorToArray };
@@ -1,10 +1,13 @@
1
+ type AsyncIteratorLike<T> = Pick<AsyncIterator<T>, 'next'>;
1
2
  /**
2
3
  * When you have a non-infinite iterator which you wish to transform into an array, you can do so with the builtin toArray method.
3
4
  *
5
+ * @param limit
6
+ *
4
7
  * @return Returns an Array containing the values from the iterator.
5
8
  *
6
9
  * @link https://github.com/tc39/proposal-iterator-helpers/blob/main/README.md
7
10
  */
8
- declare function asyncIteratorToArray<T>(asyncIteratorLike: Pick<AsyncIterator<T>, 'next'>): Promise<T[]>;
11
+ declare function asyncIteratorToArray<T>(asyncIteratorLike: AsyncIteratorLike<T>): Promise<T[]>;
9
12
 
10
13
  export { asyncIteratorToArray };
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/asyncIteratorToArray.ts"],"sourcesContent":["// @ts-expect-error core-js-pure is not typed.\nimport toArray from 'core-js-pure/full/async-iterator/to-array';\n\n/**\n * When you have a non-infinite iterator which you wish to transform into an array, you can do so with the builtin toArray method.\n *\n * @return Returns an Array containing the values from the iterator.\n *\n * @link https://github.com/tc39/proposal-iterator-helpers/blob/main/README.md\n */\nexport function asyncIteratorToArray<T>(asyncIteratorLike: Pick<AsyncIterator<T>, 'next'>): Promise<T[]> {\n return toArray(asyncIteratorLike);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,sBAAoB;AASb,SAAS,qBAAwB,mBAAiE;AACvG,aAAO,gBAAAA,SAAQ,iBAAiB;AAClC;","names":["toArray"]}
1
+ {"version":3,"sources":["../src/asyncIteratorToArray.ts"],"sourcesContent":["// @ts-expect-error core-js-pure is not typed.\nimport toArray from 'core-js-pure/full/async-iterator/to-array';\n\ntype AsyncIteratorLike<T> = Pick<AsyncIterator<T>, 'next'>;\n\n/**\n * When you have a non-infinite iterator which you wish to transform into an array, you can do so with the builtin toArray method.\n *\n * @param limit\n *\n * @return Returns an Array containing the values from the iterator.\n *\n * @link https://github.com/tc39/proposal-iterator-helpers/blob/main/README.md\n */\nexport function asyncIteratorToArray<T>(asyncIteratorLike: AsyncIteratorLike<T>): Promise<T[]> {\n return toArray(asyncIteratorLike);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,sBAAoB;AAab,SAAS,qBAAwB,mBAAuD;AAC7F,aAAO,gBAAAA,SAAQ,iBAAiB;AAClC;","names":["toArray"]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  asyncIteratorToArray
3
- } from "./chunk-JVR6BUJA.mjs";
3
+ } from "./chunk-TQCZXEK7.mjs";
4
4
  export {
5
5
  asyncIteratorToArray
6
6
  };
@@ -7,7 +7,6 @@ export { asyncIteratorFilter } from './iter-fest.asyncIteratorFilter.mjs';
7
7
  export { asyncIteratorFind } from './iter-fest.asyncIteratorFind.mjs';
8
8
  export { asyncIteratorFlatMap } from './iter-fest.asyncIteratorFlatMap.mjs';
9
9
  export { asyncIteratorForEach } from './iter-fest.asyncIteratorForEach.mjs';
10
- export { asyncIteratorFrom } from './iter-fest.asyncIteratorFrom.mjs';
11
10
  export { asyncIteratorMap } from './iter-fest.asyncIteratorMap.mjs';
12
11
  export { asyncIteratorReduce } from './iter-fest.asyncIteratorReduce.mjs';
13
12
  export { asyncIteratorSome } from './iter-fest.asyncIteratorSome.mjs';
@@ -45,7 +44,6 @@ export { iteratorToSpliced } from './iter-fest.iteratorToSpliced.mjs';
45
44
  export { iteratorToString } from './iter-fest.iteratorToString.mjs';
46
45
  export { observableFromAsync } from './iter-fest.observableFromAsync.mjs';
47
46
  export { observableSubscribeAsReadable } from './iter-fest.observableSubscribeAsReadable.mjs';
48
- export { observableValues } from './iter-fest.observableValues.mjs';
49
47
  export { readableStreamFrom } from './iter-fest.readableStreamFrom.mjs';
50
- export { readableStreamValues } from './iter-fest.readableStreamValues.mjs';
48
+ export { readerValues } from './iter-fest.readerValues.mjs';
51
49
  import 'core-js-pure/full/observable';
@@ -7,7 +7,6 @@ export { asyncIteratorFilter } from './iter-fest.asyncIteratorFilter.js';
7
7
  export { asyncIteratorFind } from './iter-fest.asyncIteratorFind.js';
8
8
  export { asyncIteratorFlatMap } from './iter-fest.asyncIteratorFlatMap.js';
9
9
  export { asyncIteratorForEach } from './iter-fest.asyncIteratorForEach.js';
10
- export { asyncIteratorFrom } from './iter-fest.asyncIteratorFrom.js';
11
10
  export { asyncIteratorMap } from './iter-fest.asyncIteratorMap.js';
12
11
  export { asyncIteratorReduce } from './iter-fest.asyncIteratorReduce.js';
13
12
  export { asyncIteratorSome } from './iter-fest.asyncIteratorSome.js';
@@ -45,7 +44,6 @@ export { iteratorToSpliced } from './iter-fest.iteratorToSpliced.js';
45
44
  export { iteratorToString } from './iter-fest.iteratorToString.js';
46
45
  export { observableFromAsync } from './iter-fest.observableFromAsync.js';
47
46
  export { observableSubscribeAsReadable } from './iter-fest.observableSubscribeAsReadable.js';
48
- export { observableValues } from './iter-fest.observableValues.js';
49
47
  export { readableStreamFrom } from './iter-fest.readableStreamFrom.js';
50
- export { readableStreamValues } from './iter-fest.readableStreamValues.js';
48
+ export { readerValues } from './iter-fest.readerValues.js';
51
49
  import 'core-js-pure/full/observable';
@@ -1,10 +1,12 @@
1
1
  /**
2
2
  * `.from` is a static method (unlike the others listed above) which takes an object as an argument. This method allows wrapping "iterator-like" objects with an iterator.
3
3
  *
4
+ * @param limit
5
+ *
4
6
  * @return Returns the object if it is already an iterator, returns a wrapping iterator if the passed object implements a callable @@iterator property.
5
7
  *
6
8
  * @link https://github.com/tc39/proposal-iterator-helpers/blob/main/README.md
7
9
  */
8
- declare function iteratorFrom<T>(iteratorLike: Pick<Iterator<T>, 'next'>): Iterator<T>;
10
+ declare function iteratorFrom<T>(iteratorLike: Iterator<T>): Iterator<T>;
9
11
 
10
12
  export { iteratorFrom };
@@ -1,10 +1,12 @@
1
1
  /**
2
2
  * `.from` is a static method (unlike the others listed above) which takes an object as an argument. This method allows wrapping "iterator-like" objects with an iterator.
3
3
  *
4
+ * @param limit
5
+ *
4
6
  * @return Returns the object if it is already an iterator, returns a wrapping iterator if the passed object implements a callable @@iterator property.
5
7
  *
6
8
  * @link https://github.com/tc39/proposal-iterator-helpers/blob/main/README.md
7
9
  */
8
- declare function iteratorFrom<T>(iteratorLike: Pick<Iterator<T>, 'next'>): Iterator<T>;
10
+ declare function iteratorFrom<T>(iteratorLike: Iterator<T>): Iterator<T>;
9
11
 
10
12
  export { iteratorFrom };
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/iteratorFrom.ts"],"sourcesContent":["// @ts-expect-error core-js-pure is not typed.\nimport from from 'core-js-pure/full/iterator/from';\n\n/**\n * `.from` is a static method (unlike the others listed above) which takes an object as an argument. This method allows wrapping \"iterator-like\" objects with an iterator.\n *\n * @return Returns the object if it is already an iterator, returns a wrapping iterator if the passed object implements a callable @@iterator property.\n *\n * @link https://github.com/tc39/proposal-iterator-helpers/blob/main/README.md\n */\nexport function iteratorFrom<T>(iteratorLike: Pick<Iterator<T>, 'next'>): Iterator<T> {\n return from(iteratorLike);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,kBAAiB;AASV,SAAS,aAAgB,cAAsD;AACpF,aAAO,YAAAA,SAAK,YAAY;AAC1B;","names":["from"]}
1
+ {"version":3,"sources":["../src/iteratorFrom.ts"],"sourcesContent":["// @ts-expect-error core-js-pure is not typed.\nimport from from 'core-js-pure/full/iterator/from';\n\n/**\n * `.from` is a static method (unlike the others listed above) which takes an object as an argument. This method allows wrapping \"iterator-like\" objects with an iterator.\n *\n * @param limit\n *\n * @return Returns the object if it is already an iterator, returns a wrapping iterator if the passed object implements a callable @@iterator property.\n *\n * @link https://github.com/tc39/proposal-iterator-helpers/blob/main/README.md\n */\nexport function iteratorFrom<T>(iteratorLike: Iterator<T>): Iterator<T> {\n return from(iteratorLike);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,kBAAiB;AAWV,SAAS,aAAgB,cAAwC;AACtE,aAAO,YAAAA,SAAK,YAAY;AAC1B;","names":["from"]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  iteratorFrom
3
- } from "./chunk-DC2ZV7KQ.mjs";
3
+ } from "./chunk-KYMTQJIJ.mjs";
4
4
  export {
5
5
  iteratorFrom
6
6
  };
@@ -1,10 +1,13 @@
1
+ type IteratorLike<T> = Pick<Iterator<T>, 'next'>;
1
2
  /**
2
3
  * When you have a non-infinite iterator which you wish to transform into an array, you can do so with the builtin toArray method.
3
4
  *
5
+ * @param limit
6
+ *
4
7
  * @return Returns an Array containing the values from the iterator.
5
8
  *
6
9
  * @link https://github.com/tc39/proposal-iterator-helpers/blob/main/README.md
7
10
  */
8
- declare function iteratorToArray<T>(iteratorLike: Pick<Iterator<T>, 'next'>): T[];
11
+ declare function iteratorToArray<T>(iteratorLike: IteratorLike<T>): T[];
9
12
 
10
13
  export { iteratorToArray };
@@ -1,10 +1,13 @@
1
+ type IteratorLike<T> = Pick<Iterator<T>, 'next'>;
1
2
  /**
2
3
  * When you have a non-infinite iterator which you wish to transform into an array, you can do so with the builtin toArray method.
3
4
  *
5
+ * @param limit
6
+ *
4
7
  * @return Returns an Array containing the values from the iterator.
5
8
  *
6
9
  * @link https://github.com/tc39/proposal-iterator-helpers/blob/main/README.md
7
10
  */
8
- declare function iteratorToArray<T>(iteratorLike: Pick<Iterator<T>, 'next'>): T[];
11
+ declare function iteratorToArray<T>(iteratorLike: IteratorLike<T>): T[];
9
12
 
10
13
  export { iteratorToArray };
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/iteratorToArray.ts"],"sourcesContent":["// @ts-expect-error core-js-pure is not typed.\nimport toArray from 'core-js-pure/full/iterator/to-array';\n\n/**\n * When you have a non-infinite iterator which you wish to transform into an array, you can do so with the builtin toArray method.\n *\n * @return Returns an Array containing the values from the iterator.\n *\n * @link https://github.com/tc39/proposal-iterator-helpers/blob/main/README.md\n */\nexport function iteratorToArray<T>(iteratorLike: Pick<Iterator<T>, 'next'>): T[] {\n return toArray(iteratorLike);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,sBAAoB;AASb,SAAS,gBAAmB,cAA8C;AAC/E,aAAO,gBAAAA,SAAQ,YAAY;AAC7B;","names":["toArray"]}
1
+ {"version":3,"sources":["../src/iteratorToArray.ts"],"sourcesContent":["// @ts-expect-error core-js-pure is not typed.\nimport toArray from 'core-js-pure/full/iterator/to-array';\n\ntype IteratorLike<T> = Pick<Iterator<T>, 'next'>;\n\n/**\n * When you have a non-infinite iterator which you wish to transform into an array, you can do so with the builtin toArray method.\n *\n * @param limit\n *\n * @return Returns an Array containing the values from the iterator.\n *\n * @link https://github.com/tc39/proposal-iterator-helpers/blob/main/README.md\n */\nexport function iteratorToArray<T>(iteratorLike: IteratorLike<T>): T[] {\n return toArray(iteratorLike);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,sBAAoB;AAab,SAAS,gBAAmB,cAAoC;AACrE,aAAO,gBAAAA,SAAQ,YAAY;AAC7B;","names":["toArray"]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  iteratorToArray
3
- } from "./chunk-S2LECQKY.mjs";
3
+ } from "./chunk-YLERARWI.mjs";
4
4
  export {
5
5
  iteratorToArray
6
6
  };
package/dist/iter-fest.js CHANGED
@@ -9,11 +9,11 @@ var __export = (target, all) => {
9
9
  for (var name in all)
10
10
  __defProp(target, name, { get: all[name], enumerable: true });
11
11
  };
12
- var __copyProps = (to, from3, except, desc) => {
13
- if (from3 && typeof from3 === "object" || typeof from3 === "function") {
14
- for (let key of __getOwnPropNames(from3))
12
+ var __copyProps = (to, from2, except, desc) => {
13
+ if (from2 && typeof from2 === "object" || typeof from2 === "function") {
14
+ for (let key of __getOwnPropNames(from2))
15
15
  if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from3[key], enumerable: !(desc = __getOwnPropDesc(from3, key)) || desc.enumerable });
16
+ __defProp(to, key, { get: () => from2[key], enumerable: !(desc = __getOwnPropDesc(from2, key)) || desc.enumerable });
17
17
  }
18
18
  return to;
19
19
  };
@@ -40,7 +40,6 @@ __export(src_exports, {
40
40
  asyncIteratorFind: () => asyncIteratorFind,
41
41
  asyncIteratorFlatMap: () => asyncIteratorFlatMap,
42
42
  asyncIteratorForEach: () => asyncIteratorForEach,
43
- asyncIteratorFrom: () => asyncIteratorFrom,
44
43
  asyncIteratorMap: () => asyncIteratorMap,
45
44
  asyncIteratorReduce: () => asyncIteratorReduce,
46
45
  asyncIteratorSome: () => asyncIteratorSome,
@@ -77,9 +76,8 @@ __export(src_exports, {
77
76
  iteratorToString: () => iteratorToString,
78
77
  observableFromAsync: () => observableFromAsync,
79
78
  observableSubscribeAsReadable: () => observableSubscribeAsReadable,
80
- observableValues: () => observableValues,
81
79
  readableStreamFrom: () => readableStreamFrom,
82
- readableStreamValues: () => readableStreamValues
80
+ readerValues: () => readerValues
83
81
  });
84
82
  module.exports = __toCommonJS(src_exports);
85
83
 
@@ -178,12 +176,6 @@ function asyncIteratorForEach(asyncIterator, callbackfn) {
178
176
  return (0, import_for_each.default)(asyncIterator, callbackfn);
179
177
  }
180
178
 
181
- // src/asyncIteratorFrom.ts
182
- var import_from = __toESM(require("core-js-pure/full/async-iterator/from"));
183
- function asyncIteratorFrom(asyncIteratorLike) {
184
- return (0, import_from.default)(asyncIteratorLike);
185
- }
186
-
187
179
  // src/asyncIteratorMap.ts
188
180
  var import_map = __toESM(require("core-js-pure/full/async-iterator/map"));
189
181
  function asyncIteratorMap(asyncIterator, callbackfn) {
@@ -444,9 +436,9 @@ function iteratorForEach(iterator, callbackfn) {
444
436
  }
445
437
 
446
438
  // src/iteratorFrom.ts
447
- var import_from2 = __toESM(require("core-js-pure/full/iterator/from"));
439
+ var import_from = __toESM(require("core-js-pure/full/iterator/from"));
448
440
  function iteratorFrom(iteratorLike) {
449
- return (0, import_from2.default)(iteratorLike);
441
+ return (0, import_from.default)(iteratorLike);
450
442
  }
451
443
 
452
444
  // src/iteratorIncludes.ts
@@ -648,55 +640,6 @@ function observableSubscribeAsReadable(observable) {
648
640
  });
649
641
  }
650
642
 
651
- // src/readableStreamValues.ts
652
- function readableStreamValues(readable) {
653
- const reader = readable.getReader();
654
- const iterable = {
655
- [Symbol.asyncIterator]() {
656
- return iterable;
657
- },
658
- async next() {
659
- const result = await Promise.race([reader.read(), reader.closed]);
660
- if (!result || result.done) {
661
- return { done: true, value: void 0 };
662
- }
663
- return { value: result.value };
664
- },
665
- async return() {
666
- reader.releaseLock();
667
- return { done: true, value: void 0 };
668
- }
669
- };
670
- return iterable;
671
- }
672
-
673
- // src/observableValues.ts
674
- function observableValues(observable) {
675
- const readable = observableSubscribeAsReadable(observable);
676
- const iterable = readableStreamValues(readable);
677
- const cancellableIterable = {
678
- [Symbol.asyncIterator]() {
679
- return cancellableIterable;
680
- },
681
- next() {
682
- return iterable.next();
683
- },
684
- return() {
685
- var _a;
686
- try {
687
- return ((_a = iterable.return) == null ? void 0 : _a.call(iterable)) ?? Promise.resolve({ done: true, value: void 0 });
688
- } finally {
689
- readable.cancel();
690
- }
691
- },
692
- throw(error) {
693
- var _a;
694
- return ((_a = iterable.throw) == null ? void 0 : _a.call(iterable, error)) ?? Promise.resolve({ done: true, value: void 0 });
695
- }
696
- };
697
- return cancellableIterable;
698
- }
699
-
700
643
  // src/readableStreamFrom.ts
701
644
  function isIterable(iterable) {
702
645
  return !!(iterable && typeof iterable === "object" && Symbol.iterator in iterable);
@@ -714,6 +657,27 @@ function readableStreamFrom(anyIterable) {
714
657
  }
715
658
  });
716
659
  }
660
+
661
+ // src/readerValues.ts
662
+ function readerValues(reader) {
663
+ const iterable = {
664
+ [Symbol.asyncIterator]() {
665
+ return iterable;
666
+ },
667
+ async next() {
668
+ const result = await Promise.race([reader.read(), reader.closed]);
669
+ if (!result || result.done) {
670
+ return { done: true, value: void 0 };
671
+ }
672
+ return { value: result.value };
673
+ },
674
+ async return() {
675
+ reader.cancel();
676
+ return { done: true, value: void 0 };
677
+ }
678
+ };
679
+ return iterable;
680
+ }
717
681
  // Annotate the CommonJS export names for ESM import in node:
718
682
  0 && (module.exports = {
719
683
  IterableWritableStream,
@@ -726,7 +690,6 @@ function readableStreamFrom(anyIterable) {
726
690
  asyncIteratorFind,
727
691
  asyncIteratorFlatMap,
728
692
  asyncIteratorForEach,
729
- asyncIteratorFrom,
730
693
  asyncIteratorMap,
731
694
  asyncIteratorReduce,
732
695
  asyncIteratorSome,
@@ -763,8 +726,7 @@ function readableStreamFrom(anyIterable) {
763
726
  iteratorToString,
764
727
  observableFromAsync,
765
728
  observableSubscribeAsReadable,
766
- observableValues,
767
729
  readableStreamFrom,
768
- readableStreamValues
730
+ readerValues
769
731
  });
770
732
  //# sourceMappingURL=iter-fest.js.map