diff options
author | (quasar) nebula <towerofnix@gmail.com> | 2021-05-15 19:08:48 -0300 |
---|---|---|
committer | (quasar) nebula <towerofnix@gmail.com> | 2021-05-25 19:07:09 -0300 |
commit | d41853b617e1b0e7fa41309ff0d42611305c3149 (patch) | |
tree | 13d4c0312f95efb22bb103fd3df07f6f0bbb2a79 /src/util/sugar.js | |
parent | 4fd0d8b5485f94ad67d32bc6a9273ac4727a6475 (diff) |
bigass code refactor (no more legacy page writes)
Diffstat (limited to 'src/util/sugar.js')
-rw-r--r-- | src/util/sugar.js | 11 |
1 files changed, 11 insertions, 0 deletions
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(); |