A collection helper methods for WebStreams, inspired by ReactiveExtensions.
npm install web-streams-extensions
import { from, pipe, map, filter, toArray } from 'web-streams-extensions';
// Create a stream from an array and process it
const stream = pipe(
from([1, 2, 3, 4, 5, 6]),
filter(x => x % 2 === 0), // Keep even numbers
map(x => x * 2) // Double them
);
const result = await toArray(stream);
console.log(result); // [4, 8, 12]
- Creation Functions -
from()
,of()
,timer()
,interval()
,range()
, etc. - Consuming Functions -
toArray()
,toPromise()
,subscribe()
, etc. - Piping -
pipe()
,retryPipe()
for chaining operations - Operators - Transform, filter, and control stream data
- Subjects -
Subject
,BehaviorSubject
,ReplaySubject
- Schedulers -
IdleScheduler
,FrameScheduler
- Utilities - Helper functions and tools
- Workers - Process streams in Web Workers
This library requires support for:
- ReadableStream (for all functionality)
- WritableStream (for Subjects)
- async/await (ES2017)
For older browsers, use the web-streams-polyfill:
import 'web-streams-polyfill/polyfill';
import { from, pipe, map } from 'web-streams-extensions';
We welcome contributions! Please see our Contributing Guide for details.