UNPKG

@johngw/stream

Version:

Reactive programming tools using the WHATWG Streams API.

81 lines 2.07 kB
import type { UnderlyingDefaultSource } from 'node:stream/web'; /** * Creates a readable stream from an collection of values. * * @group Sources * @example * Using an Iterable * ``` * fromCollection([1, 2, 3, 4]) * ``` * * Using an AsyncIterable * ``` * fromCollection((async function* () { * yield 1 * })()) * ``` * * Using an ArrayLike * ``` * fromCollection({ * 0: 'zero', * 1: 'one', * 2: 'two', * length: 3, * }) * ``` * * Streaming object entries * ``` * fromCollection({ * one: 1, * two: 2, * three: 3, * }) * // -[one, 1]-[two, 2]-[threee, 3]-| * ``` */ export declare function fromCollection<T>(collection: Iterator<T> | Iterable<T> | AsyncIterator<T> | AsyncIterable<T> | ArrayLike<T>, queuingStrategy?: QueuingStrategy<T>): ReadableStream<T>; export declare function fromCollection<T extends Record<string | symbol, unknown>>(collection: T, queuingStrategy?: QueuingStrategy<T>): ReadableStream<Entries<T>>; /** * An underlying source for an `Iterator` or `AsyncIterator`. * * @group Sources * @example * ``` * const reader = new ReadableStream(new IteratorSource((function* () { * yield 1 * yield 2 * })())) * ``` */ export declare class IteratorSource<T> implements UnderlyingDefaultSource<T> { #private; constructor(iterator: Iterator<T> | AsyncIterator<T>); pull(controller: ReadableStreamDefaultController<T>): Promise<void>; } /** * An underlying source for an `ArrayLike`. * * @group Sources * @example * ``` * const reader = new ReadableStream(new ArrayLikeSource({ * 0: 'zero', * 1: 'one', * length: 2 * })) * ``` */ export declare class ArrayLikeSource<T> implements UnderlyingDefaultSource<T> { #private; constructor(arrayLike: ArrayLike<T>); start(controller: ReadableStreamDefaultController<T>): void; pull(controller: ReadableStreamDefaultController<T>): void; } type Entries<T extends Record<string | number | symbol, unknown>> = { [K in keyof T]: [K, T[K]]; }[keyof T]; export {}; //# sourceMappingURL=fromCollection.d.ts.map