Make filtering optionally case insensitive

Fixes #5.
This commit is contained in:
Florine W. Dekker 2019-12-01 21:52:04 +01:00
parent 2cb3f67b74
commit 69fef87cd9
Signed by: FWDekker
GPG Key ID: B1B567AF58D6EE0F
1 changed files with 5 additions and 1 deletions

View File

@ -86,7 +86,11 @@
filterBaseString(baseString) {
// Regex from https://stackoverflow.com/a/3561711/
const regexSafeAlphabet = this.alphabet.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
const alphabet = this.caseSensitive
? this.alphabet
: this.alphabet.toLowerCase() + this.alphabet.toUpperCase();
const regexSafeAlphabet = alphabet.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&");
return baseString.replace(new RegExp(`[^${regexSafeAlphabet}]`, "g"), "");
}
}