This package has two functions for [web streams](https://streams.spec.whatwg.org/).
npm install webstreams-converterThis package has two functions for web streams.
- webStreamsFrom(iterable) is stream.Readable.from implementation for web streams.
- webStreams2AsyncIterator(readableStream) is Async Iteration implementation for web streams in browser. web streams spec has this, but no browserimplementation this yet.
Zero dependency! And package working in node.js (> 18) and browser.
streams sepc:
https://streams.spec.whatwg.org/
MDN doc:
https://developer.mozilla.org/en-US/docs/Web/API/Streams_API
Parameter iterable is any value meet iterable
> strings or TypedArray will only in one chunk.
``javascript
import { webStreamsFrom, webStreams2AsyncIterator } from 'webstreams-converter';
function* testGen() {
yield 'a';
yield 'b';
yield 'c';
return 'ddd';
}
let result = '';
const read = webStreamsFrom(testGen());
`
Parameter readableStream is instance of ReadableStream
> strings or TypedArray will only in one chunk.
`javascript
import { webStreamsFrom, webStreams2AsyncIterator } from 'webstreams-converter';
const read = webStreamsFrom(['a', 'b', 'c']);
for await (const val of webStreams2AsyncIterator(read)) {
console.log(val);
}
`
`bash`
$ npm i webstreams-converter
#### ESM
`html`
#### UMD
`html``