@jawis/stdio-filter
Version:
Filter the stdio from console applications.
42 lines (41 loc) • 1.84 kB
TypeScript
/// <reference types="node" />
/// <reference types="node" />
/**
*
* - onStdio callback is called with each line, making it easy to handle the stdio stream.
* - newline is not included in the line given to onStdio.
* - onStdio callback is called with undefined, when the line is fully filtered.
* - If a partial line is received, it might be emitted without filtering.
* - timeout tells when buffered data is emitted, if it hasn't been terminated by a newline.
* - If timeout is 0, flush will be performed sync. (useful for testing)
*
* impl
* - By ensuring we can handle re-entry for async cases, we ensure all async workloads are handled.
* It's a slightly stricter constraint, but it makes writing test cases easier, because they are sync,
* and any async sequence can be simulated that way.
* re-entry isn't that important to support. Async consistency is a must, however.
* That's why sync re-entry isn't implemented.
*
* states
* state 1: No buffered data and no active timeout handle.
* state 2: Buffered data and active timeout handle.
* state 3: Partial emitted and no active timeout handle.
*/
export declare const makeStdioLinearizer_old: (onStdio: (str?: string) => void, includeLine: (str: string) => boolean, timeout?: number) => (data: Buffer | string) => void;
/**
*
*/
export type MakeMapLineDeps = {
ignoreLiteralPrefixes?: string[];
mapLineBeforeFilter?: (line: string) => string;
};
export declare const makeMapLine: (deps: MakeMapLineDeps) => (line: string) => string;
/**
*
*/
export type MakeIncludeLineDeps = {
ignoreLiteralLines?: string[];
includeLine?: (line: string) => boolean;
includeJson?: (obj: any) => boolean;
} & MakeMapLineDeps;
export declare const makeIncludeLine: (deps: MakeIncludeLineDeps) => (rawLine: string) => boolean;