utilium 3.2.0 → 3.4.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.
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Utility functions for working with iterators and streams
3
+ */
4
+ /**
5
+ * Converts an `AsyncIterator` or `Iterator` to a `ReadableStream`
6
+ */
7
+ export declare function iteratorToStream<T>(iterator: AsyncIterator<T> | Iterator<T>): ReadableStream<T>;
@@ -0,0 +1,29 @@
1
+ // SPDX-License-Identifier: LGPL-3.0-or-later
2
+ // Copyright (c) 2026 James Prevett
3
+ /**
4
+ * Utility functions for working with iterators and streams
5
+ */
6
+ /**
7
+ * Converts an `AsyncIterator` or `Iterator` to a `ReadableStream`
8
+ */
9
+ export function iteratorToStream(iterator) {
10
+ return new ReadableStream({
11
+ async pull(controller) {
12
+ try {
13
+ const { value, done } = await iterator.next();
14
+ if (done) {
15
+ controller.close();
16
+ }
17
+ else {
18
+ controller.enqueue(value);
19
+ }
20
+ }
21
+ catch (err) {
22
+ controller.error(err);
23
+ }
24
+ },
25
+ async cancel() {
26
+ await iterator.return?.();
27
+ },
28
+ });
29
+ }
package/dist/types.d.ts CHANGED
@@ -49,4 +49,8 @@ export type UnionToTuple<T, L = LastOfUnion<T>, N = [T] extends [never] ? true :
49
49
  */
50
50
  export type $drain<T> = [T] extends [unknown] ? T : never;
51
51
  export type Falsy = null | undefined | false | 0 | 0n | '';
52
+ /**
53
+ * Returns whether `T` is `any`
54
+ */
55
+ export type IsAny<T> = 0 extends 1 & T ? true : false;
52
56
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "utilium",
3
- "version": "3.2.0",
3
+ "version": "3.4.0",
4
4
  "description": "Typescript utilities",
5
5
  "funding": {
6
6
  "type": "individual",