-
Provides wrappers/enhancements for functions
-
Key capabilities:
- Logging, timing, retry, caching
- Control execution (debounce, throttle, lock, once)
- Transform input/output
- Error handling and safety
- Composition and chaining
A. Logging & Monitoring
log(fn)→ logs calls and resultstime(fn)→ measures execution timeprofile(fn)→ detailed table of durationchangelog(fn)→ logs changes in object outputsstats(fn)→ tracks number of calls, avg timewatch(fn)→ subscribe to outputsfeedback(fn, logger)→ logs input/output
B. Execution Control
once(fn)→ runs only onceafter(fn, n)→ runs after n callsbefore(fn, n)→ runs at most n timeslimit(fn, max)→ limits number of callslock(fn)→ prevents concurrent executiononcePerArgs(fn)→ runs once per argument comboqueue(fn)→ sequential executiondelayFn(fn, delay)→ delay executiondelayResult(fn, ms)→ delay return valuedelayEach(fn, delayMs)→ sequential with delayafterIdle(fn, timeout)→ browser idle executionsmartIdle(fn, options)→ idle execution with cancel
C. Error Handling & Safety
catch(fn, onError, fallback)→ error catchsandbox(fn, timeout)→ safe execution with error handlingsafeJson(fn)→ catches JSON parsing errorstimeLimit(fn, timeout)→ rejects after timeoutcancelable(fn)→ cancel in-flight promise
D. Input/Output Transformation
validate(fn, validator)→ validate argumentsmask(fn, masker)→ transform argumentsrestrict(fn, isAllowed)→ allow/disallow calltap(fn, tapFn)→ side effect without affecting returntransformOutput(fn, transformer)→ change outputlocale(fn, formatter)→ format input/outputunit(fn, unit)→ wraps output with value/unit/timestamp
E. Caching & Memoization
memo(fn)→ caches resultsreplay(fn)→ returns cached result for identical args
F. Functional Composition
pipe(...fns)→ left-to-right compositionchainable(fn)→ chain calls, collect results
G. Retry & Simulation
retry(fn, retries, delayMs)→ retry failing fnsimulate(fn, options)→ simulate failure/delay/corruptionrandomBehavior(fn, behaviors)→ random behaviorrandomizeArgs(fn)→ shuffle arguments
H. Undo & History
undoable(fn, inverseFn)→ supports undohistory(fn)→ tracks args/results
I. Conditional Execution
ensure(fn, validator)→ ensures output passesfilterArgs(fn, filterFn)→ executes only if condition passesdelayIf(fn, condition, delayMs)→ delays conditionallyalertOn(fn, condition)→ logs alerts if condition truewarnOnArgs(fn, warningFn)→ warns on suspicious inputpredict(fn, modelFn)→ adds prediction based on outputeventual(fn, checkFn, interval)→ polls until condition true
J. Repeat & Batch
repeat(fn, n)→ repeat function n timesbatch(fn, chunkSize, cb)→ executes in chunks
K. Miscellaneous
hook(fn, {before, after})→ pre/post hooksevolve(fn, evolver)→ mutate or extend output
FunctionWrapper
│
├─ Logging & Monitoring
│ ├─ log()
│ ├─ time()
│ ├─ profile()
│ ├─ changelog()
│ ├─ stats()
│ ├─ watch()
│ └─ feedback()
│
├─ Execution Control
│ ├─ once()
│ ├─ after()
│ ├─ before()
│ ├─ limit()
│ ├─ lock()
│ ├─ oncePerArgs()
│ ├─ queue()
│ ├─ delayFn()
│ ├─ delayResult()
│ ├─ delayEach()
│ ├─ afterIdle()
│ └─ smartIdle()
│
├─ Error Handling & Safety
│ ├─ catch()
│ ├─ sandbox()
│ ├─ safeJson()
│ ├─ timeLimit()
│ └─ cancelable()
│
├─ Input/Output Transformation
│ ├─ validate()
│ ├─ mask()
│ ├─ restrict()
│ ├─ tap()
│ ├─ transformOutput()
│ ├─ locale()
│ └─ unit()
│
├─ Caching & Memoization
│ ├─ memo()
│ └─ replay()
│
├─ Functional Composition
│ ├─ pipe()
│ └─ chainable()
│
├─ Retry & Simulation
│ ├─ retry()
│ ├─ simulate()
│ ├─ randomBehavior()
│ └─ randomizeArgs()
│
├─ Undo & History
│ ├─ undoable()
│ └─ history()
│
├─ Conditional Execution
│ ├─ ensure()
│ ├─ filterArgs()
│ ├─ delayIf()
│ ├─ alertOn()
│ ├─ warnOnArgs()
│ ├─ predict()
│ └─ eventual()
│
├─ Repeat & Batch
│ ├─ repeat()
│ └─ batch()
│
└─ Miscellaneous
├─ hook()
└─ evolve()
FunctionWrapper
├─ Logging & Monitoring
│ ├─ log(fn)
│ ├─ time(fn)
│ ├─ profile(fn)
│ ├─ changelog(fn)
│ ├─ feedback(fn, logger)
│ └─ watch(fn)
│
├─ Execution Control
│ ├─ once(fn)
│ ├─ after(fn, n)
│ ├─ before(fn, n)
│ ├─ lock(fn)
│ ├─ queue(fn)
│ ├─ repeat(fn, n)
│ ├─ delayFn(fn, delay)
│ ├─ timeLimit(fn, timeout)
│ ├─ sandbox(fn, timeout)
│ ├─ afterIdle(fn, timeout)
│ └─ smartIdle(fn, options)
│
├─ Error Handling & Safety
│ ├─ catch(fn, onError, fallback)
│ ├─ safeJson(fn)
│ ├─ undoable(fn, inverseFn)
│ ├─ cancelable(fn)
│ ├─ ensure(fn, validator)
│ └─ restrict(fn, isAllowed)
│
├─ Input/Output Transformation
│ ├─ tap(fn, tapFn)
│ ├─ mask(fn, masker)
│ ├─ transformOutput(fn, transformer)
│ ├─ evolve(fn, evolver)
│ ├─ locale(fn, formatter)
│ ├─ randomizeArgs(fn)
│ ├─ randomBehavior(fn, behaviors)
│ └─ predict(fn, modelFn)
│
├─ Caching & Memoization
│ ├─ memo(fn)
│ ├─ replay(fn)
│ └─ oncePerArgs(fn)
│
├─ Functional Composition
│ ├─ chainable(fn)
│ ├─ pipe(...fns)
│ └─ hook(fn, {before, after})
│
├─ Retry & Simulation
│ ├─ retry(fn, retries, delayMs)
│ └─ simulate(fn, {failRate, corrupt, delay})
│
├─ Conditional Execution
│ ├─ delayIf(fn, condition, delayMs)
│ ├─ eventual(fn, checkFn, interval)
│ ├─ filterArgs(fn, filterFn)
│ ├─ warnOnArgs(fn, warningFn)
│ └─ alertOn(fn, condition)
│
├─ Repeat & Batch
│ ├─ batch(fn, chunkSize, cb)
│ └─ delayEach(fn, delayMs)
│
└─ Unit & Stats
├─ unit(fn, unit)
└─ stats(fn)