From e3baf8b7e3834b27a6ea6516e43d797570ff4c92 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Thu, 15 Apr 2021 15:48:03 -0300 Subject: use regexes, avoid parse by letter (cur: 110k/sec) --- upd8-util.js | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'upd8-util.js') 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, '\\$&'); -- cgit 1.3.0-6-gf8a5