text-stream-search
Version:
Searches for occurrences of a given search term in Node.js text streams
30 lines (29 loc) • 1.08 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const base_search_1 = __importDefault(require("./base-search"));
// calls the given handler exactly one time
// then text matches the given regex
class RegexSearch extends base_search_1.default {
constructor(regex, accumulator, resolve, reject, timeout) {
super(accumulator, resolve, reject, timeout);
this.searchRegexp = regex;
}
// checks for matches
async check(text) {
if (this.matches(text)) {
await this.foundMatch();
}
}
// returns the display name for debug / error messages
getDisplayName() {
return `regex '${this.searchRegexp.toString()}'`;
}
// returns whether the given text contains the search text this search is looking for
matches(text) {
return this.searchRegexp.test(text);
}
}
exports.default = RegexSearch;