@push-stream-std/push-expand (0.0.4)
Installation
@push-stream-std:registry=https://hub.kl1.tenere.ai/api/packages/push-stream-std/npm/npm install @push-stream-std/push-expand@0.0.4"@push-stream-std/push-expand": "0.0.4"About this package
push-expand
Recursively project each value to stream and merge.
Published as @push-stream-std/push-expand.
Synopsis
import { expand } from '@push-stream-std/push-expand';
import { values } from '@push-stream-std/push-values';
import { collect } from '@push-stream-std/push-collect';
const tree = expand(node => {
if (Array.isArray(node)) return node;
return [node];
});
values([1, [2, 3], [4, [5, 6]]])
.pipe(tree)
.pipe(collect((err, results) => {
console.log(results); // [1, 2, 3, 4, 5, 6]
}));
Install
npm config set @push-stream-std:registry https://hub.kl1.tenere.ai/api/packages/push-stream-std/npm/
npm config set -- //hub.kl1.tenere.ai/api/packages/push-stream-std/npm/:_authToken "$PACKAGE_TOKEN"
npm install @push-stream-std/push-expand
Description
Recursively expands each incoming value by calling a projector function. The projector can return an array, a stream source, or a single value. Arrays are iterated and each element is fed back through the expander. Stream sources are piped into the output. Supports maxDepth option to prevent infinite recursion. Uses O(1) amortized queue operations via head pointer pattern.
API
expand(projector, options)
projector-function(value)- Called for each incoming value. Returns a single value, an array, a push-stream source, ornull/undefined(which is skipped).options.maxDepth-number(default:100) - Maximum recursion depth to prevent infinite loops.
Returns a push-stream through stream. Pipe a source into it, pipe it to a sink. Values emitted by inner streams or arrays are recursively expanded while depth remains below maxDepth.
Tests
npm test
Tests cover identity pass-through, array expansion, nested expansion with depth limits, empty/null results, single value pass-through, and stream source handling.
Requirements
Node.js 18 or later. ESM only.
License
MIT