@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/dist/date/timeDiff.js
CHANGED
|
@@ -1,27 +1,60 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
//#region src/date/timeDiff.ts
|
|
2
|
+
var e = [
|
|
3
|
+
"year",
|
|
4
|
+
"month",
|
|
5
|
+
"week",
|
|
6
|
+
"day",
|
|
7
|
+
"hour",
|
|
8
|
+
"minute",
|
|
9
|
+
"second"
|
|
10
|
+
], t = 1e3, n = 60 * t, r = 60 * n, i = 24 * r, a = 7 * i, o = 30 * i, s = [
|
|
11
|
+
{
|
|
12
|
+
ms: 365 * i,
|
|
13
|
+
unit: "year"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
ms: o,
|
|
17
|
+
unit: "month"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
ms: a,
|
|
21
|
+
unit: "week"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
ms: i,
|
|
25
|
+
unit: "day"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
ms: r,
|
|
29
|
+
unit: "hour"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
ms: n,
|
|
33
|
+
unit: "minute"
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
ms: t,
|
|
37
|
+
unit: "second"
|
|
38
|
+
}
|
|
10
39
|
];
|
|
11
|
-
function
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
40
|
+
function c(t, n = /* @__PURE__ */ new Date(), r = e) {
|
|
41
|
+
let i = typeof t == "string" ? Date.parse(t) : t.getTime(), a = typeof n == "string" ? Date.parse(n) : n.getTime();
|
|
42
|
+
if (Number.isNaN(i) || Number.isNaN(a)) return;
|
|
43
|
+
let o = s.filter((e) => r.includes(e.unit)), c = Math.abs(i - a), l = o[o.length - 1]?.unit ?? "second";
|
|
44
|
+
if (c <= 0) return {
|
|
45
|
+
unit: l,
|
|
46
|
+
value: 0
|
|
47
|
+
};
|
|
48
|
+
let u = o.find((e) => c >= e.ms);
|
|
49
|
+
return u ? {
|
|
50
|
+
unit: u.unit,
|
|
51
|
+
value: Math.floor(c / u.ms)
|
|
52
|
+
} : {
|
|
53
|
+
unit: l,
|
|
54
|
+
value: 0
|
|
55
|
+
};
|
|
20
56
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
D as timeDiff
|
|
26
|
-
};
|
|
27
|
-
//# sourceMappingURL=timeDiff.js.map
|
|
57
|
+
//#endregion
|
|
58
|
+
export { c as timeDiff };
|
|
59
|
+
|
|
60
|
+
//# sourceMappingURL=timeDiff.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timeDiff.js","sources":["../../src/date/timeDiff.ts"],"sourcesContent":["// #region TimeDiffTypes\nexport type TimeUnit = '
|
|
1
|
+
{"version":3,"file":"timeDiff.js","names":[],"sources":["../../src/date/timeDiff.ts"],"sourcesContent":["// #region TimeDiffTypes\nexport type TimeUnit = 'year' | 'month' | 'week' | 'day' | 'hour' | 'minute' | 'second';\nexport type TimeResult = { unit: TimeUnit; value: number };\n// #endregion TimeDiffTypes\n\nconst ALL_UNITS: TimeUnit[] = ['year', 'month', 'week', 'day', 'hour', 'minute', 'second'];\n\nconst MS_PER_SECOND = 1000;\nconst MS_PER_MINUTE = 60 * MS_PER_SECOND;\nconst MS_PER_HOUR = 60 * MS_PER_MINUTE;\nconst MS_PER_DAY = 24 * MS_PER_HOUR;\nconst MS_PER_WEEK = 7 * MS_PER_DAY;\nconst MS_PER_MONTH = 30 * MS_PER_DAY;\nconst MS_PER_YEAR = 365 * MS_PER_DAY;\n\nconst TIME_UNITS = [\n { ms: MS_PER_YEAR, unit: 'year' as const },\n { ms: MS_PER_MONTH, unit: 'month' as const },\n { ms: MS_PER_WEEK, unit: 'week' as const },\n { ms: MS_PER_DAY, unit: 'day' as const },\n { ms: MS_PER_HOUR, unit: 'hour' as const },\n { ms: MS_PER_MINUTE, unit: 'minute' as const },\n { ms: MS_PER_SECOND, unit: 'second' as const },\n];\n\n/**\n * Calculates the remaining time until a target date.\n *\n * @example\n * ```ts\n * timeDiff(new Date(Date.now() + 1000 * 60 * 60 * 24 * 5)); // { value: 5, unit: 'day' }\n * timeDiff(new Date(Date.now() - 1000 * 60 * 60 * 24 * 3), 'past'); // { value: 3, unit: 'day' }\n * timeDiff(new Date(Date.now() + 1000 * 60 * 60 * 24 * 31)); // { value: 1, unit: 'month' }\n * timeDiff(new Date(Date.now() + 1000 * 60 * 60 * 24 * 365)); // { value: 1, unit: 'year' }\n * ```\n *\n * @param a - The target date (Date object or ISO string).\n * @param b - The target date (Date object or ISO string).\n * @param allowedUnits - (optional) array of units to filter the result. If provided, only these units will be considered.\n *\n * @returns An object containing the remaining time and its unit ('DAY', 'HOUR', or 'MINUTE').\n */\nexport function timeDiff(\n a: Date | string,\n b: Date | string = new Date(),\n allowedUnits: TimeUnit[] = ALL_UNITS,\n): TimeResult | undefined {\n const aDate = typeof a === 'string' ? Date.parse(a) : a.getTime();\n const bDate = typeof b === 'string' ? Date.parse(b) : b.getTime();\n\n if (Number.isNaN(aDate) || Number.isNaN(bDate)) {\n return undefined;\n }\n\n const units = TIME_UNITS.filter((u) => allowedUnits.includes(u.unit));\n const diff = Math.abs(aDate - bDate);\n const smallestUnit = units[units.length - 1]?.unit ?? 'second';\n\n if (diff <= 0) {\n return { unit: smallestUnit, value: 0 };\n }\n\n // Find the largest unit that fits\n const bestUnit = units.find((u) => diff >= u.ms);\n\n if (bestUnit) {\n return { unit: bestUnit.unit, value: Math.floor(diff / bestUnit.ms) };\n }\n\n return { unit: smallestUnit, value: 0 };\n}\n"],"mappings":";AAKA,IAAM,IAAwB;CAAC;CAAQ;CAAS;CAAQ;CAAO;CAAQ;CAAU;CAAS,EAEpF,IAAgB,KAChB,IAAgB,KAAK,GACrB,IAAc,KAAK,GACnB,IAAa,KAAK,GAClB,IAAc,IAAI,GAClB,IAAe,KAAK,GAGpB,IAAa;CACjB;EAAE,IAHgB,MAAM;EAGL,MAAM;EAAiB;CAC1C;EAAE,IAAI;EAAc,MAAM;EAAkB;CAC5C;EAAE,IAAI;EAAa,MAAM;EAAiB;CAC1C;EAAE,IAAI;EAAY,MAAM;EAAgB;CACxC;EAAE,IAAI;EAAa,MAAM;EAAiB;CAC1C;EAAE,IAAI;EAAe,MAAM;EAAmB;CAC9C;EAAE,IAAI;EAAe,MAAM;EAAmB;CAC/C;AAmBD,SAAgB,EACd,GACA,oBAAmB,IAAI,MAAM,EAC7B,IAA2B,GACH;CACxB,IAAM,IAAQ,OAAO,KAAM,WAAW,KAAK,MAAM,EAAE,GAAG,EAAE,SAAS,EAC3D,IAAQ,OAAO,KAAM,WAAW,KAAK,MAAM,EAAE,GAAG,EAAE,SAAS;AAEjE,KAAI,OAAO,MAAM,EAAM,IAAI,OAAO,MAAM,EAAM,CAC5C;CAGF,IAAM,IAAQ,EAAW,QAAQ,MAAM,EAAa,SAAS,EAAE,KAAK,CAAC,EAC/D,IAAO,KAAK,IAAI,IAAQ,EAAM,EAC9B,IAAe,EAAM,EAAM,SAAS,IAAI,QAAQ;AAEtD,KAAI,KAAQ,EACV,QAAO;EAAE,MAAM;EAAc,OAAO;EAAG;CAIzC,IAAM,IAAW,EAAM,MAAM,MAAM,KAAQ,EAAE,GAAG;AAMhD,QAJI,IACK;EAAE,MAAM,EAAS;EAAM,OAAO,KAAK,MAAM,IAAO,EAAS,GAAG;EAAE,GAGhE;EAAE,MAAM;EAAc,OAAO;EAAG"}
|
package/dist/function/assert.cjs
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
//# sourceMappingURL=assert.cjs.map
|
|
1
|
+
function e(e,t=`Assertion failed`,{args:n,bypass:r=!1,type:i=Error}={}){if(e)return;let a=`${t}${n?`\nArguments: ${JSON.stringify(n,null,2)}`:``}`;if(r)console.warn(a);else throw new i(a)}function t(t,n=`Assertion failed`,r={}){e(t.every(Boolean),n,r)}exports.assert=e,exports.assertAll=t;
|
|
2
|
+
//# sourceMappingURL=assert.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assert.cjs","sources":["../../src/function/assert.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"assert.cjs","names":[],"sources":["../../src/function/assert.ts"],"sourcesContent":["import type { Obj } from '../types';\n\ntype AssertOptions = { args?: Obj; bypass?: boolean; type?: ErrorConstructor };\n\n/**\n * Asserts that a condition is true. Throws (or warns, with `bypass`) otherwise.\n *\n * @example\n * ```ts\n * assert(Array.isArray([])); // ok\n * assert(x > 0, 'x must be positive'); // throws if false\n * assert(x > 0, 'x must be positive', { args: { x } });\n * assert(ok, 'not ok', { bypass: true }); // logs warning instead of throwing\n * assertAll([cond1, cond2], 'One failed'); // throws if any is false\n * ```\n *\n * @param condition - The boolean condition to assert.\n * @param [message] - Error message (default: `'Assertion failed'`).\n * @param [options.type] - Error class to throw (default: `Error`).\n * @param [options.args] - Debugging info appended to the message.\n * @param [options.bypass] - Log a warning instead of throwing.\n *\n * @throws {Error} If `condition` is false and `bypass` is not set.\n */\nexport function assert(\n condition: boolean,\n message = 'Assertion failed',\n { args, bypass = false, type = Error }: AssertOptions = {},\n): void {\n if (condition) return;\n\n const errorDetails = args ? `\\nArguments: ${JSON.stringify(args, null, 2)}` : '';\n const fullMessage = `${message}${errorDetails}`;\n\n if (bypass) console.warn(fullMessage);\n else throw new type(fullMessage);\n}\n\n/**\n * Asserts that every condition in the array is true.\n *\n * @example\n * ```ts\n * assertAll([cond1, cond2, cond3], 'One or more conditions failed');\n * ```\n */\nexport function assertAll(conditions: boolean[], message = 'Assertion failed', options: AssertOptions = {}): void {\n assert(conditions.every(Boolean), message, options);\n}\n"],"mappings":"AAwBA,SAAgB,EACd,EACA,EAAU,mBACV,CAAE,OAAM,SAAS,GAAO,OAAO,OAAyB,EAAE,CACpD,CACN,GAAI,EAAW,OAGf,IAAM,EAAc,GAAG,IADF,EAAO,gBAAgB,KAAK,UAAU,EAAM,KAAM,EAAE,GAAK,KAG9E,GAAI,EAAQ,QAAQ,KAAK,EAAY,MAChC,MAAM,IAAI,EAAK,EAAY,CAWlC,SAAgB,EAAU,EAAuB,EAAU,mBAAoB,EAAyB,EAAE,CAAQ,CAChH,EAAO,EAAW,MAAM,QAAQ,CAAE,EAAS,EAAQ"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Obj } from '../types';
|
|
2
|
+
type AssertOptions = {
|
|
3
|
+
args?: Obj;
|
|
4
|
+
bypass?: boolean;
|
|
5
|
+
type?: ErrorConstructor;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Asserts that a condition is true. Throws (or warns, with `bypass`) otherwise.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* assert(Array.isArray([])); // ok
|
|
13
|
+
* assert(x > 0, 'x must be positive'); // throws if false
|
|
14
|
+
* assert(x > 0, 'x must be positive', { args: { x } });
|
|
15
|
+
* assert(ok, 'not ok', { bypass: true }); // logs warning instead of throwing
|
|
16
|
+
* assertAll([cond1, cond2], 'One failed'); // throws if any is false
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @param condition - The boolean condition to assert.
|
|
20
|
+
* @param [message] - Error message (default: `'Assertion failed'`).
|
|
21
|
+
* @param [options.type] - Error class to throw (default: `Error`).
|
|
22
|
+
* @param [options.args] - Debugging info appended to the message.
|
|
23
|
+
* @param [options.bypass] - Log a warning instead of throwing.
|
|
24
|
+
*
|
|
25
|
+
* @throws {Error} If `condition` is false and `bypass` is not set.
|
|
26
|
+
*/
|
|
27
|
+
export declare function assert(condition: boolean, message?: string, { args, bypass, type }?: AssertOptions): void;
|
|
28
|
+
/**
|
|
29
|
+
* Asserts that every condition in the array is true.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* assertAll([cond1, cond2, cond3], 'One or more conditions failed');
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare function assertAll(conditions: boolean[], message?: string, options?: AssertOptions): void;
|
|
37
|
+
export {};
|
|
38
|
+
//# sourceMappingURL=assert.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../src/function/assert.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAEpC,KAAK,aAAa,GAAG;IAAE,IAAI,CAAC,EAAE,GAAG,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAAC,IAAI,CAAC,EAAE,gBAAgB,CAAA;CAAE,CAAC;AAE/E;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,MAAM,CACpB,SAAS,EAAE,OAAO,EAClB,OAAO,SAAqB,EAC5B,EAAE,IAAI,EAAE,MAAc,EAAE,IAAY,EAAE,GAAE,aAAkB,GACzD,IAAI,CAQN;AAED;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,UAAU,EAAE,OAAO,EAAE,EAAE,OAAO,SAAqB,EAAE,OAAO,GAAE,aAAkB,GAAG,IAAI,CAEhH"}
|
package/dist/function/assert.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
function
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
else throw new a(s);
|
|
1
|
+
//#region src/function/assert.ts
|
|
2
|
+
function e(e, t = "Assertion failed", { args: n, bypass: r = !1, type: i = Error } = {}) {
|
|
3
|
+
if (e) return;
|
|
4
|
+
let a = `${t}${n ? `\nArguments: ${JSON.stringify(n, null, 2)}` : ""}`;
|
|
5
|
+
if (r) console.warn(a);
|
|
6
|
+
else throw new i(a);
|
|
8
7
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
//#
|
|
8
|
+
function t(t, n = "Assertion failed", r = {}) {
|
|
9
|
+
e(t.every(Boolean), n, r);
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { e as assert, t as assertAll };
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=assert.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assert.js","sources":["../../src/function/assert.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"assert.js","names":[],"sources":["../../src/function/assert.ts"],"sourcesContent":["import type { Obj } from '../types';\n\ntype AssertOptions = { args?: Obj; bypass?: boolean; type?: ErrorConstructor };\n\n/**\n * Asserts that a condition is true. Throws (or warns, with `bypass`) otherwise.\n *\n * @example\n * ```ts\n * assert(Array.isArray([])); // ok\n * assert(x > 0, 'x must be positive'); // throws if false\n * assert(x > 0, 'x must be positive', { args: { x } });\n * assert(ok, 'not ok', { bypass: true }); // logs warning instead of throwing\n * assertAll([cond1, cond2], 'One failed'); // throws if any is false\n * ```\n *\n * @param condition - The boolean condition to assert.\n * @param [message] - Error message (default: `'Assertion failed'`).\n * @param [options.type] - Error class to throw (default: `Error`).\n * @param [options.args] - Debugging info appended to the message.\n * @param [options.bypass] - Log a warning instead of throwing.\n *\n * @throws {Error} If `condition` is false and `bypass` is not set.\n */\nexport function assert(\n condition: boolean,\n message = 'Assertion failed',\n { args, bypass = false, type = Error }: AssertOptions = {},\n): void {\n if (condition) return;\n\n const errorDetails = args ? `\\nArguments: ${JSON.stringify(args, null, 2)}` : '';\n const fullMessage = `${message}${errorDetails}`;\n\n if (bypass) console.warn(fullMessage);\n else throw new type(fullMessage);\n}\n\n/**\n * Asserts that every condition in the array is true.\n *\n * @example\n * ```ts\n * assertAll([cond1, cond2, cond3], 'One or more conditions failed');\n * ```\n */\nexport function assertAll(conditions: boolean[], message = 'Assertion failed', options: AssertOptions = {}): void {\n assert(conditions.every(Boolean), message, options);\n}\n"],"mappings":";AAwBA,SAAgB,EACd,GACA,IAAU,oBACV,EAAE,SAAM,YAAS,IAAO,UAAO,UAAyB,EAAE,EACpD;AACN,KAAI,EAAW;CAGf,IAAM,IAAc,GAAG,IADF,IAAO,gBAAgB,KAAK,UAAU,GAAM,MAAM,EAAE,KAAK;AAG9E,KAAI,EAAQ,SAAQ,KAAK,EAAY;KAChC,OAAM,IAAI,EAAK,EAAY;;AAWlC,SAAgB,EAAU,GAAuB,IAAU,oBAAoB,IAAyB,EAAE,EAAQ;AAChH,GAAO,EAAW,MAAM,QAAQ,EAAE,GAAS,EAAQ"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=assertParams.cjs.map
|
|
1
|
+
const e=require(`./assert.cjs`);function t(t,n,r,i={}){e.assert(!!t,`Missing parameters object`,i);let a=n.filter(e=>t[e]===void 0||t[e]===null);if(a.length>0){let t=r?` in "${r}"`:``,n=a.map(e=>`"${String(e)}"`).join(`, `);e.assert(!1,`Missing required parameter${a.length>1?`s`:``}: ${n}${t}`,i)}}exports.assertParams=t;
|
|
2
|
+
//# sourceMappingURL=assertParams.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assertParams.cjs","sources":["../../src/function/assertParams.ts"],"sourcesContent":["import { assert } from './assert';\n\n/**\n * Asserts that the specified keys are present in the params object
|
|
1
|
+
{"version":3,"file":"assertParams.cjs","names":[],"sources":["../../src/function/assertParams.ts"],"sourcesContent":["import { assert } from './assert';\n\n/**\n * Asserts that the specified keys are present and non-null in the params object.\n *\n * @example\n * ```ts\n * const params = { id: '123', name: undefined };\n * assertParams(params, ['id']); // Does nothing\n * assertParams(params, ['id', 'name'], 'UserUpdate'); // Throws: Missing required parameter: \"name\" in \"UserUpdate\"\n * ```\n *\n * @param params - The object containing the parameters to check.\n * @param keys - An array of keys that must be present (not null or undefined) in the params object.\n * @param [name] - An optional name for the context of the assertion (e.g., function name).\n * @param [options] - Assertion options.\n * @param [options.type] - The error class to throw (default: `Error`).\n * @param [options.bypass] - If `true`, logs a warning instead of throwing an error.\n *\n * @throws {Error} If any of the required keys are missing.\n */\nexport function assertParams<T extends object, K extends keyof T>(\n params: T,\n keys: K[],\n name?: string,\n options: { bypass?: boolean; type?: ErrorConstructor } = {},\n): asserts params is T & Required<Pick<T, K>> {\n assert(!!params, 'Missing parameters object', options);\n\n const missing = keys.filter((key) => params[key] === undefined || params[key] === null);\n\n if (missing.length > 0) {\n const context = name ? ` in \"${name}\"` : '';\n const keysStr = missing.map((key) => `\"${String(key)}\"`).join(', ');\n const message = `Missing required parameter${missing.length > 1 ? 's' : ''}: ${keysStr}${context}`;\n\n assert(false, message, options);\n }\n}\n"],"mappings":"gCAqBA,SAAgB,EACd,EACA,EACA,EACA,EAAyD,EAAE,CACf,CAC5C,EAAA,OAAO,CAAC,CAAC,EAAQ,4BAA6B,EAAQ,CAEtD,IAAM,EAAU,EAAK,OAAQ,GAAQ,EAAO,KAAS,IAAA,IAAa,EAAO,KAAS,KAAK,CAEvF,GAAI,EAAQ,OAAS,EAAG,CACtB,IAAM,EAAU,EAAO,QAAQ,EAAK,GAAK,GACnC,EAAU,EAAQ,IAAK,GAAQ,IAAI,OAAO,EAAI,CAAC,GAAG,CAAC,KAAK,KAAK,CAGnE,EAAA,OAAO,GAFS,6BAA6B,EAAQ,OAAS,EAAI,IAAM,GAAG,IAAI,IAAU,IAElE,EAAQ"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Asserts that the specified keys are present and non-null in the params object.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* const params = { id: '123', name: undefined };
|
|
7
|
+
* assertParams(params, ['id']); // Does nothing
|
|
8
|
+
* assertParams(params, ['id', 'name'], 'UserUpdate'); // Throws: Missing required parameter: "name" in "UserUpdate"
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* @param params - The object containing the parameters to check.
|
|
12
|
+
* @param keys - An array of keys that must be present (not null or undefined) in the params object.
|
|
13
|
+
* @param [name] - An optional name for the context of the assertion (e.g., function name).
|
|
14
|
+
* @param [options] - Assertion options.
|
|
15
|
+
* @param [options.type] - The error class to throw (default: `Error`).
|
|
16
|
+
* @param [options.bypass] - If `true`, logs a warning instead of throwing an error.
|
|
17
|
+
*
|
|
18
|
+
* @throws {Error} If any of the required keys are missing.
|
|
19
|
+
*/
|
|
20
|
+
export declare function assertParams<T extends object, K extends keyof T>(params: T, keys: K[], name?: string, options?: {
|
|
21
|
+
bypass?: boolean;
|
|
22
|
+
type?: ErrorConstructor;
|
|
23
|
+
}): asserts params is T & Required<Pick<T, K>>;
|
|
24
|
+
//# sourceMappingURL=assertParams.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assertParams.d.ts","sourceRoot":"","sources":["../../src/function/assertParams.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,CAAC,EAC9D,MAAM,EAAE,CAAC,EACT,IAAI,EAAE,CAAC,EAAE,EACT,IAAI,CAAC,EAAE,MAAM,EACb,OAAO,GAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAC;IAAC,IAAI,CAAC,EAAE,gBAAgB,CAAA;CAAO,GAC1D,OAAO,CAAC,MAAM,IAAI,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAY5C"}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { assert as
|
|
2
|
-
function
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { assert as e } from "./assert.js";
|
|
2
|
+
//#region src/function/assertParams.ts
|
|
3
|
+
function t(t, n, r, i = {}) {
|
|
4
|
+
e(!!t, "Missing parameters object", i);
|
|
5
|
+
let a = n.filter((e) => t[e] === void 0 || t[e] === null);
|
|
6
|
+
if (a.length > 0) {
|
|
7
|
+
let t = r ? ` in "${r}"` : "", n = a.map((e) => `"${String(e)}"`).join(", ");
|
|
8
|
+
e(!1, `Missing required parameter${a.length > 1 ? "s" : ""}: ${n}${t}`, i);
|
|
9
|
+
}
|
|
9
10
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
//# sourceMappingURL=assertParams.js.map
|
|
11
|
+
//#endregion
|
|
12
|
+
export { t as assertParams };
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=assertParams.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assertParams.js","sources":["../../src/function/assertParams.ts"],"sourcesContent":["import { assert } from './assert';\n\n/**\n * Asserts that the specified keys are present in the params object
|
|
1
|
+
{"version":3,"file":"assertParams.js","names":[],"sources":["../../src/function/assertParams.ts"],"sourcesContent":["import { assert } from './assert';\n\n/**\n * Asserts that the specified keys are present and non-null in the params object.\n *\n * @example\n * ```ts\n * const params = { id: '123', name: undefined };\n * assertParams(params, ['id']); // Does nothing\n * assertParams(params, ['id', 'name'], 'UserUpdate'); // Throws: Missing required parameter: \"name\" in \"UserUpdate\"\n * ```\n *\n * @param params - The object containing the parameters to check.\n * @param keys - An array of keys that must be present (not null or undefined) in the params object.\n * @param [name] - An optional name for the context of the assertion (e.g., function name).\n * @param [options] - Assertion options.\n * @param [options.type] - The error class to throw (default: `Error`).\n * @param [options.bypass] - If `true`, logs a warning instead of throwing an error.\n *\n * @throws {Error} If any of the required keys are missing.\n */\nexport function assertParams<T extends object, K extends keyof T>(\n params: T,\n keys: K[],\n name?: string,\n options: { bypass?: boolean; type?: ErrorConstructor } = {},\n): asserts params is T & Required<Pick<T, K>> {\n assert(!!params, 'Missing parameters object', options);\n\n const missing = keys.filter((key) => params[key] === undefined || params[key] === null);\n\n if (missing.length > 0) {\n const context = name ? ` in \"${name}\"` : '';\n const keysStr = missing.map((key) => `\"${String(key)}\"`).join(', ');\n const message = `Missing required parameter${missing.length > 1 ? 's' : ''}: ${keysStr}${context}`;\n\n assert(false, message, options);\n }\n}\n"],"mappings":";;AAqBA,SAAgB,EACd,GACA,GACA,GACA,IAAyD,EAAE,EACf;AAC5C,GAAO,CAAC,CAAC,GAAQ,6BAA6B,EAAQ;CAEtD,IAAM,IAAU,EAAK,QAAQ,MAAQ,EAAO,OAAS,KAAA,KAAa,EAAO,OAAS,KAAK;AAEvF,KAAI,EAAQ,SAAS,GAAG;EACtB,IAAM,IAAU,IAAO,QAAQ,EAAK,KAAK,IACnC,IAAU,EAAQ,KAAK,MAAQ,IAAI,OAAO,EAAI,CAAC,GAAG,CAAC,KAAK,KAAK;AAGnE,IAAO,IAFS,6BAA6B,EAAQ,SAAS,IAAI,MAAM,GAAG,IAAI,IAAU,KAElE,EAAQ"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=compare.cjs.map
|
|
1
|
+
var e=(e,t)=>{if(e===t)return 0;if(e===void 0)return 1;if(t===void 0)return-1;if(e===null)return t===null?0:-1;if(t===null)return 1;if(typeof e==`string`&&typeof t==`string`)return e.localeCompare(t);if(typeof e==`number`&&typeof t==`number`)return e===t?0:e>t?1:-1;if(e instanceof Date&&t instanceof Date){let n=e.getTime(),r=t.getTime();return n===r?0:n>r?1:-1}if(typeof e==`object`&&typeof t==`object`){let n=JSON.stringify(e),r=JSON.stringify(t);return n.localeCompare(r)}return String(e).localeCompare(String(t))};exports.compare=e;
|
|
2
|
+
//# sourceMappingURL=compare.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compare.cjs","sources":["../../src/function/compare.ts"],"sourcesContent":["/**\n * Compares two values and returns:\n * - 0 if they are equal\n * - 1 if the first value is greater\n * - -1 if the second value is greater\n *\n * @example\n * ```ts\n * compare('a', 'b'); // -1\n * compare(1, 2); // -1\n * compare(new Date('2023-01-01'), new Date('2023-01-02')); // -1\n * compare('a', 'a'); // 0\n * compare(1, 1); // 0\n * compare(new Date('2023-01-01'), new Date('2023-01-01')); // 0\n * ```\n *\n * @param a - The first value to compare.\n * @param b - The second value to compare.\n *\n * @returns 0 if equal, 1 if the first value is greater, -1 if the second value is greater.\n */\
|
|
1
|
+
{"version":3,"file":"compare.cjs","names":[],"sources":["../../src/function/compare.ts"],"sourcesContent":["/**\n * Compares two values and returns:\n * - 0 if they are equal\n * - 1 if the first value is greater\n * - -1 if the second value is greater\n *\n * @example\n * ```ts\n * compare('a', 'b'); // -1\n * compare(1, 2); // -1\n * compare(new Date('2023-01-01'), new Date('2023-01-02')); // -1\n * compare('a', 'a'); // 0\n * compare(1, 1); // 0\n * compare(new Date('2023-01-01'), new Date('2023-01-01')); // 0\n * ```\n *\n * @param a - The first value to compare.\n * @param b - The second value to compare.\n *\n * @returns 0 if equal, 1 if the first value is greater, -1 if the second value is greater.\n */\nexport const compare = (a: unknown, b: unknown): number => {\n if (a === b) return 0;\n\n if (a === undefined) return 1;\n\n if (b === undefined) return -1;\n\n if (a === null) return b === null ? 0 : -1;\n\n if (b === null) return 1;\n\n if (typeof a === 'string' && typeof b === 'string') {\n return a.localeCompare(b);\n }\n\n if (typeof a === 'number' && typeof b === 'number') {\n return a === b ? 0 : a > b ? 1 : -1;\n }\n\n if (a instanceof Date && b instanceof Date) {\n const at = a.getTime();\n const bt = b.getTime();\n\n return at === bt ? 0 : at > bt ? 1 : -1;\n }\n\n if (typeof a === 'object' && typeof b === 'object') {\n const aString = JSON.stringify(a);\n const bString = JSON.stringify(b);\n\n return aString.localeCompare(bString);\n }\n\n return String(a).localeCompare(String(b));\n};\n"],"mappings":"AAqBA,IAAa,GAAW,EAAY,IAAuB,CACzD,GAAI,IAAM,EAAG,MAAO,GAEpB,GAAI,IAAM,IAAA,GAAW,MAAO,GAE5B,GAAI,IAAM,IAAA,GAAW,MAAO,GAE5B,GAAI,IAAM,KAAM,OAAO,IAAM,KAAO,EAAI,GAExC,GAAI,IAAM,KAAM,MAAO,GAEvB,GAAI,OAAO,GAAM,UAAY,OAAO,GAAM,SACxC,OAAO,EAAE,cAAc,EAAE,CAG3B,GAAI,OAAO,GAAM,UAAY,OAAO,GAAM,SACxC,OAAO,IAAM,EAAI,EAAI,EAAI,EAAI,EAAI,GAGnC,GAAI,aAAa,MAAQ,aAAa,KAAM,CAC1C,IAAM,EAAK,EAAE,SAAS,CAChB,EAAK,EAAE,SAAS,CAEtB,OAAO,IAAO,EAAK,EAAI,EAAK,EAAK,EAAI,GAGvC,GAAI,OAAO,GAAM,UAAY,OAAO,GAAM,SAAU,CAClD,IAAM,EAAU,KAAK,UAAU,EAAE,CAC3B,EAAU,KAAK,UAAU,EAAE,CAEjC,OAAO,EAAQ,cAAc,EAAQ,CAGvC,OAAO,OAAO,EAAE,CAAC,cAAc,OAAO,EAAE,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compares two values and returns:
|
|
3
|
+
* - 0 if they are equal
|
|
4
|
+
* - 1 if the first value is greater
|
|
5
|
+
* - -1 if the second value is greater
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* compare('a', 'b'); // -1
|
|
10
|
+
* compare(1, 2); // -1
|
|
11
|
+
* compare(new Date('2023-01-01'), new Date('2023-01-02')); // -1
|
|
12
|
+
* compare('a', 'a'); // 0
|
|
13
|
+
* compare(1, 1); // 0
|
|
14
|
+
* compare(new Date('2023-01-01'), new Date('2023-01-01')); // 0
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @param a - The first value to compare.
|
|
18
|
+
* @param b - The second value to compare.
|
|
19
|
+
*
|
|
20
|
+
* @returns 0 if equal, 1 if the first value is greater, -1 if the second value is greater.
|
|
21
|
+
*/
|
|
22
|
+
export declare const compare: (a: unknown, b: unknown) => number;
|
|
23
|
+
//# sourceMappingURL=compare.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compare.d.ts","sourceRoot":"","sources":["../../src/function/compare.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,OAAO,GAAI,GAAG,OAAO,EAAE,GAAG,OAAO,KAAG,MAkChD,CAAC"}
|
package/dist/function/compare.js
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
//#region src/function/compare.ts
|
|
2
|
+
var e = (e, t) => {
|
|
3
|
+
if (e === t) return 0;
|
|
4
|
+
if (e === void 0) return 1;
|
|
5
|
+
if (t === void 0) return -1;
|
|
6
|
+
if (e === null) return t === null ? 0 : -1;
|
|
7
|
+
if (t === null) return 1;
|
|
8
|
+
if (typeof e == "string" && typeof t == "string") return e.localeCompare(t);
|
|
9
|
+
if (typeof e == "number" && typeof t == "number") return e === t ? 0 : e > t ? 1 : -1;
|
|
10
|
+
if (e instanceof Date && t instanceof Date) {
|
|
11
|
+
let n = e.getTime(), r = t.getTime();
|
|
12
|
+
return n === r ? 0 : n > r ? 1 : -1;
|
|
13
|
+
}
|
|
14
|
+
if (typeof e == "object" && typeof t == "object") {
|
|
15
|
+
let n = JSON.stringify(e), r = JSON.stringify(t);
|
|
16
|
+
return n.localeCompare(r);
|
|
17
|
+
}
|
|
18
|
+
return String(e).localeCompare(String(t));
|
|
18
19
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
//# sourceMappingURL=compare.js.map
|
|
20
|
+
//#endregion
|
|
21
|
+
export { e as compare };
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=compare.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compare.js","sources":["../../src/function/compare.ts"],"sourcesContent":["/**\n * Compares two values and returns:\n * - 0 if they are equal\n * - 1 if the first value is greater\n * - -1 if the second value is greater\n *\n * @example\n * ```ts\n * compare('a', 'b'); // -1\n * compare(1, 2); // -1\n * compare(new Date('2023-01-01'), new Date('2023-01-02')); // -1\n * compare('a', 'a'); // 0\n * compare(1, 1); // 0\n * compare(new Date('2023-01-01'), new Date('2023-01-01')); // 0\n * ```\n *\n * @param a - The first value to compare.\n * @param b - The second value to compare.\n *\n * @returns 0 if equal, 1 if the first value is greater, -1 if the second value is greater.\n */\
|
|
1
|
+
{"version":3,"file":"compare.js","names":[],"sources":["../../src/function/compare.ts"],"sourcesContent":["/**\n * Compares two values and returns:\n * - 0 if they are equal\n * - 1 if the first value is greater\n * - -1 if the second value is greater\n *\n * @example\n * ```ts\n * compare('a', 'b'); // -1\n * compare(1, 2); // -1\n * compare(new Date('2023-01-01'), new Date('2023-01-02')); // -1\n * compare('a', 'a'); // 0\n * compare(1, 1); // 0\n * compare(new Date('2023-01-01'), new Date('2023-01-01')); // 0\n * ```\n *\n * @param a - The first value to compare.\n * @param b - The second value to compare.\n *\n * @returns 0 if equal, 1 if the first value is greater, -1 if the second value is greater.\n */\nexport const compare = (a: unknown, b: unknown): number => {\n if (a === b) return 0;\n\n if (a === undefined) return 1;\n\n if (b === undefined) return -1;\n\n if (a === null) return b === null ? 0 : -1;\n\n if (b === null) return 1;\n\n if (typeof a === 'string' && typeof b === 'string') {\n return a.localeCompare(b);\n }\n\n if (typeof a === 'number' && typeof b === 'number') {\n return a === b ? 0 : a > b ? 1 : -1;\n }\n\n if (a instanceof Date && b instanceof Date) {\n const at = a.getTime();\n const bt = b.getTime();\n\n return at === bt ? 0 : at > bt ? 1 : -1;\n }\n\n if (typeof a === 'object' && typeof b === 'object') {\n const aString = JSON.stringify(a);\n const bString = JSON.stringify(b);\n\n return aString.localeCompare(bString);\n }\n\n return String(a).localeCompare(String(b));\n};\n"],"mappings":";AAqBA,IAAa,KAAW,GAAY,MAAuB;AACzD,KAAI,MAAM,EAAG,QAAO;AAEpB,KAAI,MAAM,KAAA,EAAW,QAAO;AAE5B,KAAI,MAAM,KAAA,EAAW,QAAO;AAE5B,KAAI,MAAM,KAAM,QAAO,MAAM,OAAO,IAAI;AAExC,KAAI,MAAM,KAAM,QAAO;AAEvB,KAAI,OAAO,KAAM,YAAY,OAAO,KAAM,SACxC,QAAO,EAAE,cAAc,EAAE;AAG3B,KAAI,OAAO,KAAM,YAAY,OAAO,KAAM,SACxC,QAAO,MAAM,IAAI,IAAI,IAAI,IAAI,IAAI;AAGnC,KAAI,aAAa,QAAQ,aAAa,MAAM;EAC1C,IAAM,IAAK,EAAE,SAAS,EAChB,IAAK,EAAE,SAAS;AAEtB,SAAO,MAAO,IAAK,IAAI,IAAK,IAAK,IAAI;;AAGvC,KAAI,OAAO,KAAM,YAAY,OAAO,KAAM,UAAU;EAClD,IAAM,IAAU,KAAK,UAAU,EAAE,EAC3B,IAAU,KAAK,UAAU,EAAE;AAEjC,SAAO,EAAQ,cAAc,EAAQ;;AAGvC,QAAO,OAAO,EAAE,CAAC,cAAc,OAAO,EAAE,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=compareBy.cjs.map
|
|
1
|
+
const e=require(`./compare.cjs`);var t=t=>{let n=Object.entries(t);return(t,r)=>{for(let[i,a]of n){let n=t[i],o=r[i],s=a===`desc`?-1:1,c=e.compare(n,o);if(c!==0)return c*s}return 0}};exports.compareBy=t;
|
|
2
|
+
//# sourceMappingURL=compareBy.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compareBy.cjs","sources":["../../src/function/compareBy.ts"],"sourcesContent":["import { compare } from './compare';\n\n/**\n * Compares two objects based on multiple selectors.\n * The comparison is done in the order of the selectors provided.\n * Each selector can be 'asc' for ascending or 'desc' for descending order.\n *\n * @example\n * ```ts\n * const compareByNameAndAge = compareBy<{ name: string; age: number }>({\n * name: 'asc',\n * age: 'desc',\n * });\n *\n * const a = { name: 'Alice', age: 30 };\n * const b = { name: 'Bob', age: 25 };\n *\n * console.log(compareByNameAndAge(a, b)); // -1 (Alice < Bob)\n * ```\n *\n * @param selectors - An object where keys are properties to compare and values are 'asc' or 'desc'.\n *\n * @returns A comparison function that can be used with array sorting methods.\n */\nexport const compareBy = <T>(selectors: Partial<Record<keyof T, 'asc' | 'desc'>>) => {\n const entries = Object.entries(selectors) as [keyof T, 'asc' | 'desc'][];\n\n return (a: T, b: T) => {\n for (const [key, direction] of entries) {\n const v1 = a[key];\n const v2 = b[key];\n const dir = direction === 'desc' ? -1 : 1;\n\n const cmp = compare(v1, v2);\n if (cmp !== 0) return cmp * dir;\n }\n\n return 0;\n };\n};\n"],"
|
|
1
|
+
{"version":3,"file":"compareBy.cjs","names":[],"sources":["../../src/function/compareBy.ts"],"sourcesContent":["import { compare } from './compare';\n\n/**\n * Compares two objects based on multiple selectors.\n * The comparison is done in the order of the selectors provided.\n * Each selector can be 'asc' for ascending or 'desc' for descending order.\n *\n * @example\n * ```ts\n * const compareByNameAndAge = compareBy<{ name: string; age: number }>({\n * name: 'asc',\n * age: 'desc',\n * });\n *\n * const a = { name: 'Alice', age: 30 };\n * const b = { name: 'Bob', age: 25 };\n *\n * console.log(compareByNameAndAge(a, b)); // -1 (Alice < Bob)\n * ```\n *\n * @param selectors - An object where keys are properties to compare and values are 'asc' or 'desc'.\n *\n * @returns A comparison function that can be used with array sorting methods.\n */\nexport const compareBy = <T>(selectors: Partial<Record<keyof T, 'asc' | 'desc'>>) => {\n const entries = Object.entries(selectors) as [keyof T, 'asc' | 'desc'][];\n\n return (a: T, b: T) => {\n for (const [key, direction] of entries) {\n const v1 = a[key];\n const v2 = b[key];\n const dir = direction === 'desc' ? -1 : 1;\n\n const cmp = compare(v1, v2);\n\n if (cmp !== 0) return cmp * dir;\n }\n\n return 0;\n };\n};\n"],"mappings":"iCAwBA,IAAa,EAAgB,GAAwD,CACnF,IAAM,EAAU,OAAO,QAAQ,EAAU,CAEzC,OAAQ,EAAM,IAAS,CACrB,IAAK,GAAM,CAAC,EAAK,KAAc,EAAS,CACtC,IAAM,EAAK,EAAE,GACP,EAAK,EAAE,GACP,EAAM,IAAc,OAAS,GAAK,EAElC,EAAM,EAAA,QAAQ,EAAI,EAAG,CAE3B,GAAI,IAAQ,EAAG,OAAO,EAAM,EAG9B,MAAO"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compares two objects based on multiple selectors.
|
|
3
|
+
* The comparison is done in the order of the selectors provided.
|
|
4
|
+
* Each selector can be 'asc' for ascending or 'desc' for descending order.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* const compareByNameAndAge = compareBy<{ name: string; age: number }>({
|
|
9
|
+
* name: 'asc',
|
|
10
|
+
* age: 'desc',
|
|
11
|
+
* });
|
|
12
|
+
*
|
|
13
|
+
* const a = { name: 'Alice', age: 30 };
|
|
14
|
+
* const b = { name: 'Bob', age: 25 };
|
|
15
|
+
*
|
|
16
|
+
* console.log(compareByNameAndAge(a, b)); // -1 (Alice < Bob)
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @param selectors - An object where keys are properties to compare and values are 'asc' or 'desc'.
|
|
20
|
+
*
|
|
21
|
+
* @returns A comparison function that can be used with array sorting methods.
|
|
22
|
+
*/
|
|
23
|
+
export declare const compareBy: <T>(selectors: Partial<Record<keyof T, "asc" | "desc">>) => (a: T, b: T) => number;
|
|
24
|
+
//# sourceMappingURL=compareBy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compareBy.d.ts","sourceRoot":"","sources":["../../src/function/compareBy.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,SAAS,GAAI,CAAC,EAAE,WAAW,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC,CAAC,MAGtE,GAAG,CAAC,EAAE,GAAG,CAAC,WAanB,CAAC"}
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import { compare as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { compare as e } from "./compare.js";
|
|
2
|
+
//#region src/function/compareBy.ts
|
|
3
|
+
var t = (t) => {
|
|
4
|
+
let n = Object.entries(t);
|
|
5
|
+
return (t, r) => {
|
|
6
|
+
for (let [i, a] of n) {
|
|
7
|
+
let n = t[i], o = r[i], s = a === "desc" ? -1 : 1, c = e(n, o);
|
|
8
|
+
if (c !== 0) return c * s;
|
|
9
|
+
}
|
|
10
|
+
return 0;
|
|
11
|
+
};
|
|
11
12
|
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
//# sourceMappingURL=compareBy.js.map
|
|
13
|
+
//#endregion
|
|
14
|
+
export { t as compareBy };
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=compareBy.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compareBy.js","sources":["../../src/function/compareBy.ts"],"sourcesContent":["import { compare } from './compare';\n\n/**\n * Compares two objects based on multiple selectors.\n * The comparison is done in the order of the selectors provided.\n * Each selector can be 'asc' for ascending or 'desc' for descending order.\n *\n * @example\n * ```ts\n * const compareByNameAndAge = compareBy<{ name: string; age: number }>({\n * name: 'asc',\n * age: 'desc',\n * });\n *\n * const a = { name: 'Alice', age: 30 };\n * const b = { name: 'Bob', age: 25 };\n *\n * console.log(compareByNameAndAge(a, b)); // -1 (Alice < Bob)\n * ```\n *\n * @param selectors - An object where keys are properties to compare and values are 'asc' or 'desc'.\n *\n * @returns A comparison function that can be used with array sorting methods.\n */\nexport const compareBy = <T>(selectors: Partial<Record<keyof T, 'asc' | 'desc'>>) => {\n const entries = Object.entries(selectors) as [keyof T, 'asc' | 'desc'][];\n\n return (a: T, b: T) => {\n for (const [key, direction] of entries) {\n const v1 = a[key];\n const v2 = b[key];\n const dir = direction === 'desc' ? -1 : 1;\n\n const cmp = compare(v1, v2);\n if (cmp !== 0) return cmp * dir;\n }\n\n return 0;\n };\n};\n"],"
|
|
1
|
+
{"version":3,"file":"compareBy.js","names":[],"sources":["../../src/function/compareBy.ts"],"sourcesContent":["import { compare } from './compare';\n\n/**\n * Compares two objects based on multiple selectors.\n * The comparison is done in the order of the selectors provided.\n * Each selector can be 'asc' for ascending or 'desc' for descending order.\n *\n * @example\n * ```ts\n * const compareByNameAndAge = compareBy<{ name: string; age: number }>({\n * name: 'asc',\n * age: 'desc',\n * });\n *\n * const a = { name: 'Alice', age: 30 };\n * const b = { name: 'Bob', age: 25 };\n *\n * console.log(compareByNameAndAge(a, b)); // -1 (Alice < Bob)\n * ```\n *\n * @param selectors - An object where keys are properties to compare and values are 'asc' or 'desc'.\n *\n * @returns A comparison function that can be used with array sorting methods.\n */\nexport const compareBy = <T>(selectors: Partial<Record<keyof T, 'asc' | 'desc'>>) => {\n const entries = Object.entries(selectors) as [keyof T, 'asc' | 'desc'][];\n\n return (a: T, b: T) => {\n for (const [key, direction] of entries) {\n const v1 = a[key];\n const v2 = b[key];\n const dir = direction === 'desc' ? -1 : 1;\n\n const cmp = compare(v1, v2);\n\n if (cmp !== 0) return cmp * dir;\n }\n\n return 0;\n };\n};\n"],"mappings":";;AAwBA,IAAa,KAAgB,MAAwD;CACnF,IAAM,IAAU,OAAO,QAAQ,EAAU;AAEzC,SAAQ,GAAM,MAAS;AACrB,OAAK,IAAM,CAAC,GAAK,MAAc,GAAS;GACtC,IAAM,IAAK,EAAE,IACP,IAAK,EAAE,IACP,IAAM,MAAc,SAAS,KAAK,GAElC,IAAM,EAAQ,GAAI,EAAG;AAE3B,OAAI,MAAQ,EAAG,QAAO,IAAM;;AAG9B,SAAO"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=compose.cjs.map
|
|
1
|
+
const e=require(`./assert.cjs`);function t(...t){e.assert(t.length>0,`compose requires at least one function`,{args:{fns:t}});let n=t[t.length-1],r=t.slice(0,-1);return((...e)=>r.reduceRight((e,t)=>t(e),n(...e)))}exports.compose=t;
|
|
2
|
+
//# sourceMappingURL=compose.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compose.cjs","sources":["../../src/function/compose.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"compose.cjs","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":"gCAuBA,SAAgB,EAAwB,GAAG,EAA4D,CACrG,EAAA,OAAO,EAAI,OAAS,EAAG,yCAA0C,CAAE,KAAM,CAAE,MAAK,CAAE,CAAC,CAEnF,IAAM,EAAS,EAAI,EAAI,OAAS,GAC1B,EAAU,EAAI,MAAM,EAAG,GAAG,CAEhC,QAAS,GAAG,IAA4B,EAAQ,aAAa,EAAM,IAAO,EAAG,EAAK,CAAE,EAAO,GAAG,EAAK,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Fn } from '../types';
|
|
2
|
+
type LastParameters<T> = T extends [...any, infer Last extends Fn] ? Parameters<Last> : never;
|
|
3
|
+
type FirstReturnType<F> = F extends [infer First extends Fn, ...any] ? ReturnType<First> : never;
|
|
4
|
+
/**
|
|
5
|
+
* Composes multiple functions into a single function. It starts from the rightmost function and proceeds to the left.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* const add = (x) => x + 2;
|
|
10
|
+
* const multiply = (x) => x * 3;
|
|
11
|
+
* const subtract = (x) => x - 4;
|
|
12
|
+
* const composedFn = compose(subtract, multiply, add);
|
|
13
|
+
* composedFn(5); // ((5 + 2) * 3) - 4 = 17
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @param fns - List of the functions to be composed.
|
|
17
|
+
*
|
|
18
|
+
* @returns A new function that is the composition of the input functions.
|
|
19
|
+
*/
|
|
20
|
+
export declare function compose<T extends Fn[]>(...fns: T): (...args: LastParameters<T>) => FirstReturnType<T>;
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=compose.d.ts.map
|