@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
package/README.md
ADDED
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
# @vielzeug/toolkit
|
|
2
|
+
|
|
3
|
+
> Typed utility functions for everyday TypeScript — arrays, objects, strings, async, dates, math, and more
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@vielzeug/toolkit) [](https://opensource.org/licenses/MIT)
|
|
6
|
+
|
|
7
|
+
**Toolkit** is a tree-shakeable collection of TypeScript utility functions covering arrays, objects, strings, async control-flow, dates, math, money, and type guards — all individually importable with full type inference and zero dependencies.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
pnpm add @vielzeug/toolkit
|
|
13
|
+
# npm install @vielzeug/toolkit
|
|
14
|
+
# yarn add @vielzeug/toolkit
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Quick Start
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { group, chunk, debounce, retry, merge, uuid, is } from '@vielzeug/toolkit';
|
|
21
|
+
|
|
22
|
+
// Group an array by a key
|
|
23
|
+
const byStatus = group(users, (u) => u.status);
|
|
24
|
+
// { active: [...], inactive: [...] }
|
|
25
|
+
|
|
26
|
+
// Split array into chunks
|
|
27
|
+
const pages = chunk([1, 2, 3, 4, 5], 2); // [[1,2],[3,4],[5]]
|
|
28
|
+
|
|
29
|
+
// Debounce an event handler
|
|
30
|
+
const handleSearch = debounce((query: string) => fetchResults(query), 300);
|
|
31
|
+
|
|
32
|
+
// Retry a failing async function
|
|
33
|
+
const result = await retry(() => fetchData(), { times: 3, delay: 200 });
|
|
34
|
+
|
|
35
|
+
// Deep merge objects
|
|
36
|
+
const config = merge('deep', defaults, overrides);
|
|
37
|
+
|
|
38
|
+
// Generate a UUID
|
|
39
|
+
const id = uuid(); // e.g. "550e8400-e29b-41d4-a716-446655440000"
|
|
40
|
+
|
|
41
|
+
// Runtime type checks
|
|
42
|
+
if (is.string(value)) { /* value narrowed to string */ }
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Features
|
|
46
|
+
|
|
47
|
+
- ✅ **Tree-shakeable** — import only what you use
|
|
48
|
+
- ✅ **Type-safe** — full TypeScript inference on every utility
|
|
49
|
+
- ✅ **Array** — `chunk`, `group`, `keyBy`, `fold`, `select`, `toggle`, `rotate`, `replace`, `search`, `uniq`, `sort`, `contains`, `pick`, `list`, `remoteList`
|
|
50
|
+
- ✅ **Object** — `merge`, `diff`, `get`, `seek`, `prune`, `proxy`, `cache`, `parseJSON`
|
|
51
|
+
- ✅ **String** — `camelCase`, `kebabCase`, `pascalCase`, `snakeCase`, `truncate`, `similarity`
|
|
52
|
+
- ✅ **Async** — `retry`, `sleep`, `parallel`, `pool`, `queue`, `race`, `attempt`, `defer`, `waitFor`
|
|
53
|
+
- ✅ **Function** — `debounce`, `throttle`, `memo`, `once`, `pipe`, `compose`, `curry`, `compare`, `fp`
|
|
54
|
+
- ✅ **Math** — `sum`, `average`, `median`, `min`, `max`, `clamp`, `round`, `range`, `percent`, `linspace`, `allocate`, `distribute`
|
|
55
|
+
- ✅ **Date** — `timeDiff`, `interval`, `expires`
|
|
56
|
+
- ✅ **Money** — `currency`, `exchange`
|
|
57
|
+
- ✅ **Random** — `uuid`, `random`, `draw`, `shuffle`
|
|
58
|
+
- ✅ **Type guards** — `is.string`, `is.number`, `is.array`, `is.nil`, `is.equal`, `is.match`, and more
|
|
59
|
+
- ✅ **Zero dependencies**
|
|
60
|
+
|
|
61
|
+
## Usage
|
|
62
|
+
|
|
63
|
+
### Array Utilities
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
import { group, chunk, keyBy, fold, select, toggle, uniq, sort } from '@vielzeug/toolkit';
|
|
67
|
+
|
|
68
|
+
// Group by key
|
|
69
|
+
const byRole = group(users, (u) => u.role); // { admin: [...], user: [...] }
|
|
70
|
+
|
|
71
|
+
// Split into chunks
|
|
72
|
+
const pages = chunk(items, 10); // Item[][]
|
|
73
|
+
|
|
74
|
+
// Index by key
|
|
75
|
+
const byId = keyBy(users, 'id'); // { '1': user1, '2': user2 }
|
|
76
|
+
|
|
77
|
+
// Fold (reduce without initial value)
|
|
78
|
+
fold([1, 2, 3], (a, b) => a + b); // 6
|
|
79
|
+
|
|
80
|
+
// Filter nil elements from source, then map remaining
|
|
81
|
+
select([null, 1, null, 2], (n) => n * 10); // [10, 20]
|
|
82
|
+
|
|
83
|
+
// Filter by predicate, then map
|
|
84
|
+
select([1, 2, 3, 4], (n) => n * 10, (n) => n > 2); // [30, 40]
|
|
85
|
+
|
|
86
|
+
// Toggle item in/out of array
|
|
87
|
+
toggle([1, 2, 3], 2); // [1, 3]
|
|
88
|
+
toggle([1, 2, 3], 4); // [1, 2, 3, 4]
|
|
89
|
+
|
|
90
|
+
// Sort by selector (single-field)
|
|
91
|
+
sort([{ value: 3 }, { value: 1 }], (item) => item.value); // [{ value: 1 }, { value: 3 }]
|
|
92
|
+
|
|
93
|
+
// Sort by object selectors (multi-field)
|
|
94
|
+
sort(
|
|
95
|
+
[
|
|
96
|
+
{ age: 30, name: 'Bob' },
|
|
97
|
+
{ age: 30, name: 'Alice' },
|
|
98
|
+
{ age: 25, name: 'Chris' },
|
|
99
|
+
],
|
|
100
|
+
{ age: 'desc', name: 'asc' },
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
// Remove duplicates
|
|
104
|
+
uniq([1, 2, 2, 3]); // [1, 2, 3]
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Object Utilities
|
|
108
|
+
|
|
109
|
+
```typescript
|
|
110
|
+
import { merge, diff, get, seek, prune, parseJSON } from '@vielzeug/toolkit';
|
|
111
|
+
|
|
112
|
+
// Deep merge
|
|
113
|
+
const cfg = merge('deep', { api: { host: 'localhost' } }, { api: { port: 3000 } });
|
|
114
|
+
// { api: { host: 'localhost', port: 3000 } }
|
|
115
|
+
|
|
116
|
+
// Nested path access
|
|
117
|
+
get(cfg, 'api.host'); // 'localhost'
|
|
118
|
+
|
|
119
|
+
// Recursively search object values by similarity
|
|
120
|
+
seek(cfg, 'localhost', 1); // true (exact match)
|
|
121
|
+
|
|
122
|
+
// Remove nulls/empty values
|
|
123
|
+
prune({ a: 1, b: null, c: '' }); // { a: 1 }
|
|
124
|
+
|
|
125
|
+
// Safe JSON parse
|
|
126
|
+
parseJSON('{"a":1}', {}); // { a: 1 }
|
|
127
|
+
parseJSON('bad json', {}); // {}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Async Utilities
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
import { retry, sleep, parallel, pool, race, attempt, waitFor } from '@vielzeug/toolkit';
|
|
134
|
+
|
|
135
|
+
// Retry with backoff
|
|
136
|
+
const result = await retry(() => fetchData(), { times: 3, delay: 200, backoff: 2 });
|
|
137
|
+
|
|
138
|
+
// Delay
|
|
139
|
+
await sleep(500);
|
|
140
|
+
|
|
141
|
+
// Process items with concurrency limit
|
|
142
|
+
const results = await parallel(5, urls, async (url) => fetch(url).then((r) => r.json()));
|
|
143
|
+
|
|
144
|
+
// Race promise against minimum delay (prevents loading flicker)
|
|
145
|
+
const data = await race(fetchUser(id), 300);
|
|
146
|
+
|
|
147
|
+
// Attempt with explicit success/failure handling
|
|
148
|
+
const userAttempt = await attempt(fetchUser, { times: 2, timeout: 5000 });
|
|
149
|
+
if (userAttempt.ok) {
|
|
150
|
+
console.log(userAttempt.value);
|
|
151
|
+
} else {
|
|
152
|
+
console.error(userAttempt.error);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Poll until condition is true
|
|
156
|
+
await waitFor(() => document.querySelector('#app') !== null, { timeout: 5000 });
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### String Utilities
|
|
160
|
+
|
|
161
|
+
```typescript
|
|
162
|
+
import { camelCase, kebabCase, snakeCase, pascalCase, truncate, similarity } from '@vielzeug/toolkit';
|
|
163
|
+
|
|
164
|
+
camelCase('hello-world'); // 'helloWorld'
|
|
165
|
+
kebabCase('helloWorld'); // 'hello-world'
|
|
166
|
+
snakeCase('helloWorld'); // 'hello_world'
|
|
167
|
+
pascalCase('hello-world'); // 'HelloWorld'
|
|
168
|
+
truncate('A very long string', 10); // 'A very lon...'
|
|
169
|
+
similarity('hello', 'hallo'); // ~0.8
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Function Utilities
|
|
173
|
+
|
|
174
|
+
```typescript
|
|
175
|
+
import { memo, once, pipe, debounce, throttle, compare } from '@vielzeug/toolkit';
|
|
176
|
+
|
|
177
|
+
const fib = memo((n: number): number => n <= 1 ? n : fib(n - 1) + fib(n - 2));
|
|
178
|
+
const init = once(() => bootstrap());
|
|
179
|
+
const process = pipe(trim, normalize, validate);
|
|
180
|
+
const search = debounce(fetchResults, 300);
|
|
181
|
+
const scroll = throttle(updatePosition, 16);
|
|
182
|
+
|
|
183
|
+
// Compare → always -1 | 0 | 1 (safe for sort)
|
|
184
|
+
compare(1, 2); // -1
|
|
185
|
+
compare('b', 'a'); // 1
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### Math Utilities
|
|
189
|
+
|
|
190
|
+
```typescript
|
|
191
|
+
import { sum, average, clamp, round, range, percent, linspace } from '@vielzeug/toolkit';
|
|
192
|
+
|
|
193
|
+
sum([1, 2, 3, 4]); // 10
|
|
194
|
+
average([10, 20, 30]); // 20
|
|
195
|
+
clamp(105, 0, 100); // 100
|
|
196
|
+
round(Math.PI, 4); // 3.1416
|
|
197
|
+
range(1, 6, 1); // [1, 2, 3, 4, 5]
|
|
198
|
+
percent(25, 100); // 25
|
|
199
|
+
linspace(0, 10, 5); // [0, 2.5, 5, 7.5, 10]
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### Date Utilities
|
|
203
|
+
|
|
204
|
+
```typescript
|
|
205
|
+
import { timeDiff, interval, expires } from '@vielzeug/toolkit';
|
|
206
|
+
|
|
207
|
+
// Human-readable time difference
|
|
208
|
+
timeDiff(new Date('2025-01-01'), new Date());
|
|
209
|
+
// e.g. { value: 2, unit: 'MONTH' }
|
|
210
|
+
|
|
211
|
+
// Generate date range
|
|
212
|
+
interval('2024-01-01', '2024-01-07', { interval: 'day' });
|
|
213
|
+
// [Date, Date, Date, Date, Date, Date, Date]
|
|
214
|
+
|
|
215
|
+
// Check expiration
|
|
216
|
+
expires('2023-01-01'); // e.g. 'EXPIRED'
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### Type Guards
|
|
220
|
+
|
|
221
|
+
```typescript
|
|
222
|
+
import { is } from '@vielzeug/toolkit';
|
|
223
|
+
|
|
224
|
+
is.string(v);
|
|
225
|
+
is.number(v);
|
|
226
|
+
is.boolean(v);
|
|
227
|
+
is.array(v);
|
|
228
|
+
is.object(v);
|
|
229
|
+
is.fn(v);
|
|
230
|
+
is.date(v);
|
|
231
|
+
is.promise(v);
|
|
232
|
+
is.regex(v);
|
|
233
|
+
is.nil(v);
|
|
234
|
+
is.defined(v);
|
|
235
|
+
is.primitive(v);
|
|
236
|
+
is.empty(v);
|
|
237
|
+
is.equal(a, b);
|
|
238
|
+
is.match(obj, src);
|
|
239
|
+
is.even(n);
|
|
240
|
+
is.odd(n);
|
|
241
|
+
is.positive(n);
|
|
242
|
+
is.negative(n);
|
|
243
|
+
is.zero(n);
|
|
244
|
+
is.within(n, min, max);
|
|
245
|
+
is.ge(a, b);
|
|
246
|
+
is.gt(a, b);
|
|
247
|
+
is.le(a, b);
|
|
248
|
+
is.lt(a, b);
|
|
249
|
+
is.typeOf(v); // e.g. 'string' | 'number' | 'array'
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
## API
|
|
253
|
+
|
|
254
|
+
### Array
|
|
255
|
+
|
|
256
|
+
| Function | Description |
|
|
257
|
+
|---|---|
|
|
258
|
+
| `chunk(arr, size)` | Split array into chunks of given size |
|
|
259
|
+
| `contains(arr, value)` | Check if array contains a value (deep equality) |
|
|
260
|
+
| `fold(arr, fn)` | Reduce without initial value |
|
|
261
|
+
| `group(arr, selector)` | Group by key — returns `Record<string, T[]>` |
|
|
262
|
+
| `keyBy(arr, selector)` | Index by key — returns `Record<string, T>` |
|
|
263
|
+
| `list(data, opts?)` | Reactive client-side pagination |
|
|
264
|
+
| `pick(arr, valueFn, predicate?)` | Pick single transformed element |
|
|
265
|
+
| `remoteList(opts)` | Reactive server-side pagination |
|
|
266
|
+
| `replace(arr, predicate, value)` | Replace first matching element |
|
|
267
|
+
| `rotate(arr, n, opts?)` | Rotate elements by N positions |
|
|
268
|
+
| `search(arr, query, opts?)` | Fuzzy search |
|
|
269
|
+
| `select(arr, mapper, predicate?)` | Map elements matching predicate (default: not nil) |
|
|
270
|
+
| `sort(arr, selector, direction?)` | Sort by selector with `'asc'`/`'desc'` direction |
|
|
271
|
+
| `sort(arr, selectors)` | Sort by multiple fields using object selectors |
|
|
272
|
+
| `toggle(arr, item, selector?, opts?)` | Add or remove item |
|
|
273
|
+
| `uniq(arr)` | Remove duplicates |
|
|
274
|
+
|
|
275
|
+
### Object
|
|
276
|
+
|
|
277
|
+
| Function | Description |
|
|
278
|
+
|---|---|
|
|
279
|
+
| `cache()` | Key-value cache with auto GC |
|
|
280
|
+
| `diff(a, b)` | Find differences between objects |
|
|
281
|
+
| `merge(strategy, ...objs)` | Merge objects (deep/shallow/concat) |
|
|
282
|
+
| `parseJSON(str, fallback?)` | Safe JSON parse |
|
|
283
|
+
| `get(obj, path, default?)` | Access nested property by dot-path |
|
|
284
|
+
| `proxy(obj, opts)` | Object proxy with get/set hooks |
|
|
285
|
+
| `prune(value)` | Remove nulls/empty values recursively |
|
|
286
|
+
| `seek(obj, query, tone?)` | Search object values by similarity score |
|
|
287
|
+
|
|
288
|
+
### String
|
|
289
|
+
|
|
290
|
+
| Function | Description |
|
|
291
|
+
|---|---|
|
|
292
|
+
| `camelCase(str)` | Convert to camelCase |
|
|
293
|
+
| `kebabCase(str)` | Convert to kebab-case |
|
|
294
|
+
| `pascalCase(str)` | Convert to PascalCase |
|
|
295
|
+
| `similarity(a, b)` | Similarity score (0–1) between two strings |
|
|
296
|
+
| `snakeCase(str)` | Convert to snake_case |
|
|
297
|
+
| `truncate(str, limit)` | Truncate with ellipsis |
|
|
298
|
+
|
|
299
|
+
### Function
|
|
300
|
+
|
|
301
|
+
| Function | Description |
|
|
302
|
+
|---|---|
|
|
303
|
+
| `assert(cond, msg, opts?)` | Assert condition, throw on failure |
|
|
304
|
+
| `assertParams(params, keys)` | Validate required object keys |
|
|
305
|
+
| `compare(a, b)` | Safe comparator returning -1 \| 0 \| 1 |
|
|
306
|
+
| `compareBy(criteria)` | Multi-key object comparator |
|
|
307
|
+
| `compose(...fns)` | Right-to-left function composition |
|
|
308
|
+
| `curry(fn)` | Curry with partial application |
|
|
309
|
+
| `debounce(fn, ms)` | Delay execution until idle |
|
|
310
|
+
| `fp(fn, ...args)` | Functional pipeline helper |
|
|
311
|
+
| `memo(fn)` | Cache results by arguments |
|
|
312
|
+
| `once(fn)` | Execute only on first call |
|
|
313
|
+
| `pipe(...fns)` | Left-to-right function composition |
|
|
314
|
+
| `throttle(fn, ms)` | Limit execution rate |
|
|
315
|
+
|
|
316
|
+
### Async
|
|
317
|
+
|
|
318
|
+
| Function | Description |
|
|
319
|
+
|---|---|
|
|
320
|
+
| `attempt(fn, opts?)` | Execute with retry and error handling |
|
|
321
|
+
| `defer()` | Deferred promise with external resolve/reject |
|
|
322
|
+
| `parallel(n, items, fn, signal?)` | Process array with concurrency limit |
|
|
323
|
+
| `pool(n)` | Concurrency-limited promise pool |
|
|
324
|
+
| `queue(opts?)` | Sequential/concurrent task queue |
|
|
325
|
+
| `race(promise, minDelay)` | Race promise against minimum delay |
|
|
326
|
+
| `retry(fn, opts?)` | Retry with backoff |
|
|
327
|
+
| `sleep(ms)` | Async delay |
|
|
328
|
+
| `waitFor(cond, opts?)` | Poll until condition is true |
|
|
329
|
+
|
|
330
|
+
### Math
|
|
331
|
+
|
|
332
|
+
| Function | Description |
|
|
333
|
+
|---|---|
|
|
334
|
+
| `abs(n)` | Absolute value |
|
|
335
|
+
| `allocate(amount, ratios)` | Distribute proportionally (bigint) |
|
|
336
|
+
| `average(arr, fn?)` | Average of numbers |
|
|
337
|
+
| `clamp(n, min, max)` | Clamp to range |
|
|
338
|
+
| `distribute(amount, n)` | Distribute evenly (bigint) |
|
|
339
|
+
| `linspace(start, end, steps?)` | Evenly spaced number array |
|
|
340
|
+
| `max(arr, fn?)` | Maximum value |
|
|
341
|
+
| `median(arr, fn?)` | Median value |
|
|
342
|
+
| `min(arr, fn?)` | Minimum value |
|
|
343
|
+
| `percent(value, total)` | Percentage (0–100) |
|
|
344
|
+
| `range(start, end, step?)` | Generate number array |
|
|
345
|
+
| `round(n, precision?)` | Round to decimal places |
|
|
346
|
+
| `sum(arr, fn?)` | Sum of numbers |
|
|
347
|
+
|
|
348
|
+
### Date
|
|
349
|
+
|
|
350
|
+
| Function | Description |
|
|
351
|
+
|---|---|
|
|
352
|
+
| `expires(date)` | Check expiration status |
|
|
353
|
+
| `interval(start, end, opts?)` | Generate date array for a range |
|
|
354
|
+
| `timeDiff(a, b?, units?)` | Time difference as `{ value, unit }` |
|
|
355
|
+
|
|
356
|
+
### Money
|
|
357
|
+
|
|
358
|
+
| Function | Description |
|
|
359
|
+
|---|---|
|
|
360
|
+
| `currency(money)` | Format for display |
|
|
361
|
+
| `exchange(money, opts)` | Convert between currencies |
|
|
362
|
+
|
|
363
|
+
### Random
|
|
364
|
+
|
|
365
|
+
| Function | Description |
|
|
366
|
+
|---|---|
|
|
367
|
+
| `draw(arr)` | Random element from array |
|
|
368
|
+
| `random(min, max)` | Random number in range |
|
|
369
|
+
| `shuffle(arr)` | Shuffle array |
|
|
370
|
+
| `uuid()` | Generate UUID v4 |
|
|
371
|
+
|
|
372
|
+
### Type Guards (`is` namespace)
|
|
373
|
+
|
|
374
|
+
All type checks live on the `is` object:
|
|
375
|
+
|
|
376
|
+
```typescript
|
|
377
|
+
import { is } from '@vielzeug/toolkit';
|
|
378
|
+
|
|
379
|
+
is.string(v);
|
|
380
|
+
is.number(v);
|
|
381
|
+
is.boolean(v);
|
|
382
|
+
is.array(v);
|
|
383
|
+
is.object(v);
|
|
384
|
+
is.fn(v);
|
|
385
|
+
is.date(v);
|
|
386
|
+
is.promise(v);
|
|
387
|
+
is.regex(v);
|
|
388
|
+
is.nil(v);
|
|
389
|
+
is.defined(v);
|
|
390
|
+
is.primitive(v);
|
|
391
|
+
is.empty(v);
|
|
392
|
+
is.equal(a, b);
|
|
393
|
+
is.match(obj, src);
|
|
394
|
+
is.even(n);
|
|
395
|
+
is.odd(n);
|
|
396
|
+
is.positive(n);
|
|
397
|
+
is.negative(n);
|
|
398
|
+
is.zero(n);
|
|
399
|
+
is.within(n, min, max);
|
|
400
|
+
is.ge(a, b);
|
|
401
|
+
is.gt(a, b);
|
|
402
|
+
is.le(a, b);
|
|
403
|
+
is.lt(a, b);
|
|
404
|
+
is.typeOf(v); // e.g. 'string' | 'number' | 'array'
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
## Documentation
|
|
408
|
+
|
|
409
|
+
Full docs at **[vielzeug.dev/toolkit](https://vielzeug.dev/toolkit)**
|
|
410
|
+
|
|
411
|
+
| | |
|
|
412
|
+
|---|---|
|
|
413
|
+
| [Usage Guide](https://vielzeug.dev/toolkit/usage) | Arrays, objects, async, strings |
|
|
414
|
+
| [API Reference](https://vielzeug.dev/toolkit/api) | Complete function signatures |
|
|
415
|
+
| [Examples](https://vielzeug.dev/toolkit/examples) | Real-world utility patterns |
|
|
416
|
+
|
|
417
|
+
## License
|
|
418
|
+
|
|
419
|
+
MIT © [Helmuth Saatkamp](https://github.com/helmuthdu) — Part of the [Vielzeug](https://github.com/helmuthdu/vielzeug) monorepo.
|
package/dist/array/chunk.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=chunk.cjs.map
|
|
1
|
+
const e=require(`../function/assert.cjs`),t=require(`../typed/isArray.cjs`),n=require(`../typed/isString.cjs`);function r(r,i=2,a={}){e.assert(t.isArray(r)||n.isString(r),`Argument must be an array or string.`,{args:{input:r},type:TypeError}),e.assert(i>=1,`Chunk size must be at least 1.`,{args:{size:i},type:RangeError});let{overlap:o=!1,pad:s=` `}=a;if(n.isString(r)&&o){let e=s+r+s,t=e.length-i+1;return Array.from({length:t},(t,n)=>e.slice(n,n+i))}return Array.from({length:Math.ceil(r.length/i)},(e,t)=>r.slice(t*i,t*i+i))}exports.chunk=r;
|
|
2
|
+
//# sourceMappingURL=chunk.cjs.map
|
package/dist/array/chunk.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chunk.cjs","sources":["../../src/array/chunk.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { isArray } from '../typed/isArray';\nimport { isString } from '../typed/isString';\n\n// #region ChunkTypes\ntype ChunkOptions = {\n overlap?: boolean;\n pad?: string;\n};\n\ntype ChunkResult<T> = (T extends string ? string : T[])[];\n// #endregion ChunkTypes\n\n/**\n * Splits an array or string into chunks of a specified size.\n *\n * @example\n * ```ts\n * chunk([1, 2, 3, 4, 5], 2) // [[1, 2], [3, 4], [5]]\n * chunk(\"hello\", 2) // [\"he\", \"ll\", \"o\"]\n * chunk(\"hello\", 2, { overlap: true }) // [\" h\", \"he\", \"el\", \"ll\", \"lo\", \"o \"]\n * ```\n *\n * @param input - The input array or string to be chunked.\n * @param size - The size of each chunk.\n * @param [options] - Additional options for chunking.\n * @param [options.overlap] -\n * @param [options.pad] -\n *\n * @returns An array of chunks.\n *\n * @throws {RangeError} If the chunk size is invalid.\n * @throws {TypeError} If the input type is invalid.\n */\nexport function chunk<T>(input: T[] | string, size = 2, options: ChunkOptions = {}): ChunkResult<T> {\n assert(isArray(input as T[]) || isString(input), 'Argument must be an array or string.', {\n args: { input },\n type: TypeError,\n });\n\n assert(size >= 1, 'Chunk size must be at least 1.', {\n args: { size },\n type: RangeError,\n });\n\n const { overlap = false, pad = ' ' } = options;\n\n if (isString(input) && overlap) {\n const padded = pad + input + pad;\n const numChunks = padded.length - size + 1;\n return Array.from({ length: numChunks }, (_, i) => padded.slice(i, i + size)) as ChunkResult<T>;\n }\n\n return Array.from({ length: Math.ceil(input.length / size) }, (_, i) =>\n input.slice(i * size, i * size + size),\n ) as ChunkResult<T>;\n}\n"],"
|
|
1
|
+
{"version":3,"file":"chunk.cjs","names":[],"sources":["../../src/array/chunk.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { isArray } from '../typed/isArray';\nimport { isString } from '../typed/isString';\n\n// #region ChunkTypes\ntype ChunkOptions = {\n overlap?: boolean;\n pad?: string;\n};\n\ntype ChunkResult<T> = (T extends string ? string : T[])[];\n// #endregion ChunkTypes\n\n/**\n * Splits an array or string into chunks of a specified size.\n *\n * @example\n * ```ts\n * chunk([1, 2, 3, 4, 5], 2) // [[1, 2], [3, 4], [5]]\n * chunk(\"hello\", 2) // [\"he\", \"ll\", \"o\"]\n * chunk(\"hello\", 2, { overlap: true }) // [\" h\", \"he\", \"el\", \"ll\", \"lo\", \"o \"]\n * ```\n *\n * @param input - The input array or string to be chunked.\n * @param size - The size of each chunk.\n * @param [options] - Additional options for chunking.\n * @param [options.overlap] -\n * @param [options.pad] -\n *\n * @returns An array of chunks.\n *\n * @throws {RangeError} If the chunk size is invalid.\n * @throws {TypeError} If the input type is invalid.\n */\nexport function chunk<T>(input: T[] | string, size = 2, options: ChunkOptions = {}): ChunkResult<T> {\n assert(isArray(input as T[]) || isString(input), 'Argument must be an array or string.', {\n args: { input },\n type: TypeError,\n });\n\n assert(size >= 1, 'Chunk size must be at least 1.', {\n args: { size },\n type: RangeError,\n });\n\n const { overlap = false, pad = ' ' } = options;\n\n if (isString(input) && overlap) {\n const padded = pad + input + pad;\n const numChunks = padded.length - size + 1;\n\n return Array.from({ length: numChunks }, (_, i) => padded.slice(i, i + size)) as ChunkResult<T>;\n }\n\n return Array.from({ length: Math.ceil(input.length / size) }, (_, i) =>\n input.slice(i * size, i * size + size),\n ) as ChunkResult<T>;\n}\n"],"mappings":"+GAkCA,SAAgB,EAAS,EAAqB,EAAO,EAAG,EAAwB,EAAE,CAAkB,CAClG,EAAA,OAAO,EAAA,QAAQ,EAAa,EAAI,EAAA,SAAS,EAAM,CAAE,uCAAwC,CACvF,KAAM,CAAE,QAAO,CACf,KAAM,UACP,CAAC,CAEF,EAAA,OAAO,GAAQ,EAAG,iCAAkC,CAClD,KAAM,CAAE,OAAM,CACd,KAAM,WACP,CAAC,CAEF,GAAM,CAAE,UAAU,GAAO,MAAM,KAAQ,EAEvC,GAAI,EAAA,SAAS,EAAM,EAAI,EAAS,CAC9B,IAAM,EAAS,EAAM,EAAQ,EACvB,EAAY,EAAO,OAAS,EAAO,EAEzC,OAAO,MAAM,KAAK,CAAE,OAAQ,EAAW,EAAG,EAAG,IAAM,EAAO,MAAM,EAAG,EAAI,EAAK,CAAC,CAG/E,OAAO,MAAM,KAAK,CAAE,OAAQ,KAAK,KAAK,EAAM,OAAS,EAAK,CAAE,EAAG,EAAG,IAChE,EAAM,MAAM,EAAI,EAAM,EAAI,EAAO,EAAK,CACvC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
type ChunkOptions = {
|
|
2
|
+
overlap?: boolean;
|
|
3
|
+
pad?: string;
|
|
4
|
+
};
|
|
5
|
+
type ChunkResult<T> = (T extends string ? string : T[])[];
|
|
6
|
+
/**
|
|
7
|
+
* Splits an array or string into chunks of a specified size.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* chunk([1, 2, 3, 4, 5], 2) // [[1, 2], [3, 4], [5]]
|
|
12
|
+
* chunk("hello", 2) // ["he", "ll", "o"]
|
|
13
|
+
* chunk("hello", 2, { overlap: true }) // [" h", "he", "el", "ll", "lo", "o "]
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @param input - The input array or string to be chunked.
|
|
17
|
+
* @param size - The size of each chunk.
|
|
18
|
+
* @param [options] - Additional options for chunking.
|
|
19
|
+
* @param [options.overlap] -
|
|
20
|
+
* @param [options.pad] -
|
|
21
|
+
*
|
|
22
|
+
* @returns An array of chunks.
|
|
23
|
+
*
|
|
24
|
+
* @throws {RangeError} If the chunk size is invalid.
|
|
25
|
+
* @throws {TypeError} If the input type is invalid.
|
|
26
|
+
*/
|
|
27
|
+
export declare function chunk<T>(input: T[] | string, size?: number, options?: ChunkOptions): ChunkResult<T>;
|
|
28
|
+
export {};
|
|
29
|
+
//# sourceMappingURL=chunk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunk.d.ts","sourceRoot":"","sources":["../../src/array/chunk.ts"],"names":[],"mappings":"AAKA,KAAK,YAAY,GAAG;IAClB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,KAAK,WAAW,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC;AAG1D;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,MAAM,EAAE,IAAI,SAAI,EAAE,OAAO,GAAE,YAAiB,GAAG,WAAW,CAAC,CAAC,CAAC,CAuBlG"}
|
package/dist/array/chunk.js
CHANGED
|
@@ -1,25 +1,23 @@
|
|
|
1
|
-
import { assert as
|
|
2
|
-
import { isArray as
|
|
3
|
-
import { isString as
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
(o, a) => t.slice(a * r, a * r + r)
|
|
20
|
-
);
|
|
1
|
+
import { assert as e } from "../function/assert.js";
|
|
2
|
+
import { isArray as t } from "../typed/isArray.js";
|
|
3
|
+
import { isString as n } from "../typed/isString.js";
|
|
4
|
+
//#region src/array/chunk.ts
|
|
5
|
+
function r(r, i = 2, a = {}) {
|
|
6
|
+
e(t(r) || n(r), "Argument must be an array or string.", {
|
|
7
|
+
args: { input: r },
|
|
8
|
+
type: TypeError
|
|
9
|
+
}), e(i >= 1, "Chunk size must be at least 1.", {
|
|
10
|
+
args: { size: i },
|
|
11
|
+
type: RangeError
|
|
12
|
+
});
|
|
13
|
+
let { overlap: o = !1, pad: s = " " } = a;
|
|
14
|
+
if (n(r) && o) {
|
|
15
|
+
let e = s + r + s, t = e.length - i + 1;
|
|
16
|
+
return Array.from({ length: t }, (t, n) => e.slice(n, n + i));
|
|
17
|
+
}
|
|
18
|
+
return Array.from({ length: Math.ceil(r.length / i) }, (e, t) => r.slice(t * i, t * i + i));
|
|
21
19
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
//# sourceMappingURL=chunk.js.map
|
|
20
|
+
//#endregion
|
|
21
|
+
export { r as chunk };
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=chunk.js.map
|
package/dist/array/chunk.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chunk.js","sources":["../../src/array/chunk.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { isArray } from '../typed/isArray';\nimport { isString } from '../typed/isString';\n\n// #region ChunkTypes\ntype ChunkOptions = {\n overlap?: boolean;\n pad?: string;\n};\n\ntype ChunkResult<T> = (T extends string ? string : T[])[];\n// #endregion ChunkTypes\n\n/**\n * Splits an array or string into chunks of a specified size.\n *\n * @example\n * ```ts\n * chunk([1, 2, 3, 4, 5], 2) // [[1, 2], [3, 4], [5]]\n * chunk(\"hello\", 2) // [\"he\", \"ll\", \"o\"]\n * chunk(\"hello\", 2, { overlap: true }) // [\" h\", \"he\", \"el\", \"ll\", \"lo\", \"o \"]\n * ```\n *\n * @param input - The input array or string to be chunked.\n * @param size - The size of each chunk.\n * @param [options] - Additional options for chunking.\n * @param [options.overlap] -\n * @param [options.pad] -\n *\n * @returns An array of chunks.\n *\n * @throws {RangeError} If the chunk size is invalid.\n * @throws {TypeError} If the input type is invalid.\n */\nexport function chunk<T>(input: T[] | string, size = 2, options: ChunkOptions = {}): ChunkResult<T> {\n assert(isArray(input as T[]) || isString(input), 'Argument must be an array or string.', {\n args: { input },\n type: TypeError,\n });\n\n assert(size >= 1, 'Chunk size must be at least 1.', {\n args: { size },\n type: RangeError,\n });\n\n const { overlap = false, pad = ' ' } = options;\n\n if (isString(input) && overlap) {\n const padded = pad + input + pad;\n const numChunks = padded.length - size + 1;\n return Array.from({ length: numChunks }, (_, i) => padded.slice(i, i + size)) as ChunkResult<T>;\n }\n\n return Array.from({ length: Math.ceil(input.length / size) }, (_, i) =>\n input.slice(i * size, i * size + size),\n ) as ChunkResult<T>;\n}\n"],"
|
|
1
|
+
{"version":3,"file":"chunk.js","names":[],"sources":["../../src/array/chunk.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { isArray } from '../typed/isArray';\nimport { isString } from '../typed/isString';\n\n// #region ChunkTypes\ntype ChunkOptions = {\n overlap?: boolean;\n pad?: string;\n};\n\ntype ChunkResult<T> = (T extends string ? string : T[])[];\n// #endregion ChunkTypes\n\n/**\n * Splits an array or string into chunks of a specified size.\n *\n * @example\n * ```ts\n * chunk([1, 2, 3, 4, 5], 2) // [[1, 2], [3, 4], [5]]\n * chunk(\"hello\", 2) // [\"he\", \"ll\", \"o\"]\n * chunk(\"hello\", 2, { overlap: true }) // [\" h\", \"he\", \"el\", \"ll\", \"lo\", \"o \"]\n * ```\n *\n * @param input - The input array or string to be chunked.\n * @param size - The size of each chunk.\n * @param [options] - Additional options for chunking.\n * @param [options.overlap] -\n * @param [options.pad] -\n *\n * @returns An array of chunks.\n *\n * @throws {RangeError} If the chunk size is invalid.\n * @throws {TypeError} If the input type is invalid.\n */\nexport function chunk<T>(input: T[] | string, size = 2, options: ChunkOptions = {}): ChunkResult<T> {\n assert(isArray(input as T[]) || isString(input), 'Argument must be an array or string.', {\n args: { input },\n type: TypeError,\n });\n\n assert(size >= 1, 'Chunk size must be at least 1.', {\n args: { size },\n type: RangeError,\n });\n\n const { overlap = false, pad = ' ' } = options;\n\n if (isString(input) && overlap) {\n const padded = pad + input + pad;\n const numChunks = padded.length - size + 1;\n\n return Array.from({ length: numChunks }, (_, i) => padded.slice(i, i + size)) as ChunkResult<T>;\n }\n\n return Array.from({ length: Math.ceil(input.length / size) }, (_, i) =>\n input.slice(i * size, i * size + size),\n ) as ChunkResult<T>;\n}\n"],"mappings":";;;;AAkCA,SAAgB,EAAS,GAAqB,IAAO,GAAG,IAAwB,EAAE,EAAkB;AAMlG,CALA,EAAO,EAAQ,EAAa,IAAI,EAAS,EAAM,EAAE,wCAAwC;EACvF,MAAM,EAAE,UAAO;EACf,MAAM;EACP,CAAC,EAEF,EAAO,KAAQ,GAAG,kCAAkC;EAClD,MAAM,EAAE,SAAM;EACd,MAAM;EACP,CAAC;CAEF,IAAM,EAAE,aAAU,IAAO,SAAM,QAAQ;AAEvC,KAAI,EAAS,EAAM,IAAI,GAAS;EAC9B,IAAM,IAAS,IAAM,IAAQ,GACvB,IAAY,EAAO,SAAS,IAAO;AAEzC,SAAO,MAAM,KAAK,EAAE,QAAQ,GAAW,GAAG,GAAG,MAAM,EAAO,MAAM,GAAG,IAAI,EAAK,CAAC;;AAG/E,QAAO,MAAM,KAAK,EAAE,QAAQ,KAAK,KAAK,EAAM,SAAS,EAAK,EAAE,GAAG,GAAG,MAChE,EAAM,MAAM,IAAI,GAAM,IAAI,IAAO,EAAK,CACvC"}
|
package/dist/array/contains.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=contains.cjs.map
|
|
1
|
+
const e=require(`../function/assert.cjs`),t=require(`../typed/isArray.cjs`),n=require(`../typed/isEqual.cjs`);function r(r,i){return e.assert(t.isArray(r),t.IS_ARRAY_ERROR_MSG,{args:{array:r},type:TypeError}),r.some(e=>n.isEqual(e,i))}exports.contains=r;
|
|
2
|
+
//# sourceMappingURL=contains.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contains.cjs","sources":["../../src/array/contains.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { IS_ARRAY_ERROR_MSG, isArray } from '../typed/isArray';\nimport { isEqual } from '../typed/isEqual';\n\n/**\n * Checks if a value is present in an array.\n *\n * @example\n * ```ts\n * const arr = [1, 2, 3, { a: 1 }, 'hello'];\n * const value = { a: 1 };\n * contains(arr, value) // true;\n * ```\n *\n * @param array - The array to check.\n * @param value - The value to search for.\n *\n * @returns true if the value is present in the array, else false.\n *\n * @throws {TypeError} If the first argument is not an array.\n */\n\
|
|
1
|
+
{"version":3,"file":"contains.cjs","names":[],"sources":["../../src/array/contains.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { IS_ARRAY_ERROR_MSG, isArray } from '../typed/isArray';\nimport { isEqual } from '../typed/isEqual';\n\n/**\n * Checks if a value is present in an array.\n *\n * @example\n * ```ts\n * const arr = [1, 2, 3, { a: 1 }, 'hello'];\n * const value = { a: 1 };\n * contains(arr, value) // true;\n * ```\n *\n * @param array - The array to check.\n * @param value - The value to search for.\n *\n * @returns true if the value is present in the array, else false.\n *\n * @throws {TypeError} If the first argument is not an array.\n */\n\nexport function contains<T>(array: T[], value: unknown): boolean {\n assert(isArray(array), IS_ARRAY_ERROR_MSG, { args: { array }, type: TypeError });\n\n return array.some((val) => isEqual(val, value));\n}\n"],"mappings":"8GAsBA,SAAgB,EAAY,EAAY,EAAyB,CAG/D,OAFA,EAAA,OAAO,EAAA,QAAQ,EAAM,CAAE,EAAA,mBAAoB,CAAE,KAAM,CAAE,QAAO,CAAE,KAAM,UAAW,CAAC,CAEzE,EAAM,KAAM,GAAQ,EAAA,QAAQ,EAAK,EAAM,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if a value is present in an array.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* const arr = [1, 2, 3, { a: 1 }, 'hello'];
|
|
7
|
+
* const value = { a: 1 };
|
|
8
|
+
* contains(arr, value) // true;
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* @param array - The array to check.
|
|
12
|
+
* @param value - The value to search for.
|
|
13
|
+
*
|
|
14
|
+
* @returns true if the value is present in the array, else false.
|
|
15
|
+
*
|
|
16
|
+
* @throws {TypeError} If the first argument is not an array.
|
|
17
|
+
*/
|
|
18
|
+
export declare function contains<T>(array: T[], value: unknown): boolean;
|
|
19
|
+
//# sourceMappingURL=contains.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contains.d.ts","sourceRoot":"","sources":["../../src/array/contains.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;GAgBG;AAEH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAI/D"}
|
package/dist/array/contains.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { assert as e } from "../function/assert.js";
|
|
2
|
-
import { IS_ARRAY_ERROR_MSG as
|
|
3
|
-
import { isEqual as
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
import { IS_ARRAY_ERROR_MSG as t, isArray as n } from "../typed/isArray.js";
|
|
3
|
+
import { isEqual as r } from "../typed/isEqual.js";
|
|
4
|
+
//#region src/array/contains.ts
|
|
5
|
+
function i(i, a) {
|
|
6
|
+
return e(n(i), t, {
|
|
7
|
+
args: { array: i },
|
|
8
|
+
type: TypeError
|
|
9
|
+
}), i.some((e) => r(e, a));
|
|
6
10
|
}
|
|
7
|
-
|
|
8
|
-
export {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
//# sourceMappingURL=contains.js.map
|
|
11
|
+
//#endregion
|
|
12
|
+
export { i as contains };
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=contains.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contains.js","sources":["../../src/array/contains.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { IS_ARRAY_ERROR_MSG, isArray } from '../typed/isArray';\nimport { isEqual } from '../typed/isEqual';\n\n/**\n * Checks if a value is present in an array.\n *\n * @example\n * ```ts\n * const arr = [1, 2, 3, { a: 1 }, 'hello'];\n * const value = { a: 1 };\n * contains(arr, value) // true;\n * ```\n *\n * @param array - The array to check.\n * @param value - The value to search for.\n *\n * @returns true if the value is present in the array, else false.\n *\n * @throws {TypeError} If the first argument is not an array.\n */\n\
|
|
1
|
+
{"version":3,"file":"contains.js","names":[],"sources":["../../src/array/contains.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { IS_ARRAY_ERROR_MSG, isArray } from '../typed/isArray';\nimport { isEqual } from '../typed/isEqual';\n\n/**\n * Checks if a value is present in an array.\n *\n * @example\n * ```ts\n * const arr = [1, 2, 3, { a: 1 }, 'hello'];\n * const value = { a: 1 };\n * contains(arr, value) // true;\n * ```\n *\n * @param array - The array to check.\n * @param value - The value to search for.\n *\n * @returns true if the value is present in the array, else false.\n *\n * @throws {TypeError} If the first argument is not an array.\n */\n\nexport function contains<T>(array: T[], value: unknown): boolean {\n assert(isArray(array), IS_ARRAY_ERROR_MSG, { args: { array }, type: TypeError });\n\n return array.some((val) => isEqual(val, value));\n}\n"],"mappings":";;;;AAsBA,SAAgB,EAAY,GAAY,GAAyB;AAG/D,QAFA,EAAO,EAAQ,EAAM,EAAE,GAAoB;EAAE,MAAM,EAAE,UAAO;EAAE,MAAM;EAAW,CAAC,EAEzE,EAAM,MAAM,MAAQ,EAAQ,GAAK,EAAM,CAAC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require(`../function/assert.cjs`),t=require(`../typed/isArray.cjs`);function n(n,r){e.assert(t.isArray(n),t.IS_ARRAY_ERROR_MSG,{args:{array:n,callback:r},type:TypeError});let i=n[0];for(let e=1;e<n.length;e++)i=r(i,n[e]);return i}exports.fold=n;
|
|
2
|
+
//# sourceMappingURL=fold.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fold.cjs","names":[],"sources":["../../src/array/fold.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { IS_ARRAY_ERROR_MSG, isArray } from '../typed/isArray';\n\n/**\n * Folds an array down to a single value by applying a callback to each pair of\n * elements (reduce without an initial value).\n *\n * @example\n * ```ts\n * fold([1, 2, 3], (a, b) => a + b) // 6\n * fold([1, 2, 3], (a, b) => a > b ? a : b) // 3\n * fold([{ a: 1 }, { a: 2 }], (a, b) => ({ a: a.a + b.a })) // { a: 3 }\n * fold([], (a, b) => a + b) // undefined\n * fold([1], (a, b) => a + b) // 1\n * ```\n *\n * @param array - The array to fold.\n * @param callback - The function to invoke for each pair of elements.\n * @returns The folded value, or `undefined` if the array is empty.\n *\n * @throws {TypeError} If the first argument is not an array.\n */\nexport function fold<T>(array: readonly T[], callback: (a: T, b: T) => T): T | undefined {\n assert(isArray(array), IS_ARRAY_ERROR_MSG, {\n args: { array, callback },\n type: TypeError,\n });\n\n let result = array[0];\n\n for (let i = 1; i < array.length; i++) {\n result = callback(result, array[i]);\n }\n\n return result;\n}\n"],"mappings":"4EAsBA,SAAgB,EAAQ,EAAqB,EAA4C,CACvF,EAAA,OAAO,EAAA,QAAQ,EAAM,CAAE,EAAA,mBAAoB,CACzC,KAAM,CAAE,QAAO,WAAU,CACzB,KAAM,UACP,CAAC,CAEF,IAAI,EAAS,EAAM,GAEnB,IAAK,IAAI,EAAI,EAAG,EAAI,EAAM,OAAQ,IAChC,EAAS,EAAS,EAAQ,EAAM,GAAG,CAGrC,OAAO"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Folds an array down to a single value by applying a callback to each pair of
|
|
3
|
+
* elements (reduce without an initial value).
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* fold([1, 2, 3], (a, b) => a + b) // 6
|
|
8
|
+
* fold([1, 2, 3], (a, b) => a > b ? a : b) // 3
|
|
9
|
+
* fold([{ a: 1 }, { a: 2 }], (a, b) => ({ a: a.a + b.a })) // { a: 3 }
|
|
10
|
+
* fold([], (a, b) => a + b) // undefined
|
|
11
|
+
* fold([1], (a, b) => a + b) // 1
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* @param array - The array to fold.
|
|
15
|
+
* @param callback - The function to invoke for each pair of elements.
|
|
16
|
+
* @returns The folded value, or `undefined` if the array is empty.
|
|
17
|
+
*
|
|
18
|
+
* @throws {TypeError} If the first argument is not an array.
|
|
19
|
+
*/
|
|
20
|
+
export declare function fold<T>(array: readonly T[], callback: (a: T, b: T) => T): T | undefined;
|
|
21
|
+
//# sourceMappingURL=fold.d.ts.map
|