A comprehensive collection of helper methods for WebStreams with built-in backpressure support, inspired by ReactiveExtensions
npm install web-streams-extensionsbash
npm install web-streams-extensions
`
Basic Usage
`typescript
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]
`
⚠️ReadableStreams are not recoverable. If you start and consume a stream, that instance cannot be reused.
API Reference
- 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
Browser Compatibility
This library requires support for:
- ReadableStream (for all functionality)
- WritableStream (for Subjects)
- async/await (ES2017)
For older browsers, use the web-streams-polyfill:
`ts
import 'web-streams-polyfill/polyfill';
import { from, pipe, map } from 'web-streams-extensions';
``