« 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/sugar.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/sugar.js')
-rw-r--r--src/util/sugar.js11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/util/sugar.js b/src/util/sugar.js
index c24c617..79a271b 100644
--- a/src/util/sugar.js
+++ b/src/util/sugar.js
@@ -76,3 +76,14 @@ export function delay(ms) {
 export function escapeRegex(string) {
     return string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
 }
+
+export function bindOpts(fn, bind) {
+    const bindIndex = bind[bindOpts.bindIndex] ?? 1;
+
+    return (...args) => {
+        const opts = args[bindIndex] ?? {};
+        return fn(...args.slice(0, bindIndex), {...bind, ...opts});
+    };
+}
+
+bindOpts.bindIndex = Symbol();