Reusable stream transformers for WHATWG Streams similar to ReactiveX Operators
Use either
yarn add stream-transformers
or
npm install stream-transformers
This module allows you to transform WHATWG Streams using different operators.
import { ReadableStream } from "isomorphic-streams";
import { filter, map } from "stream-transformers";
const SECOND = 1000;
const stream = new ReadableStream({
start(controller) {
let index = 0;
setInterval(() => {
controller.enqueue(index);
index += 1;
}, SECOND);
},
});
const output = stream
.pipeThrough(map((it) => it * 2))
.pipeThrough(filter((it) => it < 10));
for await (const value of output) {
console.dir(value);
}
- every - Determines whether every chunk of the stream fulfills a given predicate.
- filter - Filters chunks emitted by the stream using a predicate.
- map - Maps each chunk emitted by the stream to another type using a callback.
- reduce - Aggregates a stream to a value emitting the result when the stream closes.
- reduce1 - Aggregates a stream to a value emitting the result when the stream closes.
- scan - Aggregates a stream to a value emitting the intermediate result with each chunk.
- scan1 - Aggregates a stream to a value emitting the intermediate result with each chunk.
- some - Determines whether some chunks of the stream fulfill a given predicate.
This project is open to feedback and contributions, please open an issue.
stream-transformers
follows the Contributor Covenant Code of Conduct.
Also have a look at the following NPM Packages:
- isomorphic-streams - Isomorphic package for WHATWG Streams in Node.js and the browser.
- jest-stream-marbles - Jest extension to test WHATWG Streams with marble syntax.
MIT © 2021 Konstantin Möllers, see LICENSE.