push-stream-std

@push-stream-std/push-expand (0.0.7)

Published 2026-07-21 03:58:22 +00:00 by Dvorak

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.7
"@push-stream-std/push-expand": "0.0.7"

About this package

@push-stream-std/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-pushable';
import { collect } from '@push-stream-std/push-concat';

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

Why

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, or null/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 22 or later. ESM only.

Keywords

push-stream stream expand recursive flatMap
Details
npm
2026-07-21 03:58:22 +00:00
1
SEE LICENSE IN LICENSE
latest
3.9 KiB
Assets (1)
Versions (5) View all
0.0.7 2026-07-21
0.0.6 2026-07-20
0.0.5 2026-07-20
0.0.4 2026-07-19
0.0.3 2026-07-19