stream-chain
Version:
Chain functions, generators, Node streams, and Web streams into a pipeline with backpressure support.
42 lines (37 loc) • 1.5 kB
TypeScript
/// <reference types="node" />
import {TypedTransform} from '../typed-streams.js';
/**
* Options for the stringer stream used to control the output.
*/
interface StringerOptions {
/** The prefix string. It is prepended to the output. Defaults to `""`. */
prefix?: string;
/** The suffix string. It is appended to the output. Defaults to `""`. */
suffix?: string;
/** The separator string used between items. Defaults to `"\n"`. */
separator?: string;
/**
* The empty value string. It is used when no values were streamed. Defaults to `prefix + suffix`.
* See {@link StringerOptions.prefix} and {@link StringerOptions.suffix}.
*/
emptyValue?: string;
/**
* The optional replacer function used by `JSON.stringify()`.
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify
*/
replacer?: (this: unknown, key: string, value: unknown) => unknown;
/**
* The optional space string or number used by `JSON.stringify()`.
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify
*/
space?: string | number;
}
/**
* Returns a JSONL stringer as a Transform stream.
* @param options options for the stringer stream (see {@link StringerOptions})
* @returns a Transform stream
*/
declare function stringer<T>(options?: StringerOptions): TypedTransform<T, string>;
export default stringer;
export {stringer as stringerStream};
export type {StringerOptions};