@push-stream-std/push-split (0.0.3)
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 useindexOf; RegExp delimiters usematch. 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, ornull/undefinedto 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 |