text-stream-search
Version:
Searches for occurrences of a given search term in Node.js text streams
31 lines (30 loc) • 1.27 kB
TypeScript
import { SimpleReadableStream } from "./types/simple-readable-stream.js";
/**
* TextStreamSearch searches ReadableStreams for text and regexes.
*/
export default class TextStreamSearch {
/**
* Subscriptions contains all the requests from users of this library
* to be notified when a particular text or regex shows up in the text stream.
*/
private searchList;
/** the output captured so far */
private streamText;
constructor(stream: SimpleReadableStream);
/** Fulltext returns the complete content captured from this stream so far. */
fullText(): string;
/**
* WaitForRegex returns a promise that resolves with the matching text
* when the given RegExp shows up in observed stream.
* If a timeout is given, aborts after the given duration.
*/
waitForRegex(regex: RegExp, timeout?: number): Promise<string>;
/**
* WaitForText returns a promise that resolves with the matching text
* when the given text shows up in the observed stream.
* If a timeout is given, aborts after the given duration.
*/
waitForText(text: string, timeout?: number): Promise<string>;
/** OnStreamData is called when new text arrives on the input stream. */
private onStreamData;
}