« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/sugar.js8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/util/sugar.js b/src/util/sugar.js
index 9970bad1..c24c617c 100644
--- a/src/util/sugar.js
+++ b/src/util/sugar.js
@@ -68,3 +68,11 @@ export function queue(array, max = 50) {
 export function delay(ms) {
     return new Promise(res => setTimeout(res, ms));
 }
+
+// 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
+export function escapeRegex(string) {
+    return string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
+}