@push-stream-std/push-stringify (0.0.5)
Installation
@push-stream-std:registry=https://hub.kl1.tenere.ai/api/packages/push-stream-std/npm/npm install @push-stream-std/push-stringify@0.0.5"@push-stream-std/push-stringify": "0.0.5"About this package
push-stringify
JSON.stringify through stream with array and NDJSON output modes.
Published as @push-stream-std/push-stringify.
Synopsis
import { stringify, array, lines } from '@push-stream-std/push-stringify';
const source = values([{ a: 1 }, { b: 2 }, { c: 3 }]);
source.pipe(stringify()).pipe(log()); // "{\"a\":1}" "{\"b\":2}" "{\"c\":3}"
source.pipe(array()).pipe(log()); // "[{\"a\":1},{\"b\":2},{\"c\":3}]"
source.pipe(lines()).pipe(log()); // "{\"a\":1}\n{\"b\":2}\n{\"c\":3}\n"
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-stringify
Description
A push-stream through that buffers all incoming values and emits the JSON-serialized result on end. Three modes are available: stringify emits each value as a separate JSON string, array emits all values as a single JSON array, and lines emits each value as a line of newline-delimited JSON (NDJSON). All values are buffered in memory until the stream ends.
API
stringify(options)
Creates a through stream that emits each value as an individual JSON string.
- options
object(optional) – Reserved for future use. - Returns A through object with
pipe(),write(),end(),abort(),resume(),source,sink,paused,ended.
array(options)
Creates a through stream that emits the entire buffer as a single JSON array string on end.
- options
object(optional) – Reserved for future use. - Returns A through object.
lines(options)
Creates a through stream that emits each value as a JSON string followed by '\n' (NDJSON format).
- options
object(optional) – Reserved for future use. - Returns A through object.
Tests
npm test
Requirements
Node.js 18 or later. ESM only.
License
MIT