From d41853b617e1b0e7fa41309ff0d42611305c3149 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sat, 15 May 2021 19:08:48 -0300 Subject: bigass code refactor (no more legacy page writes) --- src/util/sugar.js | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/util/sugar.js') diff --git a/src/util/sugar.js b/src/util/sugar.js index c24c617c..79a271bf 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(); -- cgit 1.3.0-6-gf8a5