2018-03-06 22:01:22 +00:00

31 lines
839 B
TypeScript

import * as fs from "fs";
/* "Stoplist" of regular expressions to match against strings. */
export class Stoplist {
regexes: RegExp[];
constructor(slFilePath: string) {
let listExpressions = JSON.parse(fs.readFileSync(slFilePath, 'utf8'));
this.regexes = [];
if (listExpressions) {
for (var i = 0; i < listExpressions.length; i++) {
this.regexes.push(new RegExp(listExpressions[i]));
}
} else {
this.regexes = [];
}
}
// Check if an item is covered by the stoplist and reject it if so.
isRejected(itemName: string) {
for (var i = 0; i < this.regexes.length; i++) {
if (this.regexes[i].test(itemName)) {
return true;
}
}
return false;
}
}