« get me outta code hell

use regexes, avoid parse by letter (cur: 110k/sec) - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/upd8-util.js
diff options
context:
space:
mode:
author(quasar) nebula <towerofnix@gmail.com>2021-04-15 15:48:03 -0300
committer(quasar) nebula <towerofnix@gmail.com>2021-04-15 15:48:03 -0300
commite3baf8b7e3834b27a6ea6516e43d797570ff4c92 (patch)
tree3218cdcda2c13169981eec2ae1fda8fa1ed05641 /upd8-util.js
parentfbfe596c99924431b3e7105ab3c568bbf26f3fef (diff)
use regexes, avoid parse by letter (cur: 110k/sec)
Diffstat (limited to 'upd8-util.js')
-rw-r--r--upd8-util.js8
1 files changed, 8 insertions, 0 deletions
diff --git a/upd8-util.js b/upd8-util.js
index 30260f8d..3293d68a 100644
--- a/upd8-util.js
+++ b/upd8-util.js
@@ -427,3 +427,11 @@ module.exports.makeExtendedRegExp = (inputPatternStr, flags) => {
         .replace(/(^|[^\\])\s+/g, '$1');
     return new RegExp(cleanedPatternStr, flags);
 };
+
+
+// Stolen from here: https://stackoverflow.com/a/3561711
+//
+// There's a proposal for a native JS function like this, 8ut it's not even
+// past stage 1 yet: https://github.com/tc39/proposal-regex-escaping
+module.exports.escapeRegex = string =>
+    string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');