diff --git a/javascript/_utils.js b/javascript/_utils.js index e924928..2eaed4a 100644 --- a/javascript/_utils.js +++ b/javascript/_utils.js @@ -189,7 +189,11 @@ function toNgrams(inputArray, size) { ); } -function escapeRegExp(string) { +function escapeRegExp(string, wildcardMatching = false) { + if (wildcardMatching) { + // Escape all characters except asterisks and ?, which should be treated separately as placeholders. + return string.replace(/[-[\]{}()+.,\\^$|#\s]/g, '\\$&').replace(/\*/g, '.*').replace(/\?/g, '.'); + } return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string } function escapeHTML(unsafeText) { diff --git a/javascript/ext_chants.js b/javascript/ext_chants.js index 30de964..c32cc85 100644 --- a/javascript/ext_chants.js +++ b/javascript/ext_chants.js @@ -7,7 +7,10 @@ class ChantParser extends BaseTagParser { let tempResults = []; if (tagword !== "<" && tagword !== " x.terms.toLowerCase().includes(searchTerm) || x.name.toLowerCase().includes(searchTerm); + let filterCondition = x => { + let regex = new RegExp(escapeRegExp(searchTerm, true), 'i'); + return regex.test(x.terms.toLowerCase()) || regex.test(x.name.toLowerCase()); + }; tempResults = chants.filter(x => filterCondition(x)); // Filter by tagword } else { tempResults = chants; @@ -51,4 +54,4 @@ PARSERS.push(new ChantParser(CHANT_TRIGGER)); // Add our utility functions to their respective queues QUEUE_FILE_LOAD.push(load); QUEUE_SANITIZE.push(sanitize); -QUEUE_AFTER_CONFIG_CHANGE.push(load); \ No newline at end of file +QUEUE_AFTER_CONFIG_CHANGE.push(load); diff --git a/javascript/ext_embeddings.js b/javascript/ext_embeddings.js index 1a7ae86..9eb2536 100644 --- a/javascript/ext_embeddings.js +++ b/javascript/ext_embeddings.js @@ -16,7 +16,10 @@ class EmbeddingParser extends BaseTagParser { searchTerm = searchTerm.slice(3); } - let filterCondition = x => x[0].toLowerCase().includes(searchTerm) || x[0].toLowerCase().replaceAll(" ", "_").includes(searchTerm); + let filterCondition = x => { + let regex = new RegExp(escapeRegExp(searchTerm, true), 'i'); + return regex.test(x[0].toLowerCase()) || regex.test(x[0].toLowerCase().replaceAll(" ", "_")); + }; if (versionString) tempResults = embeddings.filter(x => filterCondition(x) && x[2] && x[2].toLowerCase() === versionString.toLowerCase()); // Filter by tagword @@ -62,4 +65,4 @@ PARSERS.push(new EmbeddingParser(EMB_TRIGGER)); // Add our utility functions to their respective queues QUEUE_FILE_LOAD.push(load); -QUEUE_SANITIZE.push(sanitize); \ No newline at end of file +QUEUE_SANITIZE.push(sanitize); diff --git a/javascript/ext_hypernets.js b/javascript/ext_hypernets.js index 3613b2a..8d6031a 100644 --- a/javascript/ext_hypernets.js +++ b/javascript/ext_hypernets.js @@ -7,7 +7,10 @@ class HypernetParser extends BaseTagParser { let tempResults = []; if (tagword !== "<" && tagword !== " x.toLowerCase().includes(searchTerm) || x.toLowerCase().replaceAll(" ", "_").includes(searchTerm); + let filterCondition = x => { + let regex = new RegExp(escapeRegExp(searchTerm, true), 'i'); + return regex.test(x.toLowerCase()) || regex.test(x.toLowerCase().replaceAll(" ", "_")); + }; tempResults = hypernetworks.filter(x => filterCondition(x[0])); // Filter by tagword } else { tempResults = hypernetworks; @@ -49,4 +52,4 @@ PARSERS.push(new HypernetParser(HYP_TRIGGER)); // Add our utility functions to their respective queues QUEUE_FILE_LOAD.push(load); -QUEUE_SANITIZE.push(sanitize); \ No newline at end of file +QUEUE_SANITIZE.push(sanitize); diff --git a/javascript/ext_loras.js b/javascript/ext_loras.js index 22c879c..da01d24 100644 --- a/javascript/ext_loras.js +++ b/javascript/ext_loras.js @@ -7,7 +7,10 @@ class LoraParser extends BaseTagParser { let tempResults = []; if (tagword !== "<" && tagword !== " x.toLowerCase().includes(searchTerm) || x.toLowerCase().replaceAll(" ", "_").includes(searchTerm); + let filterCondition = x => { + let regex = new RegExp(escapeRegExp(searchTerm, true), 'i'); + return regex.test(x.toLowerCase()) || regex.test(x.toLowerCase().replaceAll(" ", "_")); + }; tempResults = loras.filter(x => filterCondition(x[0])); // Filter by tagword } else { tempResults = loras; @@ -61,4 +64,4 @@ PARSERS.push(new LoraParser(LORA_TRIGGER)); // Add our utility functions to their respective queues QUEUE_FILE_LOAD.push(load); -QUEUE_SANITIZE.push(sanitize); \ No newline at end of file +QUEUE_SANITIZE.push(sanitize); diff --git a/javascript/ext_lycos.js b/javascript/ext_lycos.js index 94d5fe2..0e4ee3c 100644 --- a/javascript/ext_lycos.js +++ b/javascript/ext_lycos.js @@ -7,7 +7,10 @@ class LycoParser extends BaseTagParser { let tempResults = []; if (tagword !== "<" && tagword !== " x.toLowerCase().includes(searchTerm) || x.toLowerCase().replaceAll(" ", "_").includes(searchTerm); + let filterCondition = x => { + let regex = new RegExp(escapeRegExp(searchTerm, true), 'i'); + return regex.test(x.toLowerCase()) || regex.test(x.toLowerCase().replaceAll(" ", "_")); + }; tempResults = lycos.filter(x => filterCondition(x[0])); // Filter by tagword } else { tempResults = lycos; @@ -62,4 +65,4 @@ PARSERS.push(new LycoParser(LYCO_TRIGGER)); // Add our utility functions to their respective queues QUEUE_FILE_LOAD.push(load); -QUEUE_SANITIZE.push(sanitize); \ No newline at end of file +QUEUE_SANITIZE.push(sanitize); diff --git a/javascript/ext_styles.js b/javascript/ext_styles.js index 0401e9c..a12edf5 100644 --- a/javascript/ext_styles.js +++ b/javascript/ext_styles.js @@ -18,7 +18,10 @@ class StyleParser extends BaseTagParser { if (tagword !== matchGroups[1]) { let searchTerm = tagword.replace(matchGroups[1], ""); - let filterCondition = x => x[0].toLowerCase().includes(searchTerm) || x[0].toLowerCase().replaceAll(" ", "_").includes(searchTerm); + let filterCondition = x => { + let regex = new RegExp(escapeRegExp(searchTerm, true), 'i'); + return regex.test(x[0].toLowerCase()) || regex.test(x[0].toLowerCase().replaceAll(" ", "_")); + }; tempResults = styleNames.filter(x => filterCondition(x)); // Filter by tagword } else { tempResults = styleNames; @@ -64,4 +67,4 @@ PARSERS.push(new StyleParser(STYLE_TRIGGER)); // Add our utility functions to their respective queues QUEUE_FILE_LOAD.push(load); -QUEUE_SANITIZE.push(sanitize); \ No newline at end of file +QUEUE_SANITIZE.push(sanitize);