text-stream-search
Version:
Searches for occurrences of a given search term in Node.js text streams
31 lines (30 loc) • 1.42 kB
TypeScript
import { TextAccumulator } from "../text-accumulator.js";
import { RejectFunction } from "../types/reject-function.js";
import { ResolveFunction } from "../types/resolve-function.js";
import { Search } from "../types/search.js";
/**
* StringSearch is the search for a particular string in the text stream.
* The search is over once the string is found.
* It reports success to the given resolve function once when it finds the query string.
* When reaching the given timeoutDuration, it abourts the search and calls the given reject function.
*/
export declare class StringSearch implements Search {
/** the resolve function to call when the searchText is found */
resolve: ResolveFunction;
/** the reject function to call when the search expires */
reject: RejectFunction;
/** time after which this search expires and should be aborted, in milliseconds */
timeoutDuration?: number;
/** the stream content that has accumulated so far */
text: TextAccumulator;
/** the search string to look for in the received text */
searchText: string;
constructor(query: string, resolve: ResolveFunction, reject: RejectFunction, text: TextAccumulator, timeout?: number);
/**
* Checks the given text for the searchText.
* Calls the resolve function when it finds it.
*/
scan(): void;
/** called after this subscription times out */
private onTimeout;
}