web-streams-extensions
Version:
A comprehensive collection of helper methods for WebStreams with built-in backpressure support, inspired by ReactiveExtensions
29 lines (28 loc) • 1.19 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.pipe = pipe;
const _readable_like_js_1 = require("./_readable-like.cjs");
const through_js_1 = require("./operators/through.cjs");
const is_transform_js_1 = require("./utils/is-transform.cjs");
function pipe(src, ...args) {
if ((0, _readable_like_js_1.isReadableLike)(src)) {
src = src.readable;
}
// Extract options from the end of arguments if present
let options = { highWaterMark: 16 }; // default highWaterMark
let operators = args;
// Check if last argument is options (QueuingStrategy)
const lastArg = args[args.length - 1];
if (lastArg && typeof lastArg === 'object' &&
!lastArg.readable && !lastArg.writable &&
typeof lastArg.pipeThrough !== 'function' &&
(lastArg.highWaterMark !== undefined || lastArg.size !== undefined)) {
options = { ...options, ...lastArg };
operators = args.slice(0, -1);
}
return operators
.map(x => (0, is_transform_js_1.isTransform)(x) ? (0, through_js_1.through)(x) : x)
.reduce((stream, operator) => {
return operator(stream, options);
}, src);
}