@vielzeug/toolkit 1.1.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +419 -0
- package/dist/array/chunk.cjs +2 -2
- package/dist/array/chunk.cjs.map +1 -1
- package/dist/array/chunk.d.ts +29 -0
- package/dist/array/chunk.d.ts.map +1 -0
- package/dist/array/chunk.js +22 -24
- package/dist/array/chunk.js.map +1 -1
- package/dist/array/contains.cjs +2 -2
- package/dist/array/contains.cjs.map +1 -1
- package/dist/array/contains.d.ts +19 -0
- package/dist/array/contains.d.ts.map +1 -0
- package/dist/array/contains.js +12 -9
- package/dist/array/contains.js.map +1 -1
- package/dist/array/fold.cjs +2 -0
- package/dist/array/fold.cjs.map +1 -0
- package/dist/array/fold.d.ts +21 -0
- package/dist/array/fold.d.ts.map +1 -0
- package/dist/array/fold.js +19 -0
- package/dist/array/fold.js.map +1 -0
- package/dist/array/group.cjs +2 -2
- package/dist/array/group.cjs.map +1 -1
- package/dist/array/group.d.ts +19 -0
- package/dist/array/group.d.ts.map +1 -0
- package/dist/array/group.js +18 -15
- package/dist/array/group.js.map +1 -1
- package/dist/array/index.d.ts +16 -0
- package/dist/array/index.d.ts.map +1 -0
- package/dist/array/keyBy.cjs +2 -0
- package/dist/array/keyBy.cjs.map +1 -0
- package/dist/array/keyBy.d.ts +20 -0
- package/dist/array/keyBy.d.ts.map +1 -0
- package/dist/array/keyBy.js +19 -0
- package/dist/array/keyBy.js.map +1 -0
- package/dist/array/list.cjs +2 -2
- package/dist/array/list.cjs.map +1 -1
- package/dist/array/list.d.ts +58 -0
- package/dist/array/list.d.ts.map +1 -0
- package/dist/array/list.js +103 -106
- package/dist/array/list.js.map +1 -1
- package/dist/array/pick.cjs +2 -2
- package/dist/array/pick.cjs.map +1 -1
- package/dist/array/pick.d.ts +19 -0
- package/dist/array/pick.d.ts.map +1 -0
- package/dist/array/pick.js +15 -14
- package/dist/array/pick.js.map +1 -1
- package/dist/array/remoteList.cjs +2 -2
- package/dist/array/remoteList.cjs.map +1 -1
- package/dist/array/remoteList.d.ts +64 -0
- package/dist/array/remoteList.d.ts.map +1 -0
- package/dist/array/remoteList.js +121 -122
- package/dist/array/remoteList.js.map +1 -1
- package/dist/array/replace.cjs +2 -0
- package/dist/array/replace.cjs.map +1 -0
- package/dist/array/replace.d.ts +20 -0
- package/dist/array/replace.d.ts.map +1 -0
- package/dist/array/replace.js +19 -0
- package/dist/array/replace.js.map +1 -0
- package/dist/array/rotate.cjs +2 -0
- package/dist/array/rotate.cjs.map +1 -0
- package/dist/array/rotate.d.ts +22 -0
- package/dist/array/rotate.d.ts.map +1 -0
- package/dist/array/rotate.js +19 -0
- package/dist/array/rotate.js.map +1 -0
- package/dist/array/search.cjs +2 -2
- package/dist/array/search.cjs.map +1 -1
- package/dist/array/search.d.ts +19 -0
- package/dist/array/search.d.ts.map +1 -0
- package/dist/array/search.js +23 -13
- package/dist/array/search.js.map +1 -1
- package/dist/array/select.cjs +2 -2
- package/dist/array/select.cjs.map +1 -1
- package/dist/array/select.d.ts +21 -0
- package/dist/array/select.d.ts.map +1 -0
- package/dist/array/select.js +16 -15
- package/dist/array/select.js.map +1 -1
- package/dist/array/sort.cjs +2 -2
- package/dist/array/sort.cjs.map +1 -1
- package/dist/array/sort.d.ts +26 -0
- package/dist/array/sort.d.ts.map +1 -0
- package/dist/array/sort.js +18 -12
- package/dist/array/sort.js.map +1 -1
- package/dist/array/toggle.cjs +2 -0
- package/dist/array/toggle.cjs.map +1 -0
- package/dist/array/toggle.d.ts +29 -0
- package/dist/array/toggle.d.ts.map +1 -0
- package/dist/array/toggle.js +9 -0
- package/dist/array/toggle.js.map +1 -0
- package/dist/array/uniq.cjs +2 -2
- package/dist/array/uniq.cjs.map +1 -1
- package/dist/array/uniq.d.ts +21 -0
- package/dist/array/uniq.d.ts.map +1 -0
- package/dist/array/uniq.js +15 -17
- package/dist/array/uniq.js.map +1 -1
- package/dist/async/attempt.cjs +2 -2
- package/dist/async/attempt.cjs.map +1 -1
- package/dist/async/attempt.d.ts +40 -0
- package/dist/async/attempt.d.ts.map +1 -0
- package/dist/async/attempt.js +19 -14
- package/dist/async/attempt.js.map +1 -1
- package/dist/async/defer.cjs +2 -2
- package/dist/async/defer.cjs.map +1 -1
- package/dist/async/defer.d.ts +23 -0
- package/dist/async/defer.d.ts.map +1 -0
- package/dist/async/defer.js +12 -9
- package/dist/async/defer.js.map +1 -1
- package/dist/async/index.d.ts +12 -0
- package/dist/async/index.d.ts.map +1 -0
- package/dist/async/parallel.cjs +2 -2
- package/dist/async/parallel.cjs.map +1 -1
- package/dist/async/parallel.d.ts +31 -0
- package/dist/async/parallel.d.ts.map +1 -0
- package/dist/async/parallel.js +26 -27
- package/dist/async/parallel.js.map +1 -1
- package/dist/async/pool.cjs +2 -2
- package/dist/async/pool.cjs.map +1 -1
- package/dist/async/pool.d.ts +21 -0
- package/dist/async/pool.d.ts.map +1 -0
- package/dist/async/pool.js +23 -21
- package/dist/async/pool.js.map +1 -1
- package/dist/async/predict.cjs +2 -2
- package/dist/async/predict.cjs.map +1 -1
- package/dist/async/predict.d.ts +24 -0
- package/dist/async/predict.d.ts.map +1 -0
- package/dist/async/predict.js +10 -12
- package/dist/async/predict.js.map +1 -1
- package/dist/async/queue.cjs +2 -2
- package/dist/async/queue.cjs.map +1 -1
- package/dist/async/queue.d.ts +43 -0
- package/dist/async/queue.d.ts.map +1 -0
- package/dist/async/queue.js +52 -56
- package/dist/async/queue.js.map +1 -1
- package/dist/async/race.cjs +2 -2
- package/dist/async/race.cjs.map +1 -1
- package/dist/async/race.d.ts +16 -0
- package/dist/async/race.d.ts.map +1 -0
- package/dist/async/race.js +8 -7
- package/dist/async/race.js.map +1 -1
- package/dist/async/retry.cjs +2 -2
- package/dist/async/retry.cjs.map +1 -1
- package/dist/async/retry.d.ts +32 -0
- package/dist/async/retry.d.ts.map +1 -0
- package/dist/async/retry.js +19 -24
- package/dist/async/retry.js.map +1 -1
- package/dist/async/scheduler.cjs +2 -0
- package/dist/async/scheduler.cjs.map +1 -0
- package/dist/async/scheduler.d.ts +51 -0
- package/dist/async/scheduler.d.ts.map +1 -0
- package/dist/async/scheduler.js +43 -0
- package/dist/async/scheduler.js.map +1 -0
- package/dist/async/sleep.cjs +2 -2
- package/dist/async/sleep.cjs.map +1 -1
- package/dist/async/sleep.d.ts +16 -0
- package/dist/async/sleep.d.ts.map +1 -0
- package/dist/async/sleep.js +11 -11
- package/dist/async/sleep.js.map +1 -1
- package/dist/async/waitFor.cjs +2 -2
- package/dist/async/waitFor.cjs.map +1 -1
- package/dist/async/waitFor.d.ts +33 -0
- package/dist/async/waitFor.d.ts.map +1 -0
- package/dist/async/waitFor.js +29 -36
- package/dist/async/waitFor.js.map +1 -1
- package/dist/date/expires.cjs +2 -2
- package/dist/date/expires.cjs.map +1 -1
- package/dist/date/expires.d.ts +15 -0
- package/dist/date/expires.d.ts.map +1 -0
- package/dist/date/expires.js +11 -10
- package/dist/date/expires.js.map +1 -1
- package/dist/date/index.d.ts +4 -0
- package/dist/date/index.d.ts.map +1 -0
- package/dist/date/interval.cjs +2 -2
- package/dist/date/interval.cjs.map +1 -1
- package/dist/date/interval.d.ts +25 -0
- package/dist/date/interval.d.ts.map +1 -0
- package/dist/date/interval.js +31 -37
- package/dist/date/interval.js.map +1 -1
- package/dist/date/timeDiff.cjs +2 -2
- package/dist/date/timeDiff.cjs.map +1 -1
- package/dist/date/timeDiff.d.ts +24 -0
- package/dist/date/timeDiff.d.ts.map +1 -0
- package/dist/date/timeDiff.js +58 -25
- package/dist/date/timeDiff.js.map +1 -1
- package/dist/function/assert.cjs +2 -3
- package/dist/function/assert.cjs.map +1 -1
- package/dist/function/assert.d.ts +38 -0
- package/dist/function/assert.d.ts.map +1 -0
- package/dist/function/assert.js +13 -11
- package/dist/function/assert.js.map +1 -1
- package/dist/function/assertParams.cjs +2 -2
- package/dist/function/assertParams.cjs.map +1 -1
- package/dist/function/assertParams.d.ts +24 -0
- package/dist/function/assertParams.d.ts.map +1 -0
- package/dist/function/assertParams.js +13 -12
- package/dist/function/assertParams.js.map +1 -1
- package/dist/function/compare.cjs +2 -2
- package/dist/function/compare.cjs.map +1 -1
- package/dist/function/compare.d.ts +23 -0
- package/dist/function/compare.d.ts.map +1 -0
- package/dist/function/compare.js +22 -21
- package/dist/function/compare.js.map +1 -1
- package/dist/function/compareBy.cjs +2 -2
- package/dist/function/compareBy.cjs.map +1 -1
- package/dist/function/compareBy.d.ts +24 -0
- package/dist/function/compareBy.d.ts.map +1 -0
- package/dist/function/compareBy.js +15 -14
- package/dist/function/compareBy.js.map +1 -1
- package/dist/function/compose.cjs +2 -2
- package/dist/function/compose.cjs.map +1 -1
- package/dist/function/compose.d.ts +22 -0
- package/dist/function/compose.d.ts.map +1 -0
- package/dist/function/compose.js +10 -13
- package/dist/function/compose.js.map +1 -1
- package/dist/function/curry.cjs +2 -2
- package/dist/function/curry.cjs.map +1 -1
- package/dist/function/curry.d.ts +21 -0
- package/dist/function/curry.d.ts.map +1 -0
- package/dist/function/curry.js +8 -7
- package/dist/function/curry.js.map +1 -1
- package/dist/function/debounce.cjs +2 -2
- package/dist/function/debounce.cjs.map +1 -1
- package/dist/function/debounce.d.ts +12 -0
- package/dist/function/debounce.d.ts.map +1 -0
- package/dist/function/debounce.js +34 -26
- package/dist/function/debounce.js.map +1 -1
- package/dist/function/fp.cjs +2 -2
- package/dist/function/fp.cjs.map +1 -1
- package/dist/function/fp.d.ts +24 -0
- package/dist/function/fp.d.ts.map +1 -0
- package/dist/function/fp.js +6 -10
- package/dist/function/fp.js.map +1 -1
- package/dist/function/index.d.ts +13 -0
- package/dist/function/index.d.ts.map +1 -0
- package/dist/function/memo.cjs +2 -2
- package/dist/function/memo.cjs.map +1 -1
- package/dist/function/memo.d.ts +30 -0
- package/dist/function/memo.d.ts.map +1 -0
- package/dist/function/memo.js +16 -24
- package/dist/function/memo.js.map +1 -1
- package/dist/function/once.cjs +2 -2
- package/dist/function/once.cjs.map +1 -1
- package/dist/function/once.d.ts +24 -0
- package/dist/function/once.d.ts.map +1 -0
- package/dist/function/once.js +10 -10
- package/dist/function/once.js.map +1 -1
- package/dist/function/pipe.cjs +2 -2
- package/dist/function/pipe.cjs.map +1 -1
- package/dist/function/pipe.d.ts +23 -0
- package/dist/function/pipe.d.ts.map +1 -0
- package/dist/function/pipe.js +10 -10
- package/dist/function/pipe.js.map +1 -1
- package/dist/function/throttle.cjs +2 -2
- package/dist/function/throttle.cjs.map +1 -1
- package/dist/function/throttle.d.ts +21 -0
- package/dist/function/throttle.d.ts.map +1 -0
- package/dist/function/throttle.js +45 -37
- package/dist/function/throttle.js.map +1 -1
- package/dist/index.cjs +1 -2
- package/dist/index.d.ts +77 -2813
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +75 -253
- package/dist/math/abs.cjs +2 -2
- package/dist/math/abs.cjs.map +1 -1
- package/dist/math/abs.d.ts +17 -0
- package/dist/math/abs.d.ts.map +1 -0
- package/dist/math/abs.js +7 -6
- package/dist/math/abs.js.map +1 -1
- package/dist/math/allocate.cjs +2 -2
- package/dist/math/allocate.cjs.map +1 -1
- package/dist/math/allocate.d.ts +24 -0
- package/dist/math/allocate.d.ts.map +1 -0
- package/dist/math/allocate.js +20 -28
- package/dist/math/allocate.js.map +1 -1
- package/dist/math/average.cjs +2 -2
- package/dist/math/average.cjs.map +1 -1
- package/dist/math/average.d.ts +16 -0
- package/dist/math/average.d.ts.map +1 -0
- package/dist/math/average.js +13 -24
- package/dist/math/average.js.map +1 -1
- package/dist/math/clamp.cjs +2 -2
- package/dist/math/clamp.cjs.map +1 -1
- package/dist/math/clamp.d.ts +18 -0
- package/dist/math/clamp.d.ts.map +1 -0
- package/dist/math/clamp.js +7 -6
- package/dist/math/clamp.js.map +1 -1
- package/dist/math/distribute.cjs +2 -2
- package/dist/math/distribute.cjs.map +1 -1
- package/dist/math/distribute.d.ts +24 -0
- package/dist/math/distribute.d.ts.map +1 -0
- package/dist/math/distribute.js +14 -17
- package/dist/math/distribute.js.map +1 -1
- package/dist/math/index.d.ts +14 -0
- package/dist/math/index.d.ts.map +1 -0
- package/dist/math/linspace.cjs +2 -0
- package/dist/math/linspace.cjs.map +1 -0
- package/dist/math/linspace.d.ts +19 -0
- package/dist/math/linspace.d.ts.map +1 -0
- package/dist/math/linspace.js +11 -0
- package/dist/math/linspace.js.map +1 -0
- package/dist/math/max.cjs +2 -2
- package/dist/math/max.cjs.map +1 -1
- package/dist/math/max.d.ts +23 -0
- package/dist/math/max.d.ts.map +1 -0
- package/dist/math/max.js +10 -11
- package/dist/math/max.js.map +1 -1
- package/dist/math/median.cjs +2 -2
- package/dist/math/median.cjs.map +1 -1
- package/dist/math/median.d.ts +17 -0
- package/dist/math/median.d.ts.map +1 -0
- package/dist/math/median.js +11 -10
- package/dist/math/median.js.map +1 -1
- package/dist/math/min.cjs +2 -2
- package/dist/math/min.cjs.map +1 -1
- package/dist/math/min.d.ts +23 -0
- package/dist/math/min.d.ts.map +1 -0
- package/dist/math/min.js +10 -11
- package/dist/math/min.js.map +1 -1
- package/dist/math/percent.cjs +2 -0
- package/dist/math/percent.cjs.map +1 -0
- package/dist/math/percent.d.ts +19 -0
- package/dist/math/percent.d.ts.map +1 -0
- package/dist/math/percent.js +8 -0
- package/dist/math/percent.js.map +1 -0
- package/dist/math/range.cjs +2 -2
- package/dist/math/range.cjs.map +1 -1
- package/dist/math/range.d.ts +23 -0
- package/dist/math/range.d.ts.map +1 -0
- package/dist/math/range.js +28 -17
- package/dist/math/range.js.map +1 -1
- package/dist/math/round.cjs +2 -2
- package/dist/math/round.cjs.map +1 -1
- package/dist/math/round.d.ts +21 -0
- package/dist/math/round.d.ts.map +1 -0
- package/dist/math/round.js +9 -8
- package/dist/math/round.js.map +1 -1
- package/dist/math/sum.cjs +2 -2
- package/dist/math/sum.cjs.map +1 -1
- package/dist/math/sum.d.ts +17 -0
- package/dist/math/sum.d.ts.map +1 -0
- package/dist/math/sum.js +11 -14
- package/dist/math/sum.js.map +1 -1
- package/dist/money/currency.cjs +2 -2
- package/dist/money/currency.cjs.map +1 -1
- package/dist/money/currency.d.ts +30 -0
- package/dist/money/currency.d.ts.map +1 -0
- package/dist/money/currency.js +19 -47
- package/dist/money/currency.js.map +1 -1
- package/dist/money/exchange.cjs +2 -2
- package/dist/money/exchange.cjs.map +1 -1
- package/dist/money/exchange.d.ts +29 -0
- package/dist/money/exchange.d.ts.map +1 -0
- package/dist/money/exchange.js +12 -12
- package/dist/money/exchange.js.map +1 -1
- package/dist/money/index.d.ts +4 -0
- package/dist/money/index.d.ts.map +1 -0
- package/dist/money/types.d.ts +9 -0
- package/dist/money/types.d.ts.map +1 -0
- package/dist/object/diff.cjs +2 -2
- package/dist/object/diff.cjs.map +1 -1
- package/dist/object/diff.d.ts +26 -0
- package/dist/object/diff.d.ts.map +1 -0
- package/dist/object/diff.js +19 -17
- package/dist/object/diff.js.map +1 -1
- package/dist/object/index.d.ts +9 -0
- package/dist/object/index.d.ts.map +1 -0
- package/dist/object/merge.cjs +2 -2
- package/dist/object/merge.cjs.map +1 -1
- package/dist/object/merge.d.ts +44 -0
- package/dist/object/merge.d.ts.map +1 -0
- package/dist/object/merge.js +27 -21
- package/dist/object/merge.js.map +1 -1
- package/dist/object/parseJSON.cjs +2 -2
- package/dist/object/parseJSON.cjs.map +1 -1
- package/dist/object/parseJSON.d.ts +32 -0
- package/dist/object/parseJSON.d.ts.map +1 -0
- package/dist/object/parseJSON.js +17 -18
- package/dist/object/parseJSON.js.map +1 -1
- package/dist/object/path.cjs +2 -2
- package/dist/object/path.cjs.map +1 -1
- package/dist/object/path.d.ts +32 -0
- package/dist/object/path.d.ts.map +1 -0
- package/dist/object/path.js +25 -23
- package/dist/object/path.js.map +1 -1
- package/dist/object/proxy.cjs +2 -0
- package/dist/object/proxy.cjs.map +1 -0
- package/dist/object/proxy.d.ts +30 -0
- package/dist/object/proxy.d.ts.map +1 -0
- package/dist/object/proxy.js +21 -0
- package/dist/object/proxy.js.map +1 -0
- package/dist/object/prune.cjs +2 -0
- package/dist/object/prune.cjs.map +1 -0
- package/dist/object/prune.d.ts +21 -0
- package/dist/object/prune.d.ts.map +1 -0
- package/dist/object/prune.js +31 -0
- package/dist/object/prune.js.map +1 -0
- package/dist/object/seek.cjs +2 -2
- package/dist/object/seek.cjs.map +1 -1
- package/dist/object/seek.d.ts +2 -0
- package/dist/object/seek.d.ts.map +1 -0
- package/dist/object/seek.js +25 -12
- package/dist/object/seek.js.map +1 -1
- package/dist/object/stash.cjs +2 -0
- package/dist/object/stash.cjs.map +1 -0
- package/dist/object/stash.d.ts +45 -0
- package/dist/object/stash.d.ts.map +1 -0
- package/dist/object/stash.js +99 -0
- package/dist/object/stash.js.map +1 -0
- package/dist/random/draw.cjs +2 -2
- package/dist/random/draw.cjs.map +1 -1
- package/dist/random/draw.d.ts +16 -0
- package/dist/random/draw.d.ts.map +1 -0
- package/dist/random/draw.js +13 -10
- package/dist/random/draw.js.map +1 -1
- package/dist/random/index.d.ts +5 -0
- package/dist/random/index.d.ts.map +1 -0
- package/dist/random/random.cjs +2 -2
- package/dist/random/random.cjs.map +1 -1
- package/dist/random/random.d.ts +14 -0
- package/dist/random/random.d.ts.map +1 -0
- package/dist/random/random.js +16 -9
- package/dist/random/random.js.map +1 -1
- package/dist/random/shuffle.cjs +2 -2
- package/dist/random/shuffle.cjs.map +1 -1
- package/dist/random/shuffle.d.ts +17 -0
- package/dist/random/shuffle.d.ts.map +1 -0
- package/dist/random/shuffle.js +18 -14
- package/dist/random/shuffle.js.map +1 -1
- package/dist/random/uuid.cjs +2 -2
- package/dist/random/uuid.cjs.map +1 -1
- package/dist/random/uuid.d.ts +12 -0
- package/dist/random/uuid.d.ts.map +1 -0
- package/dist/random/uuid.js +7 -9
- package/dist/random/uuid.js.map +1 -1
- package/dist/string/_caseUtils.cjs +2 -2
- package/dist/string/_caseUtils.cjs.map +1 -1
- package/dist/string/_caseUtils.d.ts +13 -0
- package/dist/string/_caseUtils.d.ts.map +1 -0
- package/dist/string/_caseUtils.js +8 -8
- package/dist/string/_caseUtils.js.map +1 -1
- package/dist/string/camelCase.cjs +2 -2
- package/dist/string/camelCase.cjs.map +1 -1
- package/dist/string/camelCase.d.ts +14 -0
- package/dist/string/camelCase.d.ts.map +1 -0
- package/dist/string/camelCase.js +8 -7
- package/dist/string/camelCase.js.map +1 -1
- package/dist/string/index.d.ts +7 -0
- package/dist/string/index.d.ts.map +1 -0
- package/dist/string/kebabCase.cjs +2 -2
- package/dist/string/kebabCase.cjs.map +1 -1
- package/dist/string/kebabCase.d.ts +15 -0
- package/dist/string/kebabCase.d.ts.map +1 -0
- package/dist/string/kebabCase.js +8 -7
- package/dist/string/kebabCase.js.map +1 -1
- package/dist/string/pascalCase.cjs +2 -2
- package/dist/string/pascalCase.cjs.map +1 -1
- package/dist/string/pascalCase.d.ts +15 -0
- package/dist/string/pascalCase.d.ts.map +1 -0
- package/dist/string/pascalCase.js +8 -7
- package/dist/string/pascalCase.js.map +1 -1
- package/dist/string/similarity.cjs +2 -2
- package/dist/string/similarity.cjs.map +1 -1
- package/dist/string/similarity.d.ts +20 -0
- package/dist/string/similarity.d.ts.map +1 -0
- package/dist/string/similarity.js +20 -36
- package/dist/string/similarity.js.map +1 -1
- package/dist/string/snakeCase.cjs +2 -2
- package/dist/string/snakeCase.cjs.map +1 -1
- package/dist/string/snakeCase.d.ts +15 -0
- package/dist/string/snakeCase.d.ts.map +1 -0
- package/dist/string/snakeCase.js +8 -7
- package/dist/string/snakeCase.js.map +1 -1
- package/dist/string/truncate.cjs +2 -2
- package/dist/string/truncate.cjs.map +1 -1
- package/dist/string/truncate.d.ts +28 -0
- package/dist/string/truncate.d.ts.map +1 -0
- package/dist/string/truncate.js +20 -17
- package/dist/string/truncate.js.map +1 -1
- package/dist/toolkit.cjs +2 -0
- package/dist/toolkit.cjs.map +1 -0
- package/dist/toolkit.js +1523 -0
- package/dist/toolkit.js.map +1 -0
- package/dist/typed/index.d.ts +24 -0
- package/dist/typed/index.d.ts.map +1 -0
- package/dist/typed/is.cjs +2 -2
- package/dist/typed/is.cjs.map +1 -1
- package/dist/typed/is.d.ts +95 -0
- package/dist/typed/is.d.ts.map +1 -0
- package/dist/typed/is.js +54 -42
- package/dist/typed/is.js.map +1 -1
- package/dist/typed/isArray.cjs +2 -2
- package/dist/typed/isArray.cjs.map +1 -1
- package/dist/typed/isArray.d.ts +16 -0
- package/dist/typed/isArray.d.ts.map +1 -0
- package/dist/typed/isArray.js +8 -8
- package/dist/typed/isArray.js.map +1 -1
- package/dist/typed/isBoolean.cjs +2 -2
- package/dist/typed/isBoolean.cjs.map +1 -1
- package/dist/typed/isBoolean.d.ts +23 -0
- package/dist/typed/isBoolean.d.ts.map +1 -0
- package/dist/typed/isBoolean.js +7 -6
- package/dist/typed/isBoolean.js.map +1 -1
- package/dist/typed/isDate.cjs +2 -2
- package/dist/typed/isDate.cjs.map +1 -1
- package/dist/typed/isDate.d.ts +16 -0
- package/dist/typed/isDate.d.ts.map +1 -0
- package/dist/typed/isDate.js +7 -8
- package/dist/typed/isDate.js.map +1 -1
- package/dist/typed/isDefined.cjs +2 -2
- package/dist/typed/isDefined.cjs.map +1 -1
- package/dist/typed/isDefined.d.ts +19 -0
- package/dist/typed/isDefined.d.ts.map +1 -0
- package/dist/typed/isDefined.js +7 -6
- package/dist/typed/isDefined.js.map +1 -1
- package/dist/typed/isEmpty.cjs +2 -2
- package/dist/typed/isEmpty.cjs.map +1 -1
- package/dist/typed/isEmpty.d.ts +24 -0
- package/dist/typed/isEmpty.d.ts.map +1 -0
- package/dist/typed/isEmpty.js +8 -9
- package/dist/typed/isEmpty.js.map +1 -1
- package/dist/typed/isEqual.cjs +2 -2
- package/dist/typed/isEqual.cjs.map +1 -1
- package/dist/typed/isEqual.d.ts +24 -0
- package/dist/typed/isEqual.d.ts.map +1 -0
- package/dist/typed/isEqual.js +27 -28
- package/dist/typed/isEqual.js.map +1 -1
- package/dist/typed/isEven.cjs +2 -2
- package/dist/typed/isEven.cjs.map +1 -1
- package/dist/typed/isEven.d.ts +9 -0
- package/dist/typed/isEven.d.ts.map +1 -0
- package/dist/typed/isEven.js +7 -6
- package/dist/typed/isEven.js.map +1 -1
- package/dist/typed/isFunction.cjs +2 -2
- package/dist/typed/isFunction.cjs.map +1 -1
- package/dist/typed/isFunction.d.ts +16 -0
- package/dist/typed/isFunction.d.ts.map +1 -0
- package/dist/typed/isFunction.js +7 -8
- package/dist/typed/isFunction.js.map +1 -1
- package/dist/typed/isMatch.cjs +2 -2
- package/dist/typed/isMatch.cjs.map +1 -1
- package/dist/typed/isMatch.d.ts +23 -0
- package/dist/typed/isMatch.d.ts.map +1 -0
- package/dist/typed/isMatch.js +16 -18
- package/dist/typed/isMatch.js.map +1 -1
- package/dist/typed/isNegative.cjs +2 -2
- package/dist/typed/isNegative.cjs.map +1 -1
- package/dist/typed/isNegative.d.ts +26 -0
- package/dist/typed/isNegative.d.ts.map +1 -0
- package/dist/typed/isNegative.js +7 -6
- package/dist/typed/isNegative.js.map +1 -1
- package/dist/typed/isNil.cjs +2 -2
- package/dist/typed/isNil.cjs.map +1 -1
- package/dist/typed/isNil.d.ts +17 -0
- package/dist/typed/isNil.d.ts.map +1 -0
- package/dist/typed/isNil.js +7 -8
- package/dist/typed/isNil.js.map +1 -1
- package/dist/typed/isNumber.cjs +2 -2
- package/dist/typed/isNumber.cjs.map +1 -1
- package/dist/typed/isNumber.d.ts +16 -0
- package/dist/typed/isNumber.d.ts.map +1 -0
- package/dist/typed/isNumber.js +8 -8
- package/dist/typed/isNumber.js.map +1 -1
- package/dist/typed/isObject.cjs +2 -2
- package/dist/typed/isObject.cjs.map +1 -1
- package/dist/typed/isObject.d.ts +19 -0
- package/dist/typed/isObject.d.ts.map +1 -0
- package/dist/typed/isObject.js +8 -8
- package/dist/typed/isObject.js.map +1 -1
- package/dist/typed/isOdd.cjs +2 -2
- package/dist/typed/isOdd.cjs.map +1 -1
- package/dist/typed/isOdd.d.ts +9 -0
- package/dist/typed/isOdd.d.ts.map +1 -0
- package/dist/typed/isOdd.js +7 -6
- package/dist/typed/isOdd.js.map +1 -1
- package/dist/typed/isPositive.cjs +2 -2
- package/dist/typed/isPositive.cjs.map +1 -1
- package/dist/typed/isPositive.d.ts +26 -0
- package/dist/typed/isPositive.d.ts.map +1 -0
- package/dist/typed/isPositive.js +7 -6
- package/dist/typed/isPositive.js.map +1 -1
- package/dist/typed/isPrimitive.cjs +2 -2
- package/dist/typed/isPrimitive.cjs.map +1 -1
- package/dist/typed/isPrimitive.d.ts +18 -0
- package/dist/typed/isPrimitive.d.ts.map +1 -0
- package/dist/typed/isPrimitive.js +8 -9
- package/dist/typed/isPrimitive.js.map +1 -1
- package/dist/typed/isPromise.cjs +2 -2
- package/dist/typed/isPromise.cjs.map +1 -1
- package/dist/typed/isPromise.d.ts +17 -0
- package/dist/typed/isPromise.d.ts.map +1 -0
- package/dist/typed/isPromise.js +7 -9
- package/dist/typed/isPromise.js.map +1 -1
- package/dist/typed/isRegex.cjs +2 -2
- package/dist/typed/isRegex.cjs.map +1 -1
- package/dist/typed/isRegex.d.ts +21 -0
- package/dist/typed/isRegex.d.ts.map +1 -0
- package/dist/typed/isRegex.js +7 -6
- package/dist/typed/isRegex.js.map +1 -1
- package/dist/typed/isString.cjs +2 -2
- package/dist/typed/isString.cjs.map +1 -1
- package/dist/typed/isString.d.ts +16 -0
- package/dist/typed/isString.d.ts.map +1 -0
- package/dist/typed/isString.js +8 -8
- package/dist/typed/isString.js.map +1 -1
- package/dist/typed/isWithin.cjs +2 -2
- package/dist/typed/isWithin.cjs.map +1 -1
- package/dist/typed/isWithin.d.ts +20 -0
- package/dist/typed/isWithin.d.ts.map +1 -0
- package/dist/typed/isWithin.js +9 -9
- package/dist/typed/isWithin.js.map +1 -1
- package/dist/typed/isZero.cjs +2 -2
- package/dist/typed/isZero.cjs.map +1 -1
- package/dist/typed/isZero.d.ts +25 -0
- package/dist/typed/isZero.d.ts.map +1 -0
- package/dist/typed/isZero.js +7 -6
- package/dist/typed/isZero.js.map +1 -1
- package/dist/typed/typeOf.cjs +2 -2
- package/dist/typed/typeOf.cjs.map +1 -1
- package/dist/typed/typeOf.d.ts +30 -0
- package/dist/typed/typeOf.d.ts.map +1 -0
- package/dist/typed/typeOf.js +11 -13
- package/dist/typed/typeOf.js.map +1 -1
- package/dist/types.d.ts +9 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +77 -12
- package/dist/array/aggregate.cjs +0 -2
- package/dist/array/aggregate.cjs.map +0 -1
- package/dist/array/aggregate.js +0 -16
- package/dist/array/aggregate.js.map +0 -1
- package/dist/array/alternate.cjs +0 -2
- package/dist/array/alternate.cjs.map +0 -1
- package/dist/array/alternate.js +0 -9
- package/dist/array/alternate.js.map +0 -1
- package/dist/array/arrange.cjs +0 -2
- package/dist/array/arrange.cjs.map +0 -1
- package/dist/array/arrange.js +0 -6
- package/dist/array/arrange.js.map +0 -1
- package/dist/array/compact.cjs +0 -2
- package/dist/array/compact.cjs.map +0 -1
- package/dist/array/compact.js +0 -9
- package/dist/array/compact.js.map +0 -1
- package/dist/array/every.cjs +0 -2
- package/dist/array/every.cjs.map +0 -1
- package/dist/array/every.js +0 -14
- package/dist/array/every.js.map +0 -1
- package/dist/array/filter.cjs +0 -2
- package/dist/array/filter.cjs.map +0 -1
- package/dist/array/filter.js +0 -14
- package/dist/array/filter.js.map +0 -1
- package/dist/array/find.cjs +0 -2
- package/dist/array/find.cjs.map +0 -1
- package/dist/array/find.js +0 -14
- package/dist/array/find.js.map +0 -1
- package/dist/array/findIndex.cjs +0 -2
- package/dist/array/findIndex.cjs.map +0 -1
- package/dist/array/findIndex.js +0 -14
- package/dist/array/findIndex.js.map +0 -1
- package/dist/array/findLast.cjs +0 -2
- package/dist/array/findLast.cjs.map +0 -1
- package/dist/array/findLast.js +0 -14
- package/dist/array/findLast.js.map +0 -1
- package/dist/array/flatten.cjs +0 -2
- package/dist/array/flatten.cjs.map +0 -1
- package/dist/array/flatten.js +0 -7
- package/dist/array/flatten.js.map +0 -1
- package/dist/array/map.cjs +0 -2
- package/dist/array/map.cjs.map +0 -1
- package/dist/array/map.js +0 -18
- package/dist/array/map.js.map +0 -1
- package/dist/array/reduce.cjs +0 -2
- package/dist/array/reduce.cjs.map +0 -1
- package/dist/array/reduce.js +0 -16
- package/dist/array/reduce.js.map +0 -1
- package/dist/array/shift.cjs +0 -2
- package/dist/array/shift.cjs.map +0 -1
- package/dist/array/shift.js +0 -13
- package/dist/array/shift.js.map +0 -1
- package/dist/array/some.cjs +0 -2
- package/dist/array/some.cjs.map +0 -1
- package/dist/array/some.js +0 -14
- package/dist/array/some.js.map +0 -1
- package/dist/array/substitute.cjs +0 -2
- package/dist/array/substitute.cjs.map +0 -1
- package/dist/array/substitute.js +0 -13
- package/dist/array/substitute.js.map +0 -1
- package/dist/async/delay.cjs +0 -2
- package/dist/async/delay.cjs.map +0 -1
- package/dist/async/delay.js +0 -8
- package/dist/async/delay.js.map +0 -1
- package/dist/function/proxy.cjs +0 -2
- package/dist/function/proxy.cjs.map +0 -1
- package/dist/function/proxy.js +0 -22
- package/dist/function/proxy.js.map +0 -1
- package/dist/function/prune.cjs +0 -2
- package/dist/function/prune.cjs.map +0 -1
- package/dist/function/prune.js +0 -30
- package/dist/function/prune.js.map +0 -1
- package/dist/function/worker.cjs +0 -14
- package/dist/function/worker.cjs.map +0 -1
- package/dist/function/worker.js +0 -29
- package/dist/function/worker.js.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/logit/dist/logit.cjs +0 -2
- package/dist/logit/dist/logit.cjs.map +0 -1
- package/dist/logit/dist/logit.js +0 -263
- package/dist/logit/dist/logit.js.map +0 -1
- package/dist/math/add.cjs +0 -2
- package/dist/math/add.cjs.map +0 -1
- package/dist/math/add.js +0 -9
- package/dist/math/add.js.map +0 -1
- package/dist/math/boil.cjs +0 -2
- package/dist/math/boil.cjs.map +0 -1
- package/dist/math/boil.js +0 -17
- package/dist/math/boil.js.map +0 -1
- package/dist/math/divide.cjs +0 -2
- package/dist/math/divide.cjs.map +0 -1
- package/dist/math/divide.js +0 -11
- package/dist/math/divide.js.map +0 -1
- package/dist/math/multiply.cjs +0 -2
- package/dist/math/multiply.cjs.map +0 -1
- package/dist/math/multiply.js +0 -9
- package/dist/math/multiply.js.map +0 -1
- package/dist/math/rate.cjs +0 -2
- package/dist/math/rate.cjs.map +0 -1
- package/dist/math/rate.js +0 -9
- package/dist/math/rate.js.map +0 -1
- package/dist/math/subtract.cjs +0 -2
- package/dist/math/subtract.cjs.map +0 -1
- package/dist/math/subtract.js +0 -9
- package/dist/math/subtract.js.map +0 -1
- package/dist/object/cache.cjs +0 -2
- package/dist/object/cache.cjs.map +0 -1
- package/dist/object/cache.js +0 -63
- package/dist/object/cache.js.map +0 -1
- package/dist/object/clone.cjs +0 -2
- package/dist/object/clone.cjs.map +0 -1
- package/dist/object/clone.js +0 -17
- package/dist/object/clone.js.map +0 -1
- package/dist/object/entries.cjs +0 -2
- package/dist/object/entries.cjs.map +0 -1
- package/dist/object/entries.js +0 -9
- package/dist/object/entries.js.map +0 -1
- package/dist/object/keys.cjs +0 -2
- package/dist/object/keys.cjs.map +0 -1
- package/dist/object/keys.js +0 -9
- package/dist/object/keys.js.map +0 -1
- package/dist/object/values.cjs +0 -2
- package/dist/object/values.cjs.map +0 -1
- package/dist/object/values.js +0 -9
- package/dist/object/values.js.map +0 -1
- package/dist/typed/ge.cjs +0 -2
- package/dist/typed/ge.cjs.map +0 -1
- package/dist/typed/ge.js +0 -7
- package/dist/typed/ge.js.map +0 -1
- package/dist/typed/gt.cjs +0 -2
- package/dist/typed/gt.cjs.map +0 -1
- package/dist/typed/gt.js +0 -7
- package/dist/typed/gt.js.map +0 -1
- package/dist/typed/le.cjs +0 -2
- package/dist/typed/le.cjs.map +0 -1
- package/dist/typed/le.js +0 -7
- package/dist/typed/le.js.map +0 -1
- package/dist/typed/lt.cjs +0 -2
- package/dist/typed/lt.cjs.map +0 -1
- package/dist/typed/lt.js +0 -7
- package/dist/typed/lt.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compose.d.ts","sourceRoot":"","sources":["../../src/function/compose.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,UAAU,CAAC;AAInC,KAAK,cAAc,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,GAAG,EAAE,MAAM,IAAI,SAAS,EAAE,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;AAC9F,KAAK,eAAe,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,KAAK,SAAS,EAAE,EAAE,GAAG,GAAG,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC;AAEjG;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE,EAAE,GAAG,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,IAAI,EAAE,cAAc,CAAC,CAAC,CAAC,KAAK,eAAe,CAAC,CAAC,CAAC,CASrG"}
|
package/dist/function/compose.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
function
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
(e, o) => c(e) ? e.then(o) : o(e),
|
|
8
|
-
r(...i)
|
|
9
|
-
));
|
|
1
|
+
import { assert as e } from "./assert.js";
|
|
2
|
+
//#region src/function/compose.ts
|
|
3
|
+
function t(...t) {
|
|
4
|
+
e(t.length > 0, "compose requires at least one function", { args: { fns: t } });
|
|
5
|
+
let n = t[t.length - 1], r = t.slice(0, -1);
|
|
6
|
+
return ((...e) => r.reduceRight((e, t) => t(e), n(...e)));
|
|
10
7
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
//# sourceMappingURL=compose.js.map
|
|
8
|
+
//#endregion
|
|
9
|
+
export { t as compose };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=compose.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compose.js","sources":["../../src/function/compose.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"compose.js","names":[],"sources":["../../src/function/compose.ts"],"sourcesContent":["import type { Fn } from '../types';\n\nimport { assert } from './assert';\n\ntype LastParameters<T> = T extends [...any, infer Last extends Fn] ? Parameters<Last> : never;\ntype FirstReturnType<F> = F extends [infer First extends Fn, ...any] ? ReturnType<First> : never;\n\n/**\n * Composes multiple functions into a single function. It starts from the rightmost function and proceeds to the left.\n *\n * @example\n * ```ts\n * const add = (x) => x + 2;\n * const multiply = (x) => x * 3;\n * const subtract = (x) => x - 4;\n * const composedFn = compose(subtract, multiply, add);\n * composedFn(5); // ((5 + 2) * 3) - 4 = 17\n * ```\n *\n * @param fns - List of the functions to be composed.\n *\n * @returns A new function that is the composition of the input functions.\n */\nexport function compose<T extends Fn[]>(...fns: T): (...args: LastParameters<T>) => FirstReturnType<T> {\n assert(fns.length > 0, 'compose requires at least one function', { args: { fns } });\n\n const lastFn = fns[fns.length - 1];\n const restFns = fns.slice(0, -1);\n\n return ((...args: LastParameters<T>) => restFns.reduceRight((prev, fn) => fn(prev), lastFn(...args))) as (\n ...args: LastParameters<T>\n ) => FirstReturnType<T>;\n}\n"],"mappings":";;AAuBA,SAAgB,EAAwB,GAAG,GAA4D;AACrG,GAAO,EAAI,SAAS,GAAG,0CAA0C,EAAE,MAAM,EAAE,QAAK,EAAE,CAAC;CAEnF,IAAM,IAAS,EAAI,EAAI,SAAS,IAC1B,IAAU,EAAI,MAAM,GAAG,GAAG;AAEhC,UAAS,GAAG,MAA4B,EAAQ,aAAa,GAAM,MAAO,EAAG,EAAK,EAAE,EAAO,GAAG,EAAK,CAAC"}
|
package/dist/function/curry.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=curry.cjs.map
|
|
1
|
+
function e(e,t=e.length){let n=(...r)=>r.length>=t?e(...r):(...e)=>n(...r,...e);return n}exports.curry=e;
|
|
2
|
+
//# sourceMappingURL=curry.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"curry.cjs","sources":["../../src/function/curry.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"curry.cjs","names":[],"sources":["../../src/function/curry.ts"],"sourcesContent":["/**\n * Curries a function, allowing it to be called with partial arguments.\n *\n * @example\n * ```ts\n * const add = (a: number, b: number) => a + b;\n * const curriedAdd = curry(add);\n * curriedAdd(1)(2) // 3;\n * ```\n *\n * @param fn - The function to curry.\n * @param arity - The number of arguments the function expects. Defaults to the function's length.\n *\n * @returns A curried version of the function.\n */\n\n// Take first N items from tuple T\ntype Take<N extends number, T extends readonly unknown[], Acc extends readonly unknown[] = []> = Acc['length'] extends N\n ? Acc\n : T extends readonly [infer H, ...infer R]\n ? Take<N, R, readonly [...Acc, H]>\n : Acc;\n// Curried: at each step, accept a non-empty tuple of args A,\n// ensure it's a prefix of P, then either return R (if done) or recurse.\nexport type Curried<P extends readonly unknown[], R> = P extends readonly []\n ? () => R\n : <A extends readonly [unknown, ...(readonly unknown[])]>(\n ...args: A\n ) => P extends readonly [...A, ...infer Rest] ? (Rest extends readonly [] ? R : Curried<Rest, R>) : never;\n// Overloads to reflect default arity vs. a custom arity.\nexport function curry<T extends (...args: any[]) => any>(fn: T): Curried<Parameters<T>, ReturnType<T>>;\nexport function curry<T extends (...args: any[]) => any, N extends number>(\n fn: T,\n arity: N,\n): Curried<Take<N, Parameters<T>>, ReturnType<T>>;\n// Runtime implementation\nexport function curry(fn: (...args: any[]) => any, arity = fn.length) {\n const curried = (...args: any[]): any => {\n if (args.length >= arity) {\n return fn(...args);\n }\n\n return (...rest: any[]) => curried(...args, ...rest);\n };\n\n return curried as any;\n}\n"],"mappings":"AAoCA,SAAgB,EAAM,EAA6B,EAAQ,EAAG,OAAQ,CACpE,IAAM,GAAW,GAAG,IACd,EAAK,QAAU,EACV,EAAG,GAAG,EAAK,EAGZ,GAAG,IAAgB,EAAQ,GAAG,EAAM,GAAG,EAAK,CAGtD,OAAO"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Curries a function, allowing it to be called with partial arguments.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* const add = (a: number, b: number) => a + b;
|
|
7
|
+
* const curriedAdd = curry(add);
|
|
8
|
+
* curriedAdd(1)(2) // 3;
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* @param fn - The function to curry.
|
|
12
|
+
* @param arity - The number of arguments the function expects. Defaults to the function's length.
|
|
13
|
+
*
|
|
14
|
+
* @returns A curried version of the function.
|
|
15
|
+
*/
|
|
16
|
+
type Take<N extends number, T extends readonly unknown[], Acc extends readonly unknown[] = []> = Acc['length'] extends N ? Acc : T extends readonly [infer H, ...infer R] ? Take<N, R, readonly [...Acc, H]> : Acc;
|
|
17
|
+
export type Curried<P extends readonly unknown[], R> = P extends readonly [] ? () => R : <A extends readonly [unknown, ...(readonly unknown[])]>(...args: A) => P extends readonly [...A, ...infer Rest] ? (Rest extends readonly [] ? R : Curried<Rest, R>) : never;
|
|
18
|
+
export declare function curry<T extends (...args: any[]) => any>(fn: T): Curried<Parameters<T>, ReturnType<T>>;
|
|
19
|
+
export declare function curry<T extends (...args: any[]) => any, N extends number>(fn: T, arity: N): Curried<Take<N, Parameters<T>>, ReturnType<T>>;
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=curry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"curry.d.ts","sourceRoot":"","sources":["../../src/function/curry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,KAAK,IAAI,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,SAAS,OAAO,EAAE,EAAE,GAAG,SAAS,SAAS,OAAO,EAAE,GAAG,EAAE,IAAI,GAAG,CAAC,QAAQ,CAAC,SAAS,CAAC,GACpH,GAAG,GACH,CAAC,SAAS,SAAS,CAAC,MAAM,CAAC,EAAE,GAAG,MAAM,CAAC,CAAC,GACtC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,SAAS,CAAC,GAAG,GAAG,EAAE,CAAC,CAAC,CAAC,GAChC,GAAG,CAAC;AAGV,MAAM,MAAM,OAAO,CAAC,CAAC,SAAS,SAAS,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,SAAS,EAAE,GACxE,MAAM,CAAC,GACP,CAAC,CAAC,SAAS,SAAS,CAAC,OAAO,EAAE,GAAG,CAAC,SAAS,OAAO,EAAE,CAAC,CAAC,EACpD,GAAG,IAAI,EAAE,CAAC,KACP,CAAC,SAAS,SAAS,CAAC,GAAG,CAAC,EAAE,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,IAAI,SAAS,SAAS,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC;AAE9G,wBAAgB,KAAK,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAAE,EAAE,EAAE,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AACvG,wBAAgB,KAAK,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAAE,CAAC,SAAS,MAAM,EACvE,EAAE,EAAE,CAAC,EACL,KAAK,EAAE,CAAC,GACP,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC"}
|
package/dist/function/curry.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
function
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
//#region src/function/curry.ts
|
|
2
|
+
function e(e, t = e.length) {
|
|
3
|
+
let n = (...r) => r.length >= t ? e(...r) : (...e) => n(...r, ...e);
|
|
4
|
+
return n;
|
|
4
5
|
}
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
//# sourceMappingURL=curry.js.map
|
|
6
|
+
//#endregion
|
|
7
|
+
export { e as curry };
|
|
8
|
+
|
|
9
|
+
//# sourceMappingURL=curry.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"curry.js","sources":["../../src/function/curry.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"curry.js","names":[],"sources":["../../src/function/curry.ts"],"sourcesContent":["/**\n * Curries a function, allowing it to be called with partial arguments.\n *\n * @example\n * ```ts\n * const add = (a: number, b: number) => a + b;\n * const curriedAdd = curry(add);\n * curriedAdd(1)(2) // 3;\n * ```\n *\n * @param fn - The function to curry.\n * @param arity - The number of arguments the function expects. Defaults to the function's length.\n *\n * @returns A curried version of the function.\n */\n\n// Take first N items from tuple T\ntype Take<N extends number, T extends readonly unknown[], Acc extends readonly unknown[] = []> = Acc['length'] extends N\n ? Acc\n : T extends readonly [infer H, ...infer R]\n ? Take<N, R, readonly [...Acc, H]>\n : Acc;\n// Curried: at each step, accept a non-empty tuple of args A,\n// ensure it's a prefix of P, then either return R (if done) or recurse.\nexport type Curried<P extends readonly unknown[], R> = P extends readonly []\n ? () => R\n : <A extends readonly [unknown, ...(readonly unknown[])]>(\n ...args: A\n ) => P extends readonly [...A, ...infer Rest] ? (Rest extends readonly [] ? R : Curried<Rest, R>) : never;\n// Overloads to reflect default arity vs. a custom arity.\nexport function curry<T extends (...args: any[]) => any>(fn: T): Curried<Parameters<T>, ReturnType<T>>;\nexport function curry<T extends (...args: any[]) => any, N extends number>(\n fn: T,\n arity: N,\n): Curried<Take<N, Parameters<T>>, ReturnType<T>>;\n// Runtime implementation\nexport function curry(fn: (...args: any[]) => any, arity = fn.length) {\n const curried = (...args: any[]): any => {\n if (args.length >= arity) {\n return fn(...args);\n }\n\n return (...rest: any[]) => curried(...args, ...rest);\n };\n\n return curried as any;\n}\n"],"mappings":";AAoCA,SAAgB,EAAM,GAA6B,IAAQ,EAAG,QAAQ;CACpE,IAAM,KAAW,GAAG,MACd,EAAK,UAAU,IACV,EAAG,GAAG,EAAK,IAGZ,GAAG,MAAgB,EAAQ,GAAG,GAAM,GAAG,EAAK;AAGtD,QAAO"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=debounce.cjs.map
|
|
1
|
+
const e=require(`./assert.cjs`),t=require(`../async/scheduler.cjs`);function n(n,r=300){e.assert(typeof n==`function`,`First argument must be a function`,{args:{fn:n},type:TypeError}),e.assert(typeof r==`number`&&r>=0,`Delay must be a non-negative number`,{args:{delay:r},type:TypeError});let i,a,o,s=()=>{i!==void 0&&(i.abort(),i=void 0)},c=()=>{let e=new AbortController,n=new t.Scheduler;i=e,n.postTask(l,{delay:r,priority:`user-visible`,signal:e.signal}).catch(()=>{})},l=()=>{if(s(),!a)return;let e=a,t=o;return a=void 0,o=void 0,n.apply(t,e)},u=function(...e){a=e,o=this,s(),c()};return u.cancel=()=>{s(),a=void 0,o=void 0},u.flush=()=>l(),u.pending=()=>i!==void 0,u}exports.debounce=n;
|
|
2
|
+
//# sourceMappingURL=debounce.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"debounce.cjs","sources":["../../src/function/debounce.ts"],"sourcesContent":["import type { Fn } from '../types';\nimport { assert } from './assert';\n\nexport type Debounced<T extends Fn> = ((this: ThisParameterType<T>, ...args: Parameters<T>) => void) & {\n cancel(): void;\n flush(): ReturnType<T> | undefined;\n pending(): boolean;\n};\n\n/**\n * Debounce a function (trailing). Use `flush` to invoke immediately,\n * `cancel` to clear, and `pending` to check if an invocation is scheduled.\n */\nexport function debounce<T extends Fn>(fn: T, delay = 300): Debounced<T> {\n assert(typeof fn === 'function', 'First argument must be a function', {\n args: { fn },\n type: TypeError,\n });\n assert(typeof delay === 'number' && delay >= 0, 'Delay must be a non-negative number', {\n args: { delay },\n type: TypeError,\n });\n\n let
|
|
1
|
+
{"version":3,"file":"debounce.cjs","names":[],"sources":["../../src/function/debounce.ts"],"sourcesContent":["import type { Fn } from '../types';\n\nimport { Scheduler } from '../async/scheduler';\nimport { assert } from './assert';\n\nexport type Debounced<T extends Fn> = ((this: ThisParameterType<T>, ...args: Parameters<T>) => void) & {\n cancel(): void;\n flush(): ReturnType<T> | undefined;\n pending(): boolean;\n};\n\n/**\n * Debounce a function (trailing). Use `flush` to invoke immediately,\n * `cancel` to clear, and `pending` to check if an invocation is scheduled.\n */\nexport function debounce<T extends Fn>(fn: T, delay = 300): Debounced<T> {\n assert(typeof fn === 'function', 'First argument must be a function', {\n args: { fn },\n type: TypeError,\n });\n assert(typeof delay === 'number' && delay >= 0, 'Delay must be a non-negative number', {\n args: { delay },\n type: TypeError,\n });\n\n let timerController: AbortController | undefined;\n let lastArgs: Parameters<T> | undefined;\n let lastThis: ThisParameterType<T> | undefined;\n\n const clearTimer = () => {\n if (timerController !== undefined) {\n timerController.abort();\n timerController = undefined;\n }\n };\n\n const scheduleInvoke = () => {\n const controller = new AbortController();\n const scheduler = new Scheduler();\n\n timerController = controller;\n void scheduler\n .postTask(invoke, {\n delay,\n priority: 'user-visible',\n signal: controller.signal,\n })\n .catch(() => {\n // Aborts are expected when debounce is rescheduled or canceled.\n });\n };\n\n const invoke = () => {\n clearTimer();\n\n if (!lastArgs) return undefined; // nothing to invoke\n\n const args = lastArgs;\n const ctx = lastThis as ThisParameterType<T>;\n\n lastArgs = undefined;\n lastThis = undefined;\n\n return fn.apply(ctx as any, args) as ReturnType<T>;\n };\n\n const debounced = function (this: ThisParameterType<T>, ...args: Parameters<T>) {\n lastArgs = args;\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n lastThis = this;\n clearTimer();\n scheduleInvoke();\n } as Debounced<T>;\n\n debounced.cancel = () => {\n clearTimer();\n lastArgs = undefined;\n lastThis = undefined;\n };\n\n debounced.flush = () => invoke() as ReturnType<T> | undefined;\n\n debounced.pending = () => timerController !== undefined;\n\n return debounced;\n}\n"],"mappings":"oEAeA,SAAgB,EAAuB,EAAO,EAAQ,IAAmB,CACvE,EAAA,OAAO,OAAO,GAAO,WAAY,oCAAqC,CACpE,KAAM,CAAE,KAAI,CACZ,KAAM,UACP,CAAC,CACF,EAAA,OAAO,OAAO,GAAU,UAAY,GAAS,EAAG,sCAAuC,CACrF,KAAM,CAAE,QAAO,CACf,KAAM,UACP,CAAC,CAEF,IAAI,EACA,EACA,EAEE,MAAmB,CACnB,IAAoB,IAAA,KACtB,EAAgB,OAAO,CACvB,EAAkB,IAAA,KAIhB,MAAuB,CAC3B,IAAM,EAAa,IAAI,gBACjB,EAAY,IAAI,EAAA,UAEtB,EAAkB,EACb,EACF,SAAS,EAAQ,CAChB,QACA,SAAU,eACV,OAAQ,EAAW,OACpB,CAAC,CACD,UAAY,GAEX,EAGA,MAAe,CAGnB,GAFA,GAAY,CAER,CAAC,EAAU,OAEf,IAAM,EAAO,EACP,EAAM,EAKZ,MAHA,GAAW,IAAA,GACX,EAAW,IAAA,GAEJ,EAAG,MAAM,EAAY,EAAK,EAG7B,EAAY,SAAsC,GAAG,EAAqB,CAC9E,EAAW,EAEX,EAAW,KACX,GAAY,CACZ,GAAgB,EAalB,MAVA,GAAU,WAAe,CACvB,GAAY,CACZ,EAAW,IAAA,GACX,EAAW,IAAA,IAGb,EAAU,UAAc,GAAQ,CAEhC,EAAU,YAAgB,IAAoB,IAAA,GAEvC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Fn } from '../types';
|
|
2
|
+
export type Debounced<T extends Fn> = ((this: ThisParameterType<T>, ...args: Parameters<T>) => void) & {
|
|
3
|
+
cancel(): void;
|
|
4
|
+
flush(): ReturnType<T> | undefined;
|
|
5
|
+
pending(): boolean;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Debounce a function (trailing). Use `flush` to invoke immediately,
|
|
9
|
+
* `cancel` to clear, and `pending` to check if an invocation is scheduled.
|
|
10
|
+
*/
|
|
11
|
+
export declare function debounce<T extends Fn>(fn: T, delay?: number): Debounced<T>;
|
|
12
|
+
//# sourceMappingURL=debounce.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debounce.d.ts","sourceRoot":"","sources":["../../src/function/debounce.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,UAAU,CAAC;AAKnC,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,IAAI,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,GAAG;IACrG,MAAM,IAAI,IAAI,CAAC;IACf,KAAK,IAAI,UAAU,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;IACnC,OAAO,IAAI,OAAO,CAAC;CACpB,CAAC;AAEF;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,KAAK,SAAM,GAAG,SAAS,CAAC,CAAC,CAAC,CAsEvE"}
|
|
@@ -1,27 +1,35 @@
|
|
|
1
|
-
import { assert as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
1
|
+
import { assert as e } from "./assert.js";
|
|
2
|
+
import { Scheduler as t } from "../async/scheduler.js";
|
|
3
|
+
//#region src/function/debounce.ts
|
|
4
|
+
function n(n, r = 300) {
|
|
5
|
+
e(typeof n == "function", "First argument must be a function", {
|
|
6
|
+
args: { fn: n },
|
|
7
|
+
type: TypeError
|
|
8
|
+
}), e(typeof r == "number" && r >= 0, "Delay must be a non-negative number", {
|
|
9
|
+
args: { delay: r },
|
|
10
|
+
type: TypeError
|
|
11
|
+
});
|
|
12
|
+
let i, a, o, s = () => {
|
|
13
|
+
i !== void 0 && (i.abort(), i = void 0);
|
|
14
|
+
}, c = () => {
|
|
15
|
+
let e = new AbortController(), n = new t();
|
|
16
|
+
i = e, n.postTask(l, {
|
|
17
|
+
delay: r,
|
|
18
|
+
priority: "user-visible",
|
|
19
|
+
signal: e.signal
|
|
20
|
+
}).catch(() => {});
|
|
21
|
+
}, l = () => {
|
|
22
|
+
if (s(), !a) return;
|
|
23
|
+
let e = a, t = o;
|
|
24
|
+
return a = void 0, o = void 0, n.apply(t, e);
|
|
25
|
+
}, u = function(...e) {
|
|
26
|
+
a = e, o = this, s(), c();
|
|
27
|
+
};
|
|
28
|
+
return u.cancel = () => {
|
|
29
|
+
s(), a = void 0, o = void 0;
|
|
30
|
+
}, u.flush = () => l(), u.pending = () => i !== void 0, u;
|
|
23
31
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
//# sourceMappingURL=debounce.js.map
|
|
32
|
+
//#endregion
|
|
33
|
+
export { n as debounce };
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=debounce.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"debounce.js","sources":["../../src/function/debounce.ts"],"sourcesContent":["import type { Fn } from '../types';\nimport { assert } from './assert';\n\nexport type Debounced<T extends Fn> = ((this: ThisParameterType<T>, ...args: Parameters<T>) => void) & {\n cancel(): void;\n flush(): ReturnType<T> | undefined;\n pending(): boolean;\n};\n\n/**\n * Debounce a function (trailing). Use `flush` to invoke immediately,\n * `cancel` to clear, and `pending` to check if an invocation is scheduled.\n */\nexport function debounce<T extends Fn>(fn: T, delay = 300): Debounced<T> {\n assert(typeof fn === 'function', 'First argument must be a function', {\n args: { fn },\n type: TypeError,\n });\n assert(typeof delay === 'number' && delay >= 0, 'Delay must be a non-negative number', {\n args: { delay },\n type: TypeError,\n });\n\n let
|
|
1
|
+
{"version":3,"file":"debounce.js","names":[],"sources":["../../src/function/debounce.ts"],"sourcesContent":["import type { Fn } from '../types';\n\nimport { Scheduler } from '../async/scheduler';\nimport { assert } from './assert';\n\nexport type Debounced<T extends Fn> = ((this: ThisParameterType<T>, ...args: Parameters<T>) => void) & {\n cancel(): void;\n flush(): ReturnType<T> | undefined;\n pending(): boolean;\n};\n\n/**\n * Debounce a function (trailing). Use `flush` to invoke immediately,\n * `cancel` to clear, and `pending` to check if an invocation is scheduled.\n */\nexport function debounce<T extends Fn>(fn: T, delay = 300): Debounced<T> {\n assert(typeof fn === 'function', 'First argument must be a function', {\n args: { fn },\n type: TypeError,\n });\n assert(typeof delay === 'number' && delay >= 0, 'Delay must be a non-negative number', {\n args: { delay },\n type: TypeError,\n });\n\n let timerController: AbortController | undefined;\n let lastArgs: Parameters<T> | undefined;\n let lastThis: ThisParameterType<T> | undefined;\n\n const clearTimer = () => {\n if (timerController !== undefined) {\n timerController.abort();\n timerController = undefined;\n }\n };\n\n const scheduleInvoke = () => {\n const controller = new AbortController();\n const scheduler = new Scheduler();\n\n timerController = controller;\n void scheduler\n .postTask(invoke, {\n delay,\n priority: 'user-visible',\n signal: controller.signal,\n })\n .catch(() => {\n // Aborts are expected when debounce is rescheduled or canceled.\n });\n };\n\n const invoke = () => {\n clearTimer();\n\n if (!lastArgs) return undefined; // nothing to invoke\n\n const args = lastArgs;\n const ctx = lastThis as ThisParameterType<T>;\n\n lastArgs = undefined;\n lastThis = undefined;\n\n return fn.apply(ctx as any, args) as ReturnType<T>;\n };\n\n const debounced = function (this: ThisParameterType<T>, ...args: Parameters<T>) {\n lastArgs = args;\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n lastThis = this;\n clearTimer();\n scheduleInvoke();\n } as Debounced<T>;\n\n debounced.cancel = () => {\n clearTimer();\n lastArgs = undefined;\n lastThis = undefined;\n };\n\n debounced.flush = () => invoke() as ReturnType<T> | undefined;\n\n debounced.pending = () => timerController !== undefined;\n\n return debounced;\n}\n"],"mappings":";;;AAeA,SAAgB,EAAuB,GAAO,IAAQ,KAAmB;AAKvE,CAJA,EAAO,OAAO,KAAO,YAAY,qCAAqC;EACpE,MAAM,EAAE,OAAI;EACZ,MAAM;EACP,CAAC,EACF,EAAO,OAAO,KAAU,YAAY,KAAS,GAAG,uCAAuC;EACrF,MAAM,EAAE,UAAO;EACf,MAAM;EACP,CAAC;CAEF,IAAI,GACA,GACA,GAEE,UAAmB;AACvB,EAAI,MAAoB,KAAA,MACtB,EAAgB,OAAO,EACvB,IAAkB,KAAA;IAIhB,UAAuB;EAC3B,IAAM,IAAa,IAAI,iBAAiB,EAClC,IAAY,IAAI,GAAW;AAG5B,EADL,IAAkB,GACb,EACF,SAAS,GAAQ;GAChB;GACA,UAAU;GACV,QAAQ,EAAW;GACpB,CAAC,CACD,YAAY,GAEX;IAGA,UAAe;AAGnB,MAFA,GAAY,EAER,CAAC,EAAU;EAEf,IAAM,IAAO,GACP,IAAM;AAKZ,SAHA,IAAW,KAAA,GACX,IAAW,KAAA,GAEJ,EAAG,MAAM,GAAY,EAAK;IAG7B,IAAY,SAAsC,GAAG,GAAqB;AAK9E,EAJA,IAAW,GAEX,IAAW,MACX,GAAY,EACZ,GAAgB;;AAalB,QAVA,EAAU,eAAe;AAGvB,EAFA,GAAY,EACZ,IAAW,KAAA,GACX,IAAW,KAAA;IAGb,EAAU,cAAc,GAAQ,EAEhC,EAAU,gBAAgB,MAAoB,KAAA,GAEvC"}
|
package/dist/function/fp.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=fp.cjs.map
|
|
1
|
+
var e=(e,...t)=>n=>e(n,...t);exports.partial=e;
|
|
2
|
+
//# sourceMappingURL=fp.cjs.map
|
package/dist/function/fp.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fp.cjs","sources":["../../src/function/fp.ts"],"sourcesContent":["import type { Fn } from '../types';\
|
|
1
|
+
{"version":3,"file":"fp.cjs","names":[],"sources":["../../src/function/fp.ts"],"sourcesContent":["import type { Fn } from '../types';\n\ntype RemoveFirstParameter<T extends Fn> = T extends (first: any, ...rest: infer R) => any ? R : never;\ntype FirstParameter<T extends Fn> = T extends (first: infer A, ...rest: any[]) => any ? A : never;\n\n/**\n * Partially applies a multi-arg function by pre-filling every argument\n * except the first — returning a unary function useful for pipeline composition.\n *\n * @example\n * ```ts\n * const double = (num: number) => num * 2;\n * const doubleAll = partial(select, double);\n * doubleAll([1, 2, 3]); // [2, 4, 6]\n *\n * // In a pipe\n * pipe(partial(select, (x: number) => x > 1 ? x * 2 : null))([1, 2, 3]); // [4, 6]\n * ```\n *\n * @param callback - Any function whose first argument is the collection.\n * @param args - The remaining arguments to pre-apply.\n * @returns A unary function `(collection) => ReturnType<F>`.\n */\nexport const partial = <F extends Fn>(callback: F, ...args: RemoveFirstParameter<F>) => {\n return (collection: FirstParameter<F>) => callback(collection, ...args);\n};\n"],"mappings":"AAuBA,IAAa,GAAyB,EAAa,GAAG,IAC5C,GAAkC,EAAS,EAAY,GAAG,EAAK"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Fn } from '../types';
|
|
2
|
+
type RemoveFirstParameter<T extends Fn> = T extends (first: any, ...rest: infer R) => any ? R : never;
|
|
3
|
+
type FirstParameter<T extends Fn> = T extends (first: infer A, ...rest: any[]) => any ? A : never;
|
|
4
|
+
/**
|
|
5
|
+
* Partially applies a multi-arg function by pre-filling every argument
|
|
6
|
+
* except the first — returning a unary function useful for pipeline composition.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* const double = (num: number) => num * 2;
|
|
11
|
+
* const doubleAll = partial(select, double);
|
|
12
|
+
* doubleAll([1, 2, 3]); // [2, 4, 6]
|
|
13
|
+
*
|
|
14
|
+
* // In a pipe
|
|
15
|
+
* pipe(partial(select, (x: number) => x > 1 ? x * 2 : null))([1, 2, 3]); // [4, 6]
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @param callback - Any function whose first argument is the collection.
|
|
19
|
+
* @param args - The remaining arguments to pre-apply.
|
|
20
|
+
* @returns A unary function `(collection) => ReturnType<F>`.
|
|
21
|
+
*/
|
|
22
|
+
export declare const partial: <F extends Fn>(callback: F, ...args: RemoveFirstParameter<F>) => (collection: FirstParameter<F>) => any;
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=fp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fp.d.ts","sourceRoot":"","sources":["../../src/function/fp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,UAAU,CAAC;AAEnC,KAAK,oBAAoB,CAAC,CAAC,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,IAAI,EAAE,MAAM,CAAC,KAAK,GAAG,GAAG,CAAC,GAAG,KAAK,CAAC;AACtG,KAAK,cAAc,CAAC,CAAC,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,GAAG,CAAC,GAAG,KAAK,CAAC;AAElG;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,OAAO,GAAI,CAAC,SAAS,EAAE,EAAE,UAAU,CAAC,EAAE,GAAG,MAAM,oBAAoB,CAAC,CAAC,CAAC,MACzE,YAAY,cAAc,CAAC,CAAC,CAAC,QACtC,CAAC"}
|
package/dist/function/fp.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export {
|
|
8
|
-
i as fp
|
|
9
|
-
};
|
|
10
|
-
//# sourceMappingURL=fp.js.map
|
|
1
|
+
//#region src/function/fp.ts
|
|
2
|
+
var e = (e, ...t) => (n) => e(n, ...t);
|
|
3
|
+
//#endregion
|
|
4
|
+
export { e as partial };
|
|
5
|
+
|
|
6
|
+
//# sourceMappingURL=fp.js.map
|
package/dist/function/fp.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fp.js","sources":["../../src/function/fp.ts"],"sourcesContent":["import type { Fn } from '../types';\
|
|
1
|
+
{"version":3,"file":"fp.js","names":[],"sources":["../../src/function/fp.ts"],"sourcesContent":["import type { Fn } from '../types';\n\ntype RemoveFirstParameter<T extends Fn> = T extends (first: any, ...rest: infer R) => any ? R : never;\ntype FirstParameter<T extends Fn> = T extends (first: infer A, ...rest: any[]) => any ? A : never;\n\n/**\n * Partially applies a multi-arg function by pre-filling every argument\n * except the first — returning a unary function useful for pipeline composition.\n *\n * @example\n * ```ts\n * const double = (num: number) => num * 2;\n * const doubleAll = partial(select, double);\n * doubleAll([1, 2, 3]); // [2, 4, 6]\n *\n * // In a pipe\n * pipe(partial(select, (x: number) => x > 1 ? x * 2 : null))([1, 2, 3]); // [4, 6]\n * ```\n *\n * @param callback - Any function whose first argument is the collection.\n * @param args - The remaining arguments to pre-apply.\n * @returns A unary function `(collection) => ReturnType<F>`.\n */\nexport const partial = <F extends Fn>(callback: F, ...args: RemoveFirstParameter<F>) => {\n return (collection: FirstParameter<F>) => callback(collection, ...args);\n};\n"],"mappings":";AAuBA,IAAa,KAAyB,GAAa,GAAG,OAC5C,MAAkC,EAAS,GAAY,GAAG,EAAK"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from './assert';
|
|
2
|
+
export * from './assertParams';
|
|
3
|
+
export * from './compare';
|
|
4
|
+
export * from './compareBy';
|
|
5
|
+
export * from './compose';
|
|
6
|
+
export * from './curry';
|
|
7
|
+
export * from './debounce';
|
|
8
|
+
export * from './fp';
|
|
9
|
+
export * from './memo';
|
|
10
|
+
export * from './once';
|
|
11
|
+
export * from './pipe';
|
|
12
|
+
export * from './throttle';
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/function/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,MAAM,CAAC;AACrB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC"}
|
package/dist/function/memo.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=memo.cjs.map
|
|
1
|
+
function e(e,{maxSize:t,resolver:n,ttl:r}={}){let i=new Map,a=e=>n?n(...e):JSON.stringify(e,(e,t)=>t===void 0?`__undefined__`:t);return(...n)=>{let o=a(n),s=Date.now(),c=i.get(o);if(c&&(!r||s-c.timestamp<r))return i.delete(o),i.set(o,c),c.value;let l=e(...n);return i.set(o,{timestamp:s,value:l}),l instanceof Promise&&l.catch(()=>i.delete(o)),t&&i.size>t&&i.delete(i.keys().next().value),l}}exports.memo=e;
|
|
2
|
+
//# sourceMappingURL=memo.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memo.cjs","sources":["../../src/function/memo.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"memo.cjs","names":[],"sources":["../../src/function/memo.ts"],"sourcesContent":["import type { Fn } from '../types';\n\n// #region MemoizeOptions\ntype MemoizeOptions<T extends Fn> = {\n maxSize?: number; // Maximum number of items in cache\n resolver?: (...args: Parameters<T>) => string; // Custom key generator\n ttl?: number; // Time-to-live in milliseconds\n};\n// #endregion MemoizeOptions\n\ntype CacheEntry<T extends Fn> = {\n timestamp: number;\n value: ReturnType<T>;\n};\n\n/**\n * Creates a function that memorizes the result of the provided function.\n * Supports expiration (TTL) and limited cache size (LRU).\n *\n * @example\n * ```ts\n * const add = (x, y) => x + y;\n * const memoizedAdd = memo(add, { ttl: 5000, maxSize: 10 });\n *\n * memoizedAdd(1, 2); // 3 (caches the result)\n * memoizedAdd(1, 2); // 3 (from cache)\n * ```\n *\n * @param fn - The function to memorize.\n * @param options - Memoization options.\n * @param [options.ttl] - (optional) time-to-live (TTL) for cache expiration (in milliseconds).\n * @param [options.maxSize] - (optional) maximum cache size (LRU eviction).\n * @param [options.resolver] - (optional) custom function to resolve the cache key.\n *\n * @returns A new function that memorizes the input function.\n */\nexport function memo<T extends Fn>(\n fn: T,\n { maxSize, resolver, ttl }: MemoizeOptions<T> = {},\n): (...args: Parameters<T>) => ReturnType<T> {\n const cache = new Map<string, CacheEntry<T>>();\n\n const keyGen = (args: Parameters<T>): string => {\n if (resolver) return resolver(...args);\n\n // Use a replacer to distinguish undefined from null (JSON.stringify collapses both to null)\n return JSON.stringify(args, (_, v) => (v === undefined ? '__undefined__' : v));\n };\n\n return (...args: Parameters<T>): ReturnType<T> => {\n const key = keyGen(args);\n const now = Date.now();\n const cached = cache.get(key);\n\n if (cached && (!ttl || now - cached.timestamp < ttl)) {\n cache.delete(key);\n cache.set(key, cached); // Move to end (most recently used)\n\n return cached.value;\n }\n\n const result = fn(...args);\n\n cache.set(key, { timestamp: now, value: result });\n\n if (result instanceof Promise) {\n // Evict on rejection so subsequent calls retry instead of returning a settled failure\n (result as Promise<unknown>).catch(() => cache.delete(key));\n }\n\n if (maxSize && cache.size > maxSize) {\n cache.delete(cache.keys().next().value!); // Remove least recently used\n }\n\n return result;\n };\n}\n"],"mappings":"AAoCA,SAAgB,EACd,EACA,CAAE,UAAS,WAAU,OAA2B,EAAE,CACP,CAC3C,IAAM,EAAQ,IAAI,IAEZ,EAAU,GACV,EAAiB,EAAS,GAAG,EAAK,CAG/B,KAAK,UAAU,GAAO,EAAG,IAAO,IAAM,IAAA,GAAY,gBAAkB,EAAG,CAGhF,OAAQ,GAAG,IAAuC,CAChD,IAAM,EAAM,EAAO,EAAK,CAClB,EAAM,KAAK,KAAK,CAChB,EAAS,EAAM,IAAI,EAAI,CAE7B,GAAI,IAAW,CAAC,GAAO,EAAM,EAAO,UAAY,GAI9C,OAHA,EAAM,OAAO,EAAI,CACjB,EAAM,IAAI,EAAK,EAAO,CAEf,EAAO,MAGhB,IAAM,EAAS,EAAG,GAAG,EAAK,CAa1B,OAXA,EAAM,IAAI,EAAK,CAAE,UAAW,EAAK,MAAO,EAAQ,CAAC,CAE7C,aAAkB,SAEnB,EAA4B,UAAY,EAAM,OAAO,EAAI,CAAC,CAGzD,GAAW,EAAM,KAAO,GAC1B,EAAM,OAAO,EAAM,MAAM,CAAC,MAAM,CAAC,MAAO,CAGnC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Fn } from '../types';
|
|
2
|
+
type MemoizeOptions<T extends Fn> = {
|
|
3
|
+
maxSize?: number;
|
|
4
|
+
resolver?: (...args: Parameters<T>) => string;
|
|
5
|
+
ttl?: number;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Creates a function that memorizes the result of the provided function.
|
|
9
|
+
* Supports expiration (TTL) and limited cache size (LRU).
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const add = (x, y) => x + y;
|
|
14
|
+
* const memoizedAdd = memo(add, { ttl: 5000, maxSize: 10 });
|
|
15
|
+
*
|
|
16
|
+
* memoizedAdd(1, 2); // 3 (caches the result)
|
|
17
|
+
* memoizedAdd(1, 2); // 3 (from cache)
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @param fn - The function to memorize.
|
|
21
|
+
* @param options - Memoization options.
|
|
22
|
+
* @param [options.ttl] - (optional) time-to-live (TTL) for cache expiration (in milliseconds).
|
|
23
|
+
* @param [options.maxSize] - (optional) maximum cache size (LRU eviction).
|
|
24
|
+
* @param [options.resolver] - (optional) custom function to resolve the cache key.
|
|
25
|
+
*
|
|
26
|
+
* @returns A new function that memorizes the input function.
|
|
27
|
+
*/
|
|
28
|
+
export declare function memo<T extends Fn>(fn: T, { maxSize, resolver, ttl }?: MemoizeOptions<T>): (...args: Parameters<T>) => ReturnType<T>;
|
|
29
|
+
export {};
|
|
30
|
+
//# sourceMappingURL=memo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memo.d.ts","sourceRoot":"","sources":["../../src/function/memo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,UAAU,CAAC;AAGnC,KAAK,cAAc,CAAC,CAAC,SAAS,EAAE,IAAI;IAClC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,MAAM,CAAC;IAC9C,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAQF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,EAAE,EAC/B,EAAE,EAAE,CAAC,EACL,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAE,cAAc,CAAC,CAAC,CAAM,GACjD,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,CAqC3C"}
|
package/dist/function/memo.js
CHANGED
|
@@ -1,25 +1,17 @@
|
|
|
1
|
-
function
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
14
|
-
return (...t) => {
|
|
15
|
-
const e = s(t), r = Date.now(), u = n.get(e);
|
|
16
|
-
if (u && (!i || r - u.timestamp < i))
|
|
17
|
-
return n.delete(e), n.set(e, u), u.value;
|
|
18
|
-
const f = l(...t);
|
|
19
|
-
return n.set(e, { timestamp: r, value: f }), o && n.size > o && n.delete(n.keys().next().value), f;
|
|
20
|
-
};
|
|
1
|
+
//#region src/function/memo.ts
|
|
2
|
+
function e(e, { maxSize: t, resolver: n, ttl: r } = {}) {
|
|
3
|
+
let i = /* @__PURE__ */ new Map(), a = (e) => n ? n(...e) : JSON.stringify(e, (e, t) => t === void 0 ? "__undefined__" : t);
|
|
4
|
+
return (...n) => {
|
|
5
|
+
let o = a(n), s = Date.now(), c = i.get(o);
|
|
6
|
+
if (c && (!r || s - c.timestamp < r)) return i.delete(o), i.set(o, c), c.value;
|
|
7
|
+
let l = e(...n);
|
|
8
|
+
return i.set(o, {
|
|
9
|
+
timestamp: s,
|
|
10
|
+
value: l
|
|
11
|
+
}), l instanceof Promise && l.catch(() => i.delete(o)), t && i.size > t && i.delete(i.keys().next().value), l;
|
|
12
|
+
};
|
|
21
13
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
//# sourceMappingURL=memo.js.map
|
|
14
|
+
//#endregion
|
|
15
|
+
export { e as memo };
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=memo.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memo.js","sources":["../../src/function/memo.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"memo.js","names":[],"sources":["../../src/function/memo.ts"],"sourcesContent":["import type { Fn } from '../types';\n\n// #region MemoizeOptions\ntype MemoizeOptions<T extends Fn> = {\n maxSize?: number; // Maximum number of items in cache\n resolver?: (...args: Parameters<T>) => string; // Custom key generator\n ttl?: number; // Time-to-live in milliseconds\n};\n// #endregion MemoizeOptions\n\ntype CacheEntry<T extends Fn> = {\n timestamp: number;\n value: ReturnType<T>;\n};\n\n/**\n * Creates a function that memorizes the result of the provided function.\n * Supports expiration (TTL) and limited cache size (LRU).\n *\n * @example\n * ```ts\n * const add = (x, y) => x + y;\n * const memoizedAdd = memo(add, { ttl: 5000, maxSize: 10 });\n *\n * memoizedAdd(1, 2); // 3 (caches the result)\n * memoizedAdd(1, 2); // 3 (from cache)\n * ```\n *\n * @param fn - The function to memorize.\n * @param options - Memoization options.\n * @param [options.ttl] - (optional) time-to-live (TTL) for cache expiration (in milliseconds).\n * @param [options.maxSize] - (optional) maximum cache size (LRU eviction).\n * @param [options.resolver] - (optional) custom function to resolve the cache key.\n *\n * @returns A new function that memorizes the input function.\n */\nexport function memo<T extends Fn>(\n fn: T,\n { maxSize, resolver, ttl }: MemoizeOptions<T> = {},\n): (...args: Parameters<T>) => ReturnType<T> {\n const cache = new Map<string, CacheEntry<T>>();\n\n const keyGen = (args: Parameters<T>): string => {\n if (resolver) return resolver(...args);\n\n // Use a replacer to distinguish undefined from null (JSON.stringify collapses both to null)\n return JSON.stringify(args, (_, v) => (v === undefined ? '__undefined__' : v));\n };\n\n return (...args: Parameters<T>): ReturnType<T> => {\n const key = keyGen(args);\n const now = Date.now();\n const cached = cache.get(key);\n\n if (cached && (!ttl || now - cached.timestamp < ttl)) {\n cache.delete(key);\n cache.set(key, cached); // Move to end (most recently used)\n\n return cached.value;\n }\n\n const result = fn(...args);\n\n cache.set(key, { timestamp: now, value: result });\n\n if (result instanceof Promise) {\n // Evict on rejection so subsequent calls retry instead of returning a settled failure\n (result as Promise<unknown>).catch(() => cache.delete(key));\n }\n\n if (maxSize && cache.size > maxSize) {\n cache.delete(cache.keys().next().value!); // Remove least recently used\n }\n\n return result;\n };\n}\n"],"mappings":";AAoCA,SAAgB,EACd,GACA,EAAE,YAAS,aAAU,WAA2B,EAAE,EACP;CAC3C,IAAM,oBAAQ,IAAI,KAA4B,EAExC,KAAU,MACV,IAAiB,EAAS,GAAG,EAAK,GAG/B,KAAK,UAAU,IAAO,GAAG,MAAO,MAAM,KAAA,IAAY,kBAAkB,EAAG;AAGhF,SAAQ,GAAG,MAAuC;EAChD,IAAM,IAAM,EAAO,EAAK,EAClB,IAAM,KAAK,KAAK,EAChB,IAAS,EAAM,IAAI,EAAI;AAE7B,MAAI,MAAW,CAAC,KAAO,IAAM,EAAO,YAAY,GAI9C,QAHA,EAAM,OAAO,EAAI,EACjB,EAAM,IAAI,GAAK,EAAO,EAEf,EAAO;EAGhB,IAAM,IAAS,EAAG,GAAG,EAAK;AAa1B,SAXA,EAAM,IAAI,GAAK;GAAE,WAAW;GAAK,OAAO;GAAQ,CAAC,EAE7C,aAAkB,WAEnB,EAA4B,YAAY,EAAM,OAAO,EAAI,CAAC,EAGzD,KAAW,EAAM,OAAO,KAC1B,EAAM,OAAO,EAAM,MAAM,CAAC,MAAM,CAAC,MAAO,EAGnC"}
|
package/dist/function/once.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=once.cjs.map
|
|
1
|
+
var e=e=>{let t,n=!1,r=((...r)=>(n||=(t=e(...r),!0),t));return r.reset=()=>{t=void 0,n=!1},r};exports.once=e;
|
|
2
|
+
//# sourceMappingURL=once.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"once.cjs","sources":["../../src/function/once.ts"],"sourcesContent":["import type { Fn } from '../types';\n\n/**\n * Create a function that runs once and returns the first result.\n *\n * @example\n * ```ts\n * const onceRandom = once(() => Math.random())\n * onceRandom() // 0.3\n * onceRandom() // 0.3\n *\n * onceRandom.reset()\n *\n * onceRandom() // 0.2\n * onceRandom() // 0.2\n * ```\n *\n * @param fn - The function to wrap.\n *\n * @returns A function that can only be called once.\n */\nexport const once = <T extends Fn>(fn: T): T & { reset: () => void } => {\n let result: ReturnType<T> | undefined;\n let called = false;\n\n const wrappedFn = ((...args: Parameters<T>): ReturnType<T> => {\n if (!called) {\n result = fn(...args);\n called = true;\n }\n return result as ReturnType<T>;\n }) as T & { reset: () => void };\n\n wrappedFn.reset = () => {\n result = undefined;\n called = false;\n };\n\n return wrappedFn;\n};\n"],"
|
|
1
|
+
{"version":3,"file":"once.cjs","names":[],"sources":["../../src/function/once.ts"],"sourcesContent":["import type { Fn } from '../types';\n\n/**\n * Create a function that runs once and returns the first result.\n *\n * @example\n * ```ts\n * const onceRandom = once(() => Math.random())\n * onceRandom() // 0.3\n * onceRandom() // 0.3\n *\n * onceRandom.reset()\n *\n * onceRandom() // 0.2\n * onceRandom() // 0.2\n * ```\n *\n * @param fn - The function to wrap.\n *\n * @returns A function that can only be called once.\n */\nexport const once = <T extends Fn>(fn: T): T & { reset: () => void } => {\n let result: ReturnType<T> | undefined;\n let called = false;\n\n const wrappedFn = ((...args: Parameters<T>): ReturnType<T> => {\n if (!called) {\n result = fn(...args);\n called = true;\n }\n\n return result as ReturnType<T>;\n }) as T & { reset: () => void };\n\n wrappedFn.reset = () => {\n result = undefined;\n called = false;\n };\n\n return wrappedFn;\n};\n"],"mappings":"AAqBA,IAAa,EAAsB,GAAqC,CACtE,IAAI,EACA,EAAS,GAEP,IAAc,GAAG,KACrB,AAEE,KADA,EAAS,EAAG,GAAG,EAAK,CACX,IAGJ,IAQT,MALA,GAAU,UAAc,CACtB,EAAS,IAAA,GACT,EAAS,IAGJ"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Fn } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Create a function that runs once and returns the first result.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* const onceRandom = once(() => Math.random())
|
|
8
|
+
* onceRandom() // 0.3
|
|
9
|
+
* onceRandom() // 0.3
|
|
10
|
+
*
|
|
11
|
+
* onceRandom.reset()
|
|
12
|
+
*
|
|
13
|
+
* onceRandom() // 0.2
|
|
14
|
+
* onceRandom() // 0.2
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @param fn - The function to wrap.
|
|
18
|
+
*
|
|
19
|
+
* @returns A function that can only be called once.
|
|
20
|
+
*/
|
|
21
|
+
export declare const once: <T extends Fn>(fn: T) => T & {
|
|
22
|
+
reset: () => void;
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=once.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"once.d.ts","sourceRoot":"","sources":["../../src/function/once.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,UAAU,CAAC;AAEnC;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,IAAI,GAAI,CAAC,SAAS,EAAE,EAAE,IAAI,CAAC,KAAG,CAAC,GAAG;IAAE,KAAK,EAAE,MAAM,IAAI,CAAA;CAmBjE,CAAC"}
|
package/dist/function/once.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
//#region src/function/once.ts
|
|
2
|
+
var e = (e) => {
|
|
3
|
+
let t, n = !1, r = ((...r) => (n ||= (t = e(...r), !0), t));
|
|
4
|
+
return r.reset = () => {
|
|
5
|
+
t = void 0, n = !1;
|
|
6
|
+
}, r;
|
|
7
7
|
};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
//# sourceMappingURL=once.js.map
|
|
8
|
+
//#endregion
|
|
9
|
+
export { e as once };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=once.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"once.js","sources":["../../src/function/once.ts"],"sourcesContent":["import type { Fn } from '../types';\n\n/**\n * Create a function that runs once and returns the first result.\n *\n * @example\n * ```ts\n * const onceRandom = once(() => Math.random())\n * onceRandom() // 0.3\n * onceRandom() // 0.3\n *\n * onceRandom.reset()\n *\n * onceRandom() // 0.2\n * onceRandom() // 0.2\n * ```\n *\n * @param fn - The function to wrap.\n *\n * @returns A function that can only be called once.\n */\nexport const once = <T extends Fn>(fn: T): T & { reset: () => void } => {\n let result: ReturnType<T> | undefined;\n let called = false;\n\n const wrappedFn = ((...args: Parameters<T>): ReturnType<T> => {\n if (!called) {\n result = fn(...args);\n called = true;\n }\n return result as ReturnType<T>;\n }) as T & { reset: () => void };\n\n wrappedFn.reset = () => {\n result = undefined;\n called = false;\n };\n\n return wrappedFn;\n};\n"],"
|
|
1
|
+
{"version":3,"file":"once.js","names":[],"sources":["../../src/function/once.ts"],"sourcesContent":["import type { Fn } from '../types';\n\n/**\n * Create a function that runs once and returns the first result.\n *\n * @example\n * ```ts\n * const onceRandom = once(() => Math.random())\n * onceRandom() // 0.3\n * onceRandom() // 0.3\n *\n * onceRandom.reset()\n *\n * onceRandom() // 0.2\n * onceRandom() // 0.2\n * ```\n *\n * @param fn - The function to wrap.\n *\n * @returns A function that can only be called once.\n */\nexport const once = <T extends Fn>(fn: T): T & { reset: () => void } => {\n let result: ReturnType<T> | undefined;\n let called = false;\n\n const wrappedFn = ((...args: Parameters<T>): ReturnType<T> => {\n if (!called) {\n result = fn(...args);\n called = true;\n }\n\n return result as ReturnType<T>;\n }) as T & { reset: () => void };\n\n wrappedFn.reset = () => {\n result = undefined;\n called = false;\n };\n\n return wrappedFn;\n};\n"],"mappings":";AAqBA,IAAa,KAAsB,MAAqC;CACtE,IAAI,GACA,IAAS,IAEP,MAAc,GAAG,OACrB,AAEE,OADA,IAAS,EAAG,GAAG,EAAK,EACX,KAGJ;AAQT,QALA,EAAU,cAAc;AAEtB,EADA,IAAS,KAAA,GACT,IAAS;IAGJ"}
|