push-stream-std

@push-stream-std/push-recursive-flatten (0.0.4)

Published 2026-07-19 23:32:00 +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-recursive-flatten@0.0.4
"@push-stream-std/push-recursive-flatten": "0.0.4"

About this package

push-recursive-flatten

Recursively flatten nested push-streams up to a given depth.

Published as @push-stream-std/push-recursive-flatten.

Synopsis

import { flatten } from '@push-stream-std/push-recursive-flatten';
import { values } from '@push-stream-std/push-values';
import { collect } from '@push-stream-std/push-collect';

const inner = values(['c', 'd']);
const outer = values([inner, 'e']);
const nested = values([outer, 'f']);

nested
  .pipe(flatten(2))
  .pipe(collect((err, results) => {
    console.log(results); // ['c', 'd', 'e', 'f']
  }));

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-recursive-flatten

Description

A push-stream through operator that recursively flattens nested stream values. When a value is itself a push-stream source (detected by the presence of pipe, write, or resume), it is piped into the flattening pipeline and its values are emitted inline. The depth parameter controls how many levels of nesting are unwrapped. Uses O(1) amortized internal buffering via a head pointer pattern. Non-stream values pass through unchanged.

API

flatten([depth])

  • depth (number, default Infinity) — Maximum nesting depth to flatten. At depth 0, streams are treated as plain values and passed through. At depth 1, one level of nesting is flattened, and so on.

Returns a push-stream through. Pipe a source in; any value that is a push-stream source will be flattened inline up to the specified depth.

Tests

npm test

Tests cover flattening single-level and multi-level nested streams, respecting the depth parameter, mixed stream and non-stream values, and empty nested streams.

Requirements

Node.js 18 or later. ESM only.

License

MIT

Keywords

push-stream stream flatten recursive
Details
npm
2026-07-19 23:32:00 +00:00
0
MIT
3.6 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