push-stream-std

@push-stream-std/push-split (0.0.3)

Published 2026-07-19 21:14:25 +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-split@0.0.3
"@push-stream-std/push-split": "0.0.3"

About this package

push-split

Split a push-stream of strings or buffers by a delimiter.

Published as @push-stream-std/push-split.

Synopsis

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

values(['hello\nworld\nfoo'])
  .pipe(split('\n'))
  .pipe(collect((err, results) => {
    console.log(results); // ['hello', 'world', 'foo']
  }));

With a regex delimiter and mapper:

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

values(['a=1,b=2,c=3'])
  .pipe(split(',', (part) => {
    const [key, val] = part.split('=');
    return { [key]: Number(val) };
  }))
  .pipe(collect((err, results) => {
    console.log(results); // [{a: 1}, {b: 2}, {c: 3}]
  }));

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-split

Description

A push-stream through operator that splits incoming string or buffer chunks by a delimiter and emits the resulting parts. Supports both string and RegExp delimiters. An optional mapper function can transform each part before emission — returning null or undefined skips that part. Handles partial chunks by maintaining an internal buffer across writes. As a safety measure, if the internal buffer grows beyond 1MB without encountering a delimiter, the accumulated content is emitted as-is and the buffer is reset.

API

split(delimiter, [mapper])

split(mapper)

When the first argument is a function, it is treated as a mapper and the delimiter defaults to newline (\n).

  • delimiter (string or RegExp, optional) — The delimiter used to split incoming data. String delimiters use indexOf; RegExp delimiters use match. If omitted, the first argument is treated as a mapper.
  • mapper (function, optional) — function(part) — Called with each split part. Return the transformed value to emit, or null/undefined to skip the part.

Returns a push-stream through. Writes accumulate data into an internal buffer; each time the delimiter is found, the preceding content is emitted. When the source ends, any remaining buffered content is emitted as a final part.

Tests

npm test

Tests cover string delimiter splitting, RegExp delimiter splitting, mapper transformation, partial chunk buffering across multiple writes, large buffer safety emission, empty stream, and trailing content after source end.

Requirements

Node.js 18 or later. ESM only.

License

MIT

Dependencies

Dependencies

ID Version
push-stream-base ^1.0.0

Keywords

push-stream stream split delimiter
Details
npm
2026-07-19 21:14:25 +00:00
0
MIT
4.0 KiB
Assets (1)
Versions (7) View all
0.0.10 2026-07-21
0.0.9 2026-07-20
0.0.8 2026-07-20
0.0.7 2026-07-20
0.0.6 2026-07-19