diff options
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 |
commit | e3baf8b7e3834b27a6ea6516e43d797570ff4c92 (patch) | |
tree | 3218cdcda2c13169981eec2ae1fda8fa1ed05641 /upd8-util.js | |
parent | fbfe596c99924431b3e7105ab3c568bbf26f3fef (diff) |
use regexes, avoid parse by letter (cur: 110k/sec)
Diffstat (limited to 'upd8-util.js')
-rw-r--r-- | upd8-util.js | 8 |
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, '\\$&'); |