stream-chain
Advanced tools
Comparing version 3.0.1 to 3.1.0
{ | ||
"name": "stream-chain", | ||
"version": "3.0.1", | ||
"version": "3.1.0", | ||
"description": "Chain functions as transform streams.", | ||
@@ -5,0 +5,0 @@ "type": "commonjs", |
@@ -182,2 +182,4 @@ # stream-chain [![NPM version][npm-img]][npm-url] | ||
* [readable.resume()](https://nodejs.org/api/stream.html#stream_readable_resume). | ||
* *(Since 3.1.0)* If a value is a web stream object (like `ReadableStream` or `WritableStream`), it is adapted to a corresponding Node stream and included in the pipeline. | ||
* Note that the support of web streams is still experimental in Node. | ||
* `options` is an optional object detailed in the [Node's documentation](https://nodejs.org/api/stream.html#stream_new_stream_duplex_options). | ||
@@ -209,2 +211,3 @@ * The default options is this object: | ||
- 3.1.0 *Added a seamless support for web streams.* | ||
- 3.0.1 *First release of 3.0. See [wiki](https://github.com/uhop/stream-chain/wiki) for details.* | ||
@@ -211,0 +214,0 @@ - 3.0.0 *New major version. Unreleased.* |
'use strict'; | ||
const {Duplex} = require('stream'); | ||
const {Readable, Writable,Duplex} = require('stream'); | ||
const defs = require('./defs'); | ||
@@ -31,2 +31,15 @@ const gen = require('./gen'); | ||
const isReadableWebStream = obj => | ||
obj && globalThis.ReadableStream && obj instanceof globalThis.ReadableStream; | ||
const isWritableWebStream = obj => | ||
obj && globalThis.WritableStream && obj instanceof globalThis.WritableStream; | ||
const isDuplexWebStream = obj => | ||
obj && | ||
globalThis.ReadableStream && | ||
obj.readable instanceof globalThis.ReadableStream && | ||
globalThis.WritableStream && | ||
obj.writable instanceof globalThis.WritableStream; | ||
const groupFunctions = (output, fn, index, fns) => { | ||
@@ -41,2 +54,14 @@ if ( | ||
} | ||
if (isDuplexWebStream(fn)) { | ||
output.push(Duplex.fromWeb(fn, {objectMode: true})); | ||
return output; | ||
} | ||
if (!index && isReadableWebStream(fn)) { | ||
output.push(Readable.fromWeb(fn, {objectMode: true})); | ||
return output; | ||
} | ||
if (index === fns.length - 1 && isWritableWebStream(fn)) { | ||
output.push(Writable.fromWeb(fn, {objectMode: true})); | ||
return output; | ||
} | ||
if (typeof fn != 'function') | ||
@@ -71,2 +96,11 @@ throw TypeError('Item #' + index + ' is not a proper stream, nor a function.'); | ||
} | ||
if (isDuplexWebStream(fn)) { | ||
return Duplex.fromWeb(fn, {objectMode: true}); | ||
} | ||
if (!index && isReadableWebStream(fn)) { | ||
return Readable.fromWeb(fn, {objectMode: true}); | ||
} | ||
if (index === fns.length - 1 && isWritableWebStream(fn)) { | ||
return Writable.fromWeb(fn, {objectMode: true}); | ||
} | ||
if (typeof fn == 'function') return chain.asStream(fn); // a function | ||
@@ -73,0 +107,0 @@ throw TypeError('Item #' + index + ' is not a proper stream, nor a function.'); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
41747
952
228
0