@vielzeug/toolkit 1.1.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +419 -0
- package/dist/array/chunk.cjs +2 -2
- package/dist/array/chunk.cjs.map +1 -1
- package/dist/array/chunk.d.ts +29 -0
- package/dist/array/chunk.d.ts.map +1 -0
- package/dist/array/chunk.js +22 -24
- package/dist/array/chunk.js.map +1 -1
- package/dist/array/contains.cjs +2 -2
- package/dist/array/contains.cjs.map +1 -1
- package/dist/array/contains.d.ts +19 -0
- package/dist/array/contains.d.ts.map +1 -0
- package/dist/array/contains.js +12 -9
- package/dist/array/contains.js.map +1 -1
- package/dist/array/fold.cjs +2 -0
- package/dist/array/fold.cjs.map +1 -0
- package/dist/array/fold.d.ts +21 -0
- package/dist/array/fold.d.ts.map +1 -0
- package/dist/array/fold.js +19 -0
- package/dist/array/fold.js.map +1 -0
- package/dist/array/group.cjs +2 -2
- package/dist/array/group.cjs.map +1 -1
- package/dist/array/group.d.ts +19 -0
- package/dist/array/group.d.ts.map +1 -0
- package/dist/array/group.js +18 -15
- package/dist/array/group.js.map +1 -1
- package/dist/array/index.d.ts +16 -0
- package/dist/array/index.d.ts.map +1 -0
- package/dist/array/keyBy.cjs +2 -0
- package/dist/array/keyBy.cjs.map +1 -0
- package/dist/array/keyBy.d.ts +20 -0
- package/dist/array/keyBy.d.ts.map +1 -0
- package/dist/array/keyBy.js +19 -0
- package/dist/array/keyBy.js.map +1 -0
- package/dist/array/list.cjs +2 -2
- package/dist/array/list.cjs.map +1 -1
- package/dist/array/list.d.ts +58 -0
- package/dist/array/list.d.ts.map +1 -0
- package/dist/array/list.js +103 -106
- package/dist/array/list.js.map +1 -1
- package/dist/array/pick.cjs +2 -2
- package/dist/array/pick.cjs.map +1 -1
- package/dist/array/pick.d.ts +19 -0
- package/dist/array/pick.d.ts.map +1 -0
- package/dist/array/pick.js +15 -14
- package/dist/array/pick.js.map +1 -1
- package/dist/array/remoteList.cjs +2 -2
- package/dist/array/remoteList.cjs.map +1 -1
- package/dist/array/remoteList.d.ts +64 -0
- package/dist/array/remoteList.d.ts.map +1 -0
- package/dist/array/remoteList.js +121 -122
- package/dist/array/remoteList.js.map +1 -1
- package/dist/array/replace.cjs +2 -0
- package/dist/array/replace.cjs.map +1 -0
- package/dist/array/replace.d.ts +20 -0
- package/dist/array/replace.d.ts.map +1 -0
- package/dist/array/replace.js +19 -0
- package/dist/array/replace.js.map +1 -0
- package/dist/array/rotate.cjs +2 -0
- package/dist/array/rotate.cjs.map +1 -0
- package/dist/array/rotate.d.ts +22 -0
- package/dist/array/rotate.d.ts.map +1 -0
- package/dist/array/rotate.js +19 -0
- package/dist/array/rotate.js.map +1 -0
- package/dist/array/search.cjs +2 -2
- package/dist/array/search.cjs.map +1 -1
- package/dist/array/search.d.ts +19 -0
- package/dist/array/search.d.ts.map +1 -0
- package/dist/array/search.js +23 -13
- package/dist/array/search.js.map +1 -1
- package/dist/array/select.cjs +2 -2
- package/dist/array/select.cjs.map +1 -1
- package/dist/array/select.d.ts +21 -0
- package/dist/array/select.d.ts.map +1 -0
- package/dist/array/select.js +16 -15
- package/dist/array/select.js.map +1 -1
- package/dist/array/sort.cjs +2 -2
- package/dist/array/sort.cjs.map +1 -1
- package/dist/array/sort.d.ts +26 -0
- package/dist/array/sort.d.ts.map +1 -0
- package/dist/array/sort.js +18 -12
- package/dist/array/sort.js.map +1 -1
- package/dist/array/toggle.cjs +2 -0
- package/dist/array/toggle.cjs.map +1 -0
- package/dist/array/toggle.d.ts +29 -0
- package/dist/array/toggle.d.ts.map +1 -0
- package/dist/array/toggle.js +9 -0
- package/dist/array/toggle.js.map +1 -0
- package/dist/array/uniq.cjs +2 -2
- package/dist/array/uniq.cjs.map +1 -1
- package/dist/array/uniq.d.ts +21 -0
- package/dist/array/uniq.d.ts.map +1 -0
- package/dist/array/uniq.js +15 -17
- package/dist/array/uniq.js.map +1 -1
- package/dist/async/attempt.cjs +2 -2
- package/dist/async/attempt.cjs.map +1 -1
- package/dist/async/attempt.d.ts +40 -0
- package/dist/async/attempt.d.ts.map +1 -0
- package/dist/async/attempt.js +19 -14
- package/dist/async/attempt.js.map +1 -1
- package/dist/async/defer.cjs +2 -2
- package/dist/async/defer.cjs.map +1 -1
- package/dist/async/defer.d.ts +23 -0
- package/dist/async/defer.d.ts.map +1 -0
- package/dist/async/defer.js +12 -9
- package/dist/async/defer.js.map +1 -1
- package/dist/async/index.d.ts +12 -0
- package/dist/async/index.d.ts.map +1 -0
- package/dist/async/parallel.cjs +2 -2
- package/dist/async/parallel.cjs.map +1 -1
- package/dist/async/parallel.d.ts +31 -0
- package/dist/async/parallel.d.ts.map +1 -0
- package/dist/async/parallel.js +26 -27
- package/dist/async/parallel.js.map +1 -1
- package/dist/async/pool.cjs +2 -2
- package/dist/async/pool.cjs.map +1 -1
- package/dist/async/pool.d.ts +21 -0
- package/dist/async/pool.d.ts.map +1 -0
- package/dist/async/pool.js +23 -21
- package/dist/async/pool.js.map +1 -1
- package/dist/async/predict.cjs +2 -2
- package/dist/async/predict.cjs.map +1 -1
- package/dist/async/predict.d.ts +24 -0
- package/dist/async/predict.d.ts.map +1 -0
- package/dist/async/predict.js +10 -12
- package/dist/async/predict.js.map +1 -1
- package/dist/async/queue.cjs +2 -2
- package/dist/async/queue.cjs.map +1 -1
- package/dist/async/queue.d.ts +43 -0
- package/dist/async/queue.d.ts.map +1 -0
- package/dist/async/queue.js +52 -56
- package/dist/async/queue.js.map +1 -1
- package/dist/async/race.cjs +2 -2
- package/dist/async/race.cjs.map +1 -1
- package/dist/async/race.d.ts +16 -0
- package/dist/async/race.d.ts.map +1 -0
- package/dist/async/race.js +8 -7
- package/dist/async/race.js.map +1 -1
- package/dist/async/retry.cjs +2 -2
- package/dist/async/retry.cjs.map +1 -1
- package/dist/async/retry.d.ts +32 -0
- package/dist/async/retry.d.ts.map +1 -0
- package/dist/async/retry.js +19 -24
- package/dist/async/retry.js.map +1 -1
- package/dist/async/scheduler.cjs +2 -0
- package/dist/async/scheduler.cjs.map +1 -0
- package/dist/async/scheduler.d.ts +51 -0
- package/dist/async/scheduler.d.ts.map +1 -0
- package/dist/async/scheduler.js +43 -0
- package/dist/async/scheduler.js.map +1 -0
- package/dist/async/sleep.cjs +2 -2
- package/dist/async/sleep.cjs.map +1 -1
- package/dist/async/sleep.d.ts +16 -0
- package/dist/async/sleep.d.ts.map +1 -0
- package/dist/async/sleep.js +11 -11
- package/dist/async/sleep.js.map +1 -1
- package/dist/async/waitFor.cjs +2 -2
- package/dist/async/waitFor.cjs.map +1 -1
- package/dist/async/waitFor.d.ts +33 -0
- package/dist/async/waitFor.d.ts.map +1 -0
- package/dist/async/waitFor.js +29 -36
- package/dist/async/waitFor.js.map +1 -1
- package/dist/date/expires.cjs +2 -2
- package/dist/date/expires.cjs.map +1 -1
- package/dist/date/expires.d.ts +15 -0
- package/dist/date/expires.d.ts.map +1 -0
- package/dist/date/expires.js +11 -10
- package/dist/date/expires.js.map +1 -1
- package/dist/date/index.d.ts +4 -0
- package/dist/date/index.d.ts.map +1 -0
- package/dist/date/interval.cjs +2 -2
- package/dist/date/interval.cjs.map +1 -1
- package/dist/date/interval.d.ts +25 -0
- package/dist/date/interval.d.ts.map +1 -0
- package/dist/date/interval.js +31 -37
- package/dist/date/interval.js.map +1 -1
- package/dist/date/timeDiff.cjs +2 -2
- package/dist/date/timeDiff.cjs.map +1 -1
- package/dist/date/timeDiff.d.ts +24 -0
- package/dist/date/timeDiff.d.ts.map +1 -0
- package/dist/date/timeDiff.js +58 -25
- package/dist/date/timeDiff.js.map +1 -1
- package/dist/function/assert.cjs +2 -3
- package/dist/function/assert.cjs.map +1 -1
- package/dist/function/assert.d.ts +38 -0
- package/dist/function/assert.d.ts.map +1 -0
- package/dist/function/assert.js +13 -11
- package/dist/function/assert.js.map +1 -1
- package/dist/function/assertParams.cjs +2 -2
- package/dist/function/assertParams.cjs.map +1 -1
- package/dist/function/assertParams.d.ts +24 -0
- package/dist/function/assertParams.d.ts.map +1 -0
- package/dist/function/assertParams.js +13 -12
- package/dist/function/assertParams.js.map +1 -1
- package/dist/function/compare.cjs +2 -2
- package/dist/function/compare.cjs.map +1 -1
- package/dist/function/compare.d.ts +23 -0
- package/dist/function/compare.d.ts.map +1 -0
- package/dist/function/compare.js +22 -21
- package/dist/function/compare.js.map +1 -1
- package/dist/function/compareBy.cjs +2 -2
- package/dist/function/compareBy.cjs.map +1 -1
- package/dist/function/compareBy.d.ts +24 -0
- package/dist/function/compareBy.d.ts.map +1 -0
- package/dist/function/compareBy.js +15 -14
- package/dist/function/compareBy.js.map +1 -1
- package/dist/function/compose.cjs +2 -2
- package/dist/function/compose.cjs.map +1 -1
- package/dist/function/compose.d.ts +22 -0
- package/dist/function/compose.d.ts.map +1 -0
- package/dist/function/compose.js +10 -13
- package/dist/function/compose.js.map +1 -1
- package/dist/function/curry.cjs +2 -2
- package/dist/function/curry.cjs.map +1 -1
- package/dist/function/curry.d.ts +21 -0
- package/dist/function/curry.d.ts.map +1 -0
- package/dist/function/curry.js +8 -7
- package/dist/function/curry.js.map +1 -1
- package/dist/function/debounce.cjs +2 -2
- package/dist/function/debounce.cjs.map +1 -1
- package/dist/function/debounce.d.ts +12 -0
- package/dist/function/debounce.d.ts.map +1 -0
- package/dist/function/debounce.js +34 -26
- package/dist/function/debounce.js.map +1 -1
- package/dist/function/fp.cjs +2 -2
- package/dist/function/fp.cjs.map +1 -1
- package/dist/function/fp.d.ts +24 -0
- package/dist/function/fp.d.ts.map +1 -0
- package/dist/function/fp.js +6 -10
- package/dist/function/fp.js.map +1 -1
- package/dist/function/index.d.ts +13 -0
- package/dist/function/index.d.ts.map +1 -0
- package/dist/function/memo.cjs +2 -2
- package/dist/function/memo.cjs.map +1 -1
- package/dist/function/memo.d.ts +30 -0
- package/dist/function/memo.d.ts.map +1 -0
- package/dist/function/memo.js +16 -24
- package/dist/function/memo.js.map +1 -1
- package/dist/function/once.cjs +2 -2
- package/dist/function/once.cjs.map +1 -1
- package/dist/function/once.d.ts +24 -0
- package/dist/function/once.d.ts.map +1 -0
- package/dist/function/once.js +10 -10
- package/dist/function/once.js.map +1 -1
- package/dist/function/pipe.cjs +2 -2
- package/dist/function/pipe.cjs.map +1 -1
- package/dist/function/pipe.d.ts +23 -0
- package/dist/function/pipe.d.ts.map +1 -0
- package/dist/function/pipe.js +10 -10
- package/dist/function/pipe.js.map +1 -1
- package/dist/function/throttle.cjs +2 -2
- package/dist/function/throttle.cjs.map +1 -1
- package/dist/function/throttle.d.ts +21 -0
- package/dist/function/throttle.d.ts.map +1 -0
- package/dist/function/throttle.js +45 -37
- package/dist/function/throttle.js.map +1 -1
- package/dist/index.cjs +1 -2
- package/dist/index.d.ts +77 -2813
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +75 -253
- package/dist/math/abs.cjs +2 -2
- package/dist/math/abs.cjs.map +1 -1
- package/dist/math/abs.d.ts +17 -0
- package/dist/math/abs.d.ts.map +1 -0
- package/dist/math/abs.js +7 -6
- package/dist/math/abs.js.map +1 -1
- package/dist/math/allocate.cjs +2 -2
- package/dist/math/allocate.cjs.map +1 -1
- package/dist/math/allocate.d.ts +24 -0
- package/dist/math/allocate.d.ts.map +1 -0
- package/dist/math/allocate.js +20 -28
- package/dist/math/allocate.js.map +1 -1
- package/dist/math/average.cjs +2 -2
- package/dist/math/average.cjs.map +1 -1
- package/dist/math/average.d.ts +16 -0
- package/dist/math/average.d.ts.map +1 -0
- package/dist/math/average.js +13 -24
- package/dist/math/average.js.map +1 -1
- package/dist/math/clamp.cjs +2 -2
- package/dist/math/clamp.cjs.map +1 -1
- package/dist/math/clamp.d.ts +18 -0
- package/dist/math/clamp.d.ts.map +1 -0
- package/dist/math/clamp.js +7 -6
- package/dist/math/clamp.js.map +1 -1
- package/dist/math/distribute.cjs +2 -2
- package/dist/math/distribute.cjs.map +1 -1
- package/dist/math/distribute.d.ts +24 -0
- package/dist/math/distribute.d.ts.map +1 -0
- package/dist/math/distribute.js +14 -17
- package/dist/math/distribute.js.map +1 -1
- package/dist/math/index.d.ts +14 -0
- package/dist/math/index.d.ts.map +1 -0
- package/dist/math/linspace.cjs +2 -0
- package/dist/math/linspace.cjs.map +1 -0
- package/dist/math/linspace.d.ts +19 -0
- package/dist/math/linspace.d.ts.map +1 -0
- package/dist/math/linspace.js +11 -0
- package/dist/math/linspace.js.map +1 -0
- package/dist/math/max.cjs +2 -2
- package/dist/math/max.cjs.map +1 -1
- package/dist/math/max.d.ts +23 -0
- package/dist/math/max.d.ts.map +1 -0
- package/dist/math/max.js +10 -11
- package/dist/math/max.js.map +1 -1
- package/dist/math/median.cjs +2 -2
- package/dist/math/median.cjs.map +1 -1
- package/dist/math/median.d.ts +17 -0
- package/dist/math/median.d.ts.map +1 -0
- package/dist/math/median.js +11 -10
- package/dist/math/median.js.map +1 -1
- package/dist/math/min.cjs +2 -2
- package/dist/math/min.cjs.map +1 -1
- package/dist/math/min.d.ts +23 -0
- package/dist/math/min.d.ts.map +1 -0
- package/dist/math/min.js +10 -11
- package/dist/math/min.js.map +1 -1
- package/dist/math/percent.cjs +2 -0
- package/dist/math/percent.cjs.map +1 -0
- package/dist/math/percent.d.ts +19 -0
- package/dist/math/percent.d.ts.map +1 -0
- package/dist/math/percent.js +8 -0
- package/dist/math/percent.js.map +1 -0
- package/dist/math/range.cjs +2 -2
- package/dist/math/range.cjs.map +1 -1
- package/dist/math/range.d.ts +23 -0
- package/dist/math/range.d.ts.map +1 -0
- package/dist/math/range.js +28 -17
- package/dist/math/range.js.map +1 -1
- package/dist/math/round.cjs +2 -2
- package/dist/math/round.cjs.map +1 -1
- package/dist/math/round.d.ts +21 -0
- package/dist/math/round.d.ts.map +1 -0
- package/dist/math/round.js +9 -8
- package/dist/math/round.js.map +1 -1
- package/dist/math/sum.cjs +2 -2
- package/dist/math/sum.cjs.map +1 -1
- package/dist/math/sum.d.ts +17 -0
- package/dist/math/sum.d.ts.map +1 -0
- package/dist/math/sum.js +11 -14
- package/dist/math/sum.js.map +1 -1
- package/dist/money/currency.cjs +2 -2
- package/dist/money/currency.cjs.map +1 -1
- package/dist/money/currency.d.ts +30 -0
- package/dist/money/currency.d.ts.map +1 -0
- package/dist/money/currency.js +19 -47
- package/dist/money/currency.js.map +1 -1
- package/dist/money/exchange.cjs +2 -2
- package/dist/money/exchange.cjs.map +1 -1
- package/dist/money/exchange.d.ts +29 -0
- package/dist/money/exchange.d.ts.map +1 -0
- package/dist/money/exchange.js +12 -12
- package/dist/money/exchange.js.map +1 -1
- package/dist/money/index.d.ts +4 -0
- package/dist/money/index.d.ts.map +1 -0
- package/dist/money/types.d.ts +9 -0
- package/dist/money/types.d.ts.map +1 -0
- package/dist/object/diff.cjs +2 -2
- package/dist/object/diff.cjs.map +1 -1
- package/dist/object/diff.d.ts +26 -0
- package/dist/object/diff.d.ts.map +1 -0
- package/dist/object/diff.js +19 -17
- package/dist/object/diff.js.map +1 -1
- package/dist/object/index.d.ts +9 -0
- package/dist/object/index.d.ts.map +1 -0
- package/dist/object/merge.cjs +2 -2
- package/dist/object/merge.cjs.map +1 -1
- package/dist/object/merge.d.ts +44 -0
- package/dist/object/merge.d.ts.map +1 -0
- package/dist/object/merge.js +27 -21
- package/dist/object/merge.js.map +1 -1
- package/dist/object/parseJSON.cjs +2 -2
- package/dist/object/parseJSON.cjs.map +1 -1
- package/dist/object/parseJSON.d.ts +32 -0
- package/dist/object/parseJSON.d.ts.map +1 -0
- package/dist/object/parseJSON.js +17 -18
- package/dist/object/parseJSON.js.map +1 -1
- package/dist/object/path.cjs +2 -2
- package/dist/object/path.cjs.map +1 -1
- package/dist/object/path.d.ts +32 -0
- package/dist/object/path.d.ts.map +1 -0
- package/dist/object/path.js +25 -23
- package/dist/object/path.js.map +1 -1
- package/dist/object/proxy.cjs +2 -0
- package/dist/object/proxy.cjs.map +1 -0
- package/dist/object/proxy.d.ts +30 -0
- package/dist/object/proxy.d.ts.map +1 -0
- package/dist/object/proxy.js +21 -0
- package/dist/object/proxy.js.map +1 -0
- package/dist/object/prune.cjs +2 -0
- package/dist/object/prune.cjs.map +1 -0
- package/dist/object/prune.d.ts +21 -0
- package/dist/object/prune.d.ts.map +1 -0
- package/dist/object/prune.js +31 -0
- package/dist/object/prune.js.map +1 -0
- package/dist/object/seek.cjs +2 -2
- package/dist/object/seek.cjs.map +1 -1
- package/dist/object/seek.d.ts +2 -0
- package/dist/object/seek.d.ts.map +1 -0
- package/dist/object/seek.js +25 -12
- package/dist/object/seek.js.map +1 -1
- package/dist/object/stash.cjs +2 -0
- package/dist/object/stash.cjs.map +1 -0
- package/dist/object/stash.d.ts +45 -0
- package/dist/object/stash.d.ts.map +1 -0
- package/dist/object/stash.js +99 -0
- package/dist/object/stash.js.map +1 -0
- package/dist/random/draw.cjs +2 -2
- package/dist/random/draw.cjs.map +1 -1
- package/dist/random/draw.d.ts +16 -0
- package/dist/random/draw.d.ts.map +1 -0
- package/dist/random/draw.js +13 -10
- package/dist/random/draw.js.map +1 -1
- package/dist/random/index.d.ts +5 -0
- package/dist/random/index.d.ts.map +1 -0
- package/dist/random/random.cjs +2 -2
- package/dist/random/random.cjs.map +1 -1
- package/dist/random/random.d.ts +14 -0
- package/dist/random/random.d.ts.map +1 -0
- package/dist/random/random.js +16 -9
- package/dist/random/random.js.map +1 -1
- package/dist/random/shuffle.cjs +2 -2
- package/dist/random/shuffle.cjs.map +1 -1
- package/dist/random/shuffle.d.ts +17 -0
- package/dist/random/shuffle.d.ts.map +1 -0
- package/dist/random/shuffle.js +18 -14
- package/dist/random/shuffle.js.map +1 -1
- package/dist/random/uuid.cjs +2 -2
- package/dist/random/uuid.cjs.map +1 -1
- package/dist/random/uuid.d.ts +12 -0
- package/dist/random/uuid.d.ts.map +1 -0
- package/dist/random/uuid.js +7 -9
- package/dist/random/uuid.js.map +1 -1
- package/dist/string/_caseUtils.cjs +2 -2
- package/dist/string/_caseUtils.cjs.map +1 -1
- package/dist/string/_caseUtils.d.ts +13 -0
- package/dist/string/_caseUtils.d.ts.map +1 -0
- package/dist/string/_caseUtils.js +8 -8
- package/dist/string/_caseUtils.js.map +1 -1
- package/dist/string/camelCase.cjs +2 -2
- package/dist/string/camelCase.cjs.map +1 -1
- package/dist/string/camelCase.d.ts +14 -0
- package/dist/string/camelCase.d.ts.map +1 -0
- package/dist/string/camelCase.js +8 -7
- package/dist/string/camelCase.js.map +1 -1
- package/dist/string/index.d.ts +7 -0
- package/dist/string/index.d.ts.map +1 -0
- package/dist/string/kebabCase.cjs +2 -2
- package/dist/string/kebabCase.cjs.map +1 -1
- package/dist/string/kebabCase.d.ts +15 -0
- package/dist/string/kebabCase.d.ts.map +1 -0
- package/dist/string/kebabCase.js +8 -7
- package/dist/string/kebabCase.js.map +1 -1
- package/dist/string/pascalCase.cjs +2 -2
- package/dist/string/pascalCase.cjs.map +1 -1
- package/dist/string/pascalCase.d.ts +15 -0
- package/dist/string/pascalCase.d.ts.map +1 -0
- package/dist/string/pascalCase.js +8 -7
- package/dist/string/pascalCase.js.map +1 -1
- package/dist/string/similarity.cjs +2 -2
- package/dist/string/similarity.cjs.map +1 -1
- package/dist/string/similarity.d.ts +20 -0
- package/dist/string/similarity.d.ts.map +1 -0
- package/dist/string/similarity.js +20 -36
- package/dist/string/similarity.js.map +1 -1
- package/dist/string/snakeCase.cjs +2 -2
- package/dist/string/snakeCase.cjs.map +1 -1
- package/dist/string/snakeCase.d.ts +15 -0
- package/dist/string/snakeCase.d.ts.map +1 -0
- package/dist/string/snakeCase.js +8 -7
- package/dist/string/snakeCase.js.map +1 -1
- package/dist/string/truncate.cjs +2 -2
- package/dist/string/truncate.cjs.map +1 -1
- package/dist/string/truncate.d.ts +28 -0
- package/dist/string/truncate.d.ts.map +1 -0
- package/dist/string/truncate.js +20 -17
- package/dist/string/truncate.js.map +1 -1
- package/dist/toolkit.cjs +2 -0
- package/dist/toolkit.cjs.map +1 -0
- package/dist/toolkit.js +1523 -0
- package/dist/toolkit.js.map +1 -0
- package/dist/typed/index.d.ts +24 -0
- package/dist/typed/index.d.ts.map +1 -0
- package/dist/typed/is.cjs +2 -2
- package/dist/typed/is.cjs.map +1 -1
- package/dist/typed/is.d.ts +95 -0
- package/dist/typed/is.d.ts.map +1 -0
- package/dist/typed/is.js +54 -42
- package/dist/typed/is.js.map +1 -1
- package/dist/typed/isArray.cjs +2 -2
- package/dist/typed/isArray.cjs.map +1 -1
- package/dist/typed/isArray.d.ts +16 -0
- package/dist/typed/isArray.d.ts.map +1 -0
- package/dist/typed/isArray.js +8 -8
- package/dist/typed/isArray.js.map +1 -1
- package/dist/typed/isBoolean.cjs +2 -2
- package/dist/typed/isBoolean.cjs.map +1 -1
- package/dist/typed/isBoolean.d.ts +23 -0
- package/dist/typed/isBoolean.d.ts.map +1 -0
- package/dist/typed/isBoolean.js +7 -6
- package/dist/typed/isBoolean.js.map +1 -1
- package/dist/typed/isDate.cjs +2 -2
- package/dist/typed/isDate.cjs.map +1 -1
- package/dist/typed/isDate.d.ts +16 -0
- package/dist/typed/isDate.d.ts.map +1 -0
- package/dist/typed/isDate.js +7 -8
- package/dist/typed/isDate.js.map +1 -1
- package/dist/typed/isDefined.cjs +2 -2
- package/dist/typed/isDefined.cjs.map +1 -1
- package/dist/typed/isDefined.d.ts +19 -0
- package/dist/typed/isDefined.d.ts.map +1 -0
- package/dist/typed/isDefined.js +7 -6
- package/dist/typed/isDefined.js.map +1 -1
- package/dist/typed/isEmpty.cjs +2 -2
- package/dist/typed/isEmpty.cjs.map +1 -1
- package/dist/typed/isEmpty.d.ts +24 -0
- package/dist/typed/isEmpty.d.ts.map +1 -0
- package/dist/typed/isEmpty.js +8 -9
- package/dist/typed/isEmpty.js.map +1 -1
- package/dist/typed/isEqual.cjs +2 -2
- package/dist/typed/isEqual.cjs.map +1 -1
- package/dist/typed/isEqual.d.ts +24 -0
- package/dist/typed/isEqual.d.ts.map +1 -0
- package/dist/typed/isEqual.js +27 -28
- package/dist/typed/isEqual.js.map +1 -1
- package/dist/typed/isEven.cjs +2 -2
- package/dist/typed/isEven.cjs.map +1 -1
- package/dist/typed/isEven.d.ts +9 -0
- package/dist/typed/isEven.d.ts.map +1 -0
- package/dist/typed/isEven.js +7 -6
- package/dist/typed/isEven.js.map +1 -1
- package/dist/typed/isFunction.cjs +2 -2
- package/dist/typed/isFunction.cjs.map +1 -1
- package/dist/typed/isFunction.d.ts +16 -0
- package/dist/typed/isFunction.d.ts.map +1 -0
- package/dist/typed/isFunction.js +7 -8
- package/dist/typed/isFunction.js.map +1 -1
- package/dist/typed/isMatch.cjs +2 -2
- package/dist/typed/isMatch.cjs.map +1 -1
- package/dist/typed/isMatch.d.ts +23 -0
- package/dist/typed/isMatch.d.ts.map +1 -0
- package/dist/typed/isMatch.js +16 -18
- package/dist/typed/isMatch.js.map +1 -1
- package/dist/typed/isNegative.cjs +2 -2
- package/dist/typed/isNegative.cjs.map +1 -1
- package/dist/typed/isNegative.d.ts +26 -0
- package/dist/typed/isNegative.d.ts.map +1 -0
- package/dist/typed/isNegative.js +7 -6
- package/dist/typed/isNegative.js.map +1 -1
- package/dist/typed/isNil.cjs +2 -2
- package/dist/typed/isNil.cjs.map +1 -1
- package/dist/typed/isNil.d.ts +17 -0
- package/dist/typed/isNil.d.ts.map +1 -0
- package/dist/typed/isNil.js +7 -8
- package/dist/typed/isNil.js.map +1 -1
- package/dist/typed/isNumber.cjs +2 -2
- package/dist/typed/isNumber.cjs.map +1 -1
- package/dist/typed/isNumber.d.ts +16 -0
- package/dist/typed/isNumber.d.ts.map +1 -0
- package/dist/typed/isNumber.js +8 -8
- package/dist/typed/isNumber.js.map +1 -1
- package/dist/typed/isObject.cjs +2 -2
- package/dist/typed/isObject.cjs.map +1 -1
- package/dist/typed/isObject.d.ts +19 -0
- package/dist/typed/isObject.d.ts.map +1 -0
- package/dist/typed/isObject.js +8 -8
- package/dist/typed/isObject.js.map +1 -1
- package/dist/typed/isOdd.cjs +2 -2
- package/dist/typed/isOdd.cjs.map +1 -1
- package/dist/typed/isOdd.d.ts +9 -0
- package/dist/typed/isOdd.d.ts.map +1 -0
- package/dist/typed/isOdd.js +7 -6
- package/dist/typed/isOdd.js.map +1 -1
- package/dist/typed/isPositive.cjs +2 -2
- package/dist/typed/isPositive.cjs.map +1 -1
- package/dist/typed/isPositive.d.ts +26 -0
- package/dist/typed/isPositive.d.ts.map +1 -0
- package/dist/typed/isPositive.js +7 -6
- package/dist/typed/isPositive.js.map +1 -1
- package/dist/typed/isPrimitive.cjs +2 -2
- package/dist/typed/isPrimitive.cjs.map +1 -1
- package/dist/typed/isPrimitive.d.ts +18 -0
- package/dist/typed/isPrimitive.d.ts.map +1 -0
- package/dist/typed/isPrimitive.js +8 -9
- package/dist/typed/isPrimitive.js.map +1 -1
- package/dist/typed/isPromise.cjs +2 -2
- package/dist/typed/isPromise.cjs.map +1 -1
- package/dist/typed/isPromise.d.ts +17 -0
- package/dist/typed/isPromise.d.ts.map +1 -0
- package/dist/typed/isPromise.js +7 -9
- package/dist/typed/isPromise.js.map +1 -1
- package/dist/typed/isRegex.cjs +2 -2
- package/dist/typed/isRegex.cjs.map +1 -1
- package/dist/typed/isRegex.d.ts +21 -0
- package/dist/typed/isRegex.d.ts.map +1 -0
- package/dist/typed/isRegex.js +7 -6
- package/dist/typed/isRegex.js.map +1 -1
- package/dist/typed/isString.cjs +2 -2
- package/dist/typed/isString.cjs.map +1 -1
- package/dist/typed/isString.d.ts +16 -0
- package/dist/typed/isString.d.ts.map +1 -0
- package/dist/typed/isString.js +8 -8
- package/dist/typed/isString.js.map +1 -1
- package/dist/typed/isWithin.cjs +2 -2
- package/dist/typed/isWithin.cjs.map +1 -1
- package/dist/typed/isWithin.d.ts +20 -0
- package/dist/typed/isWithin.d.ts.map +1 -0
- package/dist/typed/isWithin.js +9 -9
- package/dist/typed/isWithin.js.map +1 -1
- package/dist/typed/isZero.cjs +2 -2
- package/dist/typed/isZero.cjs.map +1 -1
- package/dist/typed/isZero.d.ts +25 -0
- package/dist/typed/isZero.d.ts.map +1 -0
- package/dist/typed/isZero.js +7 -6
- package/dist/typed/isZero.js.map +1 -1
- package/dist/typed/typeOf.cjs +2 -2
- package/dist/typed/typeOf.cjs.map +1 -1
- package/dist/typed/typeOf.d.ts +30 -0
- package/dist/typed/typeOf.d.ts.map +1 -0
- package/dist/typed/typeOf.js +11 -13
- package/dist/typed/typeOf.js.map +1 -1
- package/dist/types.d.ts +9 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +77 -12
- package/dist/array/aggregate.cjs +0 -2
- package/dist/array/aggregate.cjs.map +0 -1
- package/dist/array/aggregate.js +0 -16
- package/dist/array/aggregate.js.map +0 -1
- package/dist/array/alternate.cjs +0 -2
- package/dist/array/alternate.cjs.map +0 -1
- package/dist/array/alternate.js +0 -9
- package/dist/array/alternate.js.map +0 -1
- package/dist/array/arrange.cjs +0 -2
- package/dist/array/arrange.cjs.map +0 -1
- package/dist/array/arrange.js +0 -6
- package/dist/array/arrange.js.map +0 -1
- package/dist/array/compact.cjs +0 -2
- package/dist/array/compact.cjs.map +0 -1
- package/dist/array/compact.js +0 -9
- package/dist/array/compact.js.map +0 -1
- package/dist/array/every.cjs +0 -2
- package/dist/array/every.cjs.map +0 -1
- package/dist/array/every.js +0 -14
- package/dist/array/every.js.map +0 -1
- package/dist/array/filter.cjs +0 -2
- package/dist/array/filter.cjs.map +0 -1
- package/dist/array/filter.js +0 -14
- package/dist/array/filter.js.map +0 -1
- package/dist/array/find.cjs +0 -2
- package/dist/array/find.cjs.map +0 -1
- package/dist/array/find.js +0 -14
- package/dist/array/find.js.map +0 -1
- package/dist/array/findIndex.cjs +0 -2
- package/dist/array/findIndex.cjs.map +0 -1
- package/dist/array/findIndex.js +0 -14
- package/dist/array/findIndex.js.map +0 -1
- package/dist/array/findLast.cjs +0 -2
- package/dist/array/findLast.cjs.map +0 -1
- package/dist/array/findLast.js +0 -14
- package/dist/array/findLast.js.map +0 -1
- package/dist/array/flatten.cjs +0 -2
- package/dist/array/flatten.cjs.map +0 -1
- package/dist/array/flatten.js +0 -7
- package/dist/array/flatten.js.map +0 -1
- package/dist/array/map.cjs +0 -2
- package/dist/array/map.cjs.map +0 -1
- package/dist/array/map.js +0 -18
- package/dist/array/map.js.map +0 -1
- package/dist/array/reduce.cjs +0 -2
- package/dist/array/reduce.cjs.map +0 -1
- package/dist/array/reduce.js +0 -16
- package/dist/array/reduce.js.map +0 -1
- package/dist/array/shift.cjs +0 -2
- package/dist/array/shift.cjs.map +0 -1
- package/dist/array/shift.js +0 -13
- package/dist/array/shift.js.map +0 -1
- package/dist/array/some.cjs +0 -2
- package/dist/array/some.cjs.map +0 -1
- package/dist/array/some.js +0 -14
- package/dist/array/some.js.map +0 -1
- package/dist/array/substitute.cjs +0 -2
- package/dist/array/substitute.cjs.map +0 -1
- package/dist/array/substitute.js +0 -13
- package/dist/array/substitute.js.map +0 -1
- package/dist/async/delay.cjs +0 -2
- package/dist/async/delay.cjs.map +0 -1
- package/dist/async/delay.js +0 -8
- package/dist/async/delay.js.map +0 -1
- package/dist/function/proxy.cjs +0 -2
- package/dist/function/proxy.cjs.map +0 -1
- package/dist/function/proxy.js +0 -22
- package/dist/function/proxy.js.map +0 -1
- package/dist/function/prune.cjs +0 -2
- package/dist/function/prune.cjs.map +0 -1
- package/dist/function/prune.js +0 -30
- package/dist/function/prune.js.map +0 -1
- package/dist/function/worker.cjs +0 -14
- package/dist/function/worker.cjs.map +0 -1
- package/dist/function/worker.js +0 -29
- package/dist/function/worker.js.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/logit/dist/logit.cjs +0 -2
- package/dist/logit/dist/logit.cjs.map +0 -1
- package/dist/logit/dist/logit.js +0 -263
- package/dist/logit/dist/logit.js.map +0 -1
- package/dist/math/add.cjs +0 -2
- package/dist/math/add.cjs.map +0 -1
- package/dist/math/add.js +0 -9
- package/dist/math/add.js.map +0 -1
- package/dist/math/boil.cjs +0 -2
- package/dist/math/boil.cjs.map +0 -1
- package/dist/math/boil.js +0 -17
- package/dist/math/boil.js.map +0 -1
- package/dist/math/divide.cjs +0 -2
- package/dist/math/divide.cjs.map +0 -1
- package/dist/math/divide.js +0 -11
- package/dist/math/divide.js.map +0 -1
- package/dist/math/multiply.cjs +0 -2
- package/dist/math/multiply.cjs.map +0 -1
- package/dist/math/multiply.js +0 -9
- package/dist/math/multiply.js.map +0 -1
- package/dist/math/rate.cjs +0 -2
- package/dist/math/rate.cjs.map +0 -1
- package/dist/math/rate.js +0 -9
- package/dist/math/rate.js.map +0 -1
- package/dist/math/subtract.cjs +0 -2
- package/dist/math/subtract.cjs.map +0 -1
- package/dist/math/subtract.js +0 -9
- package/dist/math/subtract.js.map +0 -1
- package/dist/object/cache.cjs +0 -2
- package/dist/object/cache.cjs.map +0 -1
- package/dist/object/cache.js +0 -63
- package/dist/object/cache.js.map +0 -1
- package/dist/object/clone.cjs +0 -2
- package/dist/object/clone.cjs.map +0 -1
- package/dist/object/clone.js +0 -17
- package/dist/object/clone.js.map +0 -1
- package/dist/object/entries.cjs +0 -2
- package/dist/object/entries.cjs.map +0 -1
- package/dist/object/entries.js +0 -9
- package/dist/object/entries.js.map +0 -1
- package/dist/object/keys.cjs +0 -2
- package/dist/object/keys.cjs.map +0 -1
- package/dist/object/keys.js +0 -9
- package/dist/object/keys.js.map +0 -1
- package/dist/object/values.cjs +0 -2
- package/dist/object/values.cjs.map +0 -1
- package/dist/object/values.js +0 -9
- package/dist/object/values.js.map +0 -1
- package/dist/typed/ge.cjs +0 -2
- package/dist/typed/ge.cjs.map +0 -1
- package/dist/typed/ge.js +0 -7
- package/dist/typed/ge.js.map +0 -1
- package/dist/typed/gt.cjs +0 -2
- package/dist/typed/gt.cjs.map +0 -1
- package/dist/typed/gt.js +0 -7
- package/dist/typed/gt.js.map +0 -1
- package/dist/typed/le.cjs +0 -2
- package/dist/typed/le.cjs.map +0 -1
- package/dist/typed/le.js +0 -7
- package/dist/typed/le.js.map +0 -1
- package/dist/typed/lt.cjs +0 -2
- package/dist/typed/lt.cjs.map +0 -1
- package/dist/typed/lt.js +0 -7
- package/dist/typed/lt.js.map +0 -1
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Predicate } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Replaces the first element in an array that satisfies the provided predicate
|
|
4
|
+
* function with a new value.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* replace([1, 2, 3], (n) => n === 2, 4) // [1, 4, 3]
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* @param array - The array to search.
|
|
12
|
+
* @param predicate - A function to test each element of the array.
|
|
13
|
+
* @param value - The new value to replace the found element.
|
|
14
|
+
*
|
|
15
|
+
* @return A new array with the replaced value.
|
|
16
|
+
*
|
|
17
|
+
* @throws {TypeError} If the first argument is not an array.
|
|
18
|
+
*/
|
|
19
|
+
export declare function replace<T>(array: T[], predicate: Predicate<T>, value: T): T[];
|
|
20
|
+
//# sourceMappingURL=replace.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replace.d.ts","sourceRoot":"","sources":["../../src/array/replace.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAK1C;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,EAAE,CAQ7E"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { assert as e } from "../function/assert.js";
|
|
2
|
+
import { IS_ARRAY_ERROR_MSG as t, isArray as n } from "../typed/isArray.js";
|
|
3
|
+
//#region src/array/replace.ts
|
|
4
|
+
function r(r, i, a) {
|
|
5
|
+
e(n(r), t, {
|
|
6
|
+
args: { array: r },
|
|
7
|
+
type: TypeError
|
|
8
|
+
});
|
|
9
|
+
let o = r.findIndex(i);
|
|
10
|
+
return o === -1 ? r : [
|
|
11
|
+
...r.slice(0, o),
|
|
12
|
+
a,
|
|
13
|
+
...r.slice(o + 1)
|
|
14
|
+
];
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
export { r as replace };
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=replace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replace.js","names":[],"sources":["../../src/array/replace.ts"],"sourcesContent":["import type { Predicate } from '../types';\n\nimport { assert } from '../function/assert';\nimport { IS_ARRAY_ERROR_MSG, isArray } from '../typed/isArray';\n\n/**\n * Replaces the first element in an array that satisfies the provided predicate\n * function with a new value.\n *\n * @example\n * ```ts\n * replace([1, 2, 3], (n) => n === 2, 4) // [1, 4, 3]\n * ```\n *\n * @param array - The array to search.\n * @param predicate - A function to test each element of the array.\n * @param value - The new value to replace the found element.\n *\n * @return A new array with the replaced value.\n *\n * @throws {TypeError} If the first argument is not an array.\n */\nexport function replace<T>(array: T[], predicate: Predicate<T>, value: T): T[] {\n assert(isArray(array), IS_ARRAY_ERROR_MSG, { args: { array }, type: TypeError });\n\n const index = array.findIndex(predicate);\n\n if (index === -1) return array;\n\n return [...array.slice(0, index), value, ...array.slice(index + 1)];\n}\n"],"mappings":";;;AAsBA,SAAgB,EAAW,GAAY,GAAyB,GAAe;AAC7E,GAAO,EAAQ,EAAM,EAAE,GAAoB;EAAE,MAAM,EAAE,UAAO;EAAE,MAAM;EAAW,CAAC;CAEhF,IAAM,IAAQ,EAAM,UAAU,EAAU;AAIxC,QAFI,MAAU,KAAW,IAElB;EAAC,GAAG,EAAM,MAAM,GAAG,EAAM;EAAE;EAAO,GAAG,EAAM,MAAM,IAAQ,EAAE;EAAC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require(`../function/assert.cjs`),t=require(`../typed/isArray.cjs`),n=require(`../typed/isNumber.cjs`);function r(r,i,{wrap:a=!1}={}){if(e.assert(t.isArray(r),t.IS_ARRAY_ERROR_MSG,{args:{array:r},type:TypeError}),e.assert(n.isNumber(i),n.IS_NUMBER_ERROR_MSG,{args:{positions:i},type:TypeError}),r.length===0)return r;let o=(i%r.length+r.length)%r.length,s=r.slice(o);return a?[...s,...r.slice(0,o)]:s}exports.rotate=r;
|
|
2
|
+
//# sourceMappingURL=rotate.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rotate.cjs","names":[],"sources":["../../src/array/rotate.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { IS_ARRAY_ERROR_MSG, isArray } from '../typed/isArray';\nimport { IS_NUMBER_ERROR_MSG, isNumber } from '../typed/isNumber';\n\n/**\n * Rotates the elements of an array by a specified number of positions.\n *\n * @example\n * ```ts\n * const arr = [1, 2, 3, 4, 5];\n * rotate(arr, 2); // [3, 4, 5]\n * rotate(arr, 2, { wrap: true }); // [3, 4, 5, 1, 2]\n * ```\n * @param array - The array to rotate.\n * @param positions - The number of positions to rotate the array.\n * @param [options] - Options for the rotate operation.\n * @param [options.wrap] - If `true`, the rotated-out elements are appended to the end.\n *\n * @returns A new array with the elements rotated.\n *\n * @throws {TypeError} If the first argument is not an array, or the second argument is not a number.\n */\nexport function rotate<T>(array: T[], positions: number, { wrap = false }: { wrap?: boolean } = {}): T[] {\n assert(isArray(array), IS_ARRAY_ERROR_MSG, { args: { array }, type: TypeError });\n assert(isNumber(positions), IS_NUMBER_ERROR_MSG, { args: { positions }, type: TypeError });\n\n if (array.length === 0) return array;\n\n const normalizedPos = ((positions % array.length) + array.length) % array.length;\n const rotated = array.slice(normalizedPos);\n\n return wrap ? [...rotated, ...array.slice(0, normalizedPos)] : rotated;\n}\n"],"mappings":"+GAsBA,SAAgB,EAAU,EAAY,EAAmB,CAAE,OAAO,IAA8B,EAAE,CAAO,CAIvG,GAHA,EAAA,OAAO,EAAA,QAAQ,EAAM,CAAE,EAAA,mBAAoB,CAAE,KAAM,CAAE,QAAO,CAAE,KAAM,UAAW,CAAC,CAChF,EAAA,OAAO,EAAA,SAAS,EAAU,CAAE,EAAA,oBAAqB,CAAE,KAAM,CAAE,YAAW,CAAE,KAAM,UAAW,CAAC,CAEtF,EAAM,SAAW,EAAG,OAAO,EAE/B,IAAM,GAAkB,EAAY,EAAM,OAAU,EAAM,QAAU,EAAM,OACpE,EAAU,EAAM,MAAM,EAAc,CAE1C,OAAO,EAAO,CAAC,GAAG,EAAS,GAAG,EAAM,MAAM,EAAG,EAAc,CAAC,CAAG"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rotates the elements of an array by a specified number of positions.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* const arr = [1, 2, 3, 4, 5];
|
|
7
|
+
* rotate(arr, 2); // [3, 4, 5]
|
|
8
|
+
* rotate(arr, 2, { wrap: true }); // [3, 4, 5, 1, 2]
|
|
9
|
+
* ```
|
|
10
|
+
* @param array - The array to rotate.
|
|
11
|
+
* @param positions - The number of positions to rotate the array.
|
|
12
|
+
* @param [options] - Options for the rotate operation.
|
|
13
|
+
* @param [options.wrap] - If `true`, the rotated-out elements are appended to the end.
|
|
14
|
+
*
|
|
15
|
+
* @returns A new array with the elements rotated.
|
|
16
|
+
*
|
|
17
|
+
* @throws {TypeError} If the first argument is not an array, or the second argument is not a number.
|
|
18
|
+
*/
|
|
19
|
+
export declare function rotate<T>(array: T[], positions: number, { wrap }?: {
|
|
20
|
+
wrap?: boolean;
|
|
21
|
+
}): T[];
|
|
22
|
+
//# sourceMappingURL=rotate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rotate.d.ts","sourceRoot":"","sources":["../../src/array/rotate.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,IAAY,EAAE,GAAE;IAAE,IAAI,CAAC,EAAE,OAAO,CAAA;CAAO,GAAG,CAAC,EAAE,CAUvG"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { assert as e } from "../function/assert.js";
|
|
2
|
+
import { IS_ARRAY_ERROR_MSG as t, isArray as n } from "../typed/isArray.js";
|
|
3
|
+
import { IS_NUMBER_ERROR_MSG as r, isNumber as i } from "../typed/isNumber.js";
|
|
4
|
+
//#region src/array/rotate.ts
|
|
5
|
+
function a(a, o, { wrap: s = !1 } = {}) {
|
|
6
|
+
if (e(n(a), t, {
|
|
7
|
+
args: { array: a },
|
|
8
|
+
type: TypeError
|
|
9
|
+
}), e(i(o), r, {
|
|
10
|
+
args: { positions: o },
|
|
11
|
+
type: TypeError
|
|
12
|
+
}), a.length === 0) return a;
|
|
13
|
+
let c = (o % a.length + a.length) % a.length, l = a.slice(c);
|
|
14
|
+
return s ? [...l, ...a.slice(0, c)] : l;
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
export { a as rotate };
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=rotate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rotate.js","names":[],"sources":["../../src/array/rotate.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { IS_ARRAY_ERROR_MSG, isArray } from '../typed/isArray';\nimport { IS_NUMBER_ERROR_MSG, isNumber } from '../typed/isNumber';\n\n/**\n * Rotates the elements of an array by a specified number of positions.\n *\n * @example\n * ```ts\n * const arr = [1, 2, 3, 4, 5];\n * rotate(arr, 2); // [3, 4, 5]\n * rotate(arr, 2, { wrap: true }); // [3, 4, 5, 1, 2]\n * ```\n * @param array - The array to rotate.\n * @param positions - The number of positions to rotate the array.\n * @param [options] - Options for the rotate operation.\n * @param [options.wrap] - If `true`, the rotated-out elements are appended to the end.\n *\n * @returns A new array with the elements rotated.\n *\n * @throws {TypeError} If the first argument is not an array, or the second argument is not a number.\n */\nexport function rotate<T>(array: T[], positions: number, { wrap = false }: { wrap?: boolean } = {}): T[] {\n assert(isArray(array), IS_ARRAY_ERROR_MSG, { args: { array }, type: TypeError });\n assert(isNumber(positions), IS_NUMBER_ERROR_MSG, { args: { positions }, type: TypeError });\n\n if (array.length === 0) return array;\n\n const normalizedPos = ((positions % array.length) + array.length) % array.length;\n const rotated = array.slice(normalizedPos);\n\n return wrap ? [...rotated, ...array.slice(0, normalizedPos)] : rotated;\n}\n"],"mappings":";;;;AAsBA,SAAgB,EAAU,GAAY,GAAmB,EAAE,UAAO,OAA8B,EAAE,EAAO;AAIvG,KAHA,EAAO,EAAQ,EAAM,EAAE,GAAoB;EAAE,MAAM,EAAE,UAAO;EAAE,MAAM;EAAW,CAAC,EAChF,EAAO,EAAS,EAAU,EAAE,GAAqB;EAAE,MAAM,EAAE,cAAW;EAAE,MAAM;EAAW,CAAC,EAEtF,EAAM,WAAW,EAAG,QAAO;CAE/B,IAAM,KAAkB,IAAY,EAAM,SAAU,EAAM,UAAU,EAAM,QACpE,IAAU,EAAM,MAAM,EAAc;AAE1C,QAAO,IAAO,CAAC,GAAG,GAAS,GAAG,EAAM,MAAM,GAAG,EAAc,CAAC,GAAG"}
|
package/dist/array/search.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=search.cjs.map
|
|
1
|
+
const e=require(`../function/assert.cjs`),t=require(`../typed/isString.cjs`),n=require(`../typed/isWithin.cjs`),r=require(`../object/seek.cjs`);function i(i,a,o=.25){if(e.assert(t.isString(a),t.IS_STRING_ERROR_MSG,{args:{query:a},type:TypeError}),e.assert(n.isWithin(o,0,1),n.IS_WITHIN_ERROR_MSG,{args:{max:1,min:0,tone:o},type:TypeError}),!a)return[...i];let s=a.toLowerCase();return i.filter(e=>r.seek(e,s,o))}exports.search=i;
|
|
2
|
+
//# sourceMappingURL=search.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search.cjs","sources":["../../src/array/search.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { seek } from '../object/seek';\nimport { IS_STRING_ERROR_MSG, isString } from '../typed/isString';\nimport { IS_WITHIN_ERROR_MSG, isWithin } from '../typed/isWithin';\
|
|
1
|
+
{"version":3,"file":"search.cjs","names":[],"sources":["../../src/array/search.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { seek } from '../object/seek';\nimport { IS_STRING_ERROR_MSG, isString } from '../typed/isString';\nimport { IS_WITHIN_ERROR_MSG, isWithin } from '../typed/isWithin';\n\n/**\n * Performs a search on an array of objects, checking all values for a match with the search string.\n *\n * @example\n * ```ts\n * const data = [{ name: 'John Doe', age: 25 }, { name: 'Jane Doe', age: 30 }];\n * search(data, 'doe', 0.5); // [{ name: 'John Doe', age: 25 }, { name: 'Jane Doe', age: 30 }]\n * ```\n *\n * @param array - The array of objects to search.\n * @param query - The string to search for.\n * @param [tone=0.25] - Degree of similarity between 0 and 1.\n *\n * @returns The filtered array of objects that match the search string.\n *\n * @throws {Error} If input values are invalid.\n */\nexport function search<T>(array: T[], query: string, tone = 0.25): T[] {\n assert(isString(query), IS_STRING_ERROR_MSG, { args: { query }, type: TypeError });\n assert(isWithin(tone, 0, 1), IS_WITHIN_ERROR_MSG, { args: { max: 1, min: 0, tone }, type: TypeError });\n\n if (!query) return [...array];\n\n const searchTerm = query.toLowerCase();\n\n return array.filter((obj) => seek(obj as object, searchTerm, tone));\n}\n"],"mappings":"gJAsBA,SAAgB,EAAU,EAAY,EAAe,EAAO,IAAW,CAIrE,GAHA,EAAA,OAAO,EAAA,SAAS,EAAM,CAAE,EAAA,oBAAqB,CAAE,KAAM,CAAE,QAAO,CAAE,KAAM,UAAW,CAAC,CAClF,EAAA,OAAO,EAAA,SAAS,EAAM,EAAG,EAAE,CAAE,EAAA,oBAAqB,CAAE,KAAM,CAAE,IAAK,EAAG,IAAK,EAAG,OAAM,CAAE,KAAM,UAAW,CAAC,CAElG,CAAC,EAAO,MAAO,CAAC,GAAG,EAAM,CAE7B,IAAM,EAAa,EAAM,aAAa,CAEtC,OAAO,EAAM,OAAQ,GAAQ,EAAA,KAAK,EAAe,EAAY,EAAK,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Performs a search on an array of objects, checking all values for a match with the search string.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* const data = [{ name: 'John Doe', age: 25 }, { name: 'Jane Doe', age: 30 }];
|
|
7
|
+
* search(data, 'doe', 0.5); // [{ name: 'John Doe', age: 25 }, { name: 'Jane Doe', age: 30 }]
|
|
8
|
+
* ```
|
|
9
|
+
*
|
|
10
|
+
* @param array - The array of objects to search.
|
|
11
|
+
* @param query - The string to search for.
|
|
12
|
+
* @param [tone=0.25] - Degree of similarity between 0 and 1.
|
|
13
|
+
*
|
|
14
|
+
* @returns The filtered array of objects that match the search string.
|
|
15
|
+
*
|
|
16
|
+
* @throws {Error} If input values are invalid.
|
|
17
|
+
*/
|
|
18
|
+
export declare function search<T>(array: T[], query: string, tone?: number): T[];
|
|
19
|
+
//# sourceMappingURL=search.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../src/array/search.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,SAAO,GAAG,CAAC,EAAE,CASrE"}
|
package/dist/array/search.js
CHANGED
|
@@ -1,14 +1,24 @@
|
|
|
1
|
-
import { assert as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
function
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { assert as e } from "../function/assert.js";
|
|
2
|
+
import { IS_STRING_ERROR_MSG as t, isString as n } from "../typed/isString.js";
|
|
3
|
+
import { IS_WITHIN_ERROR_MSG as r, isWithin as i } from "../typed/isWithin.js";
|
|
4
|
+
import { seek as a } from "../object/seek.js";
|
|
5
|
+
//#region src/array/search.ts
|
|
6
|
+
function o(o, s, c = .25) {
|
|
7
|
+
if (e(n(s), t, {
|
|
8
|
+
args: { query: s },
|
|
9
|
+
type: TypeError
|
|
10
|
+
}), e(i(c, 0, 1), r, {
|
|
11
|
+
args: {
|
|
12
|
+
max: 1,
|
|
13
|
+
min: 0,
|
|
14
|
+
tone: c
|
|
15
|
+
},
|
|
16
|
+
type: TypeError
|
|
17
|
+
}), !s) return [...o];
|
|
18
|
+
let l = s.toLowerCase();
|
|
19
|
+
return o.filter((e) => a(e, l, c));
|
|
10
20
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
//# sourceMappingURL=search.js.map
|
|
21
|
+
//#endregion
|
|
22
|
+
export { o as search };
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=search.js.map
|
package/dist/array/search.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search.js","sources":["../../src/array/search.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { seek } from '../object/seek';\nimport { IS_STRING_ERROR_MSG, isString } from '../typed/isString';\nimport { IS_WITHIN_ERROR_MSG, isWithin } from '../typed/isWithin';\
|
|
1
|
+
{"version":3,"file":"search.js","names":[],"sources":["../../src/array/search.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { seek } from '../object/seek';\nimport { IS_STRING_ERROR_MSG, isString } from '../typed/isString';\nimport { IS_WITHIN_ERROR_MSG, isWithin } from '../typed/isWithin';\n\n/**\n * Performs a search on an array of objects, checking all values for a match with the search string.\n *\n * @example\n * ```ts\n * const data = [{ name: 'John Doe', age: 25 }, { name: 'Jane Doe', age: 30 }];\n * search(data, 'doe', 0.5); // [{ name: 'John Doe', age: 25 }, { name: 'Jane Doe', age: 30 }]\n * ```\n *\n * @param array - The array of objects to search.\n * @param query - The string to search for.\n * @param [tone=0.25] - Degree of similarity between 0 and 1.\n *\n * @returns The filtered array of objects that match the search string.\n *\n * @throws {Error} If input values are invalid.\n */\nexport function search<T>(array: T[], query: string, tone = 0.25): T[] {\n assert(isString(query), IS_STRING_ERROR_MSG, { args: { query }, type: TypeError });\n assert(isWithin(tone, 0, 1), IS_WITHIN_ERROR_MSG, { args: { max: 1, min: 0, tone }, type: TypeError });\n\n if (!query) return [...array];\n\n const searchTerm = query.toLowerCase();\n\n return array.filter((obj) => seek(obj as object, searchTerm, tone));\n}\n"],"mappings":";;;;;AAsBA,SAAgB,EAAU,GAAY,GAAe,IAAO,KAAW;AAIrE,KAHA,EAAO,EAAS,EAAM,EAAE,GAAqB;EAAE,MAAM,EAAE,UAAO;EAAE,MAAM;EAAW,CAAC,EAClF,EAAO,EAAS,GAAM,GAAG,EAAE,EAAE,GAAqB;EAAE,MAAM;GAAE,KAAK;GAAG,KAAK;GAAG;GAAM;EAAE,MAAM;EAAW,CAAC,EAElG,CAAC,EAAO,QAAO,CAAC,GAAG,EAAM;CAE7B,IAAM,IAAa,EAAM,aAAa;AAEtC,QAAO,EAAM,QAAQ,MAAQ,EAAK,GAAe,GAAY,EAAK,CAAC"}
|
package/dist/array/select.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=select.cjs.map
|
|
1
|
+
const e=require(`../function/assert.cjs`),t=require(`../typed/isArray.cjs`),n=require(`../typed/isNil.cjs`);function r(r,i,a){e.assert(t.isArray(r),t.IS_ARRAY_ERROR_MSG,{args:{array:r},type:TypeError});let o=a??(e=>!n.isNil(e)),s=[];for(let e=0;e<r.length;e++)o(r[e],e,r)&&s.push(i(r[e],e,r));return s}exports.select=r;
|
|
2
|
+
//# sourceMappingURL=select.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"select.cjs","sources":["../../src/array/select.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"select.cjs","names":[],"sources":["../../src/array/select.ts"],"sourcesContent":["import type { Predicate } from '../types';\n\nimport { assert } from '../function/assert';\nimport { IS_ARRAY_ERROR_MSG, isArray } from '../typed/isArray';\nimport { isNil } from '../typed/isNil';\n\n/**\n * Selects elements from an array based on a callback function and an optional predicate function.\n *\n * @example\n * ```ts\n * const arr = [1, 2, 3, 4];\n * select(arr, x => x * x, x => x > 2) // [9, 16]\n * select(arr, x => x * x) // [1, 4, 9, 16]\n * ```\n *\n * @param array - The array to select from.\n * @param callback - The function to map the values.\n * @param [predicate] - (optional) The function to filter the values.\n *\n * @returns A new array with the selected values.\n *\n * @throws {TypeError} If the provided array is not an array.\n */\nexport function select<T, R>(\n array: T[],\n callback: (item: T, index: number, array: T[]) => R,\n predicate?: Predicate<T>,\n): R[] {\n assert(isArray(array), IS_ARRAY_ERROR_MSG, { args: { array }, type: TypeError });\n\n const isValid = predicate ?? ((value: T) => !isNil(value));\n const result: R[] = [];\n\n for (let index = 0; index < array.length; index++) {\n if (isValid(array[index], index, array)) {\n result.push(callback(array[index], index, array));\n }\n }\n\n return result;\n}\n"],"mappings":"4GAwBA,SAAgB,EACd,EACA,EACA,EACK,CACL,EAAA,OAAO,EAAA,QAAQ,EAAM,CAAE,EAAA,mBAAoB,CAAE,KAAM,CAAE,QAAO,CAAE,KAAM,UAAW,CAAC,CAEhF,IAAM,EAAU,IAAe,GAAa,CAAC,EAAA,MAAM,EAAM,EACnD,EAAc,EAAE,CAEtB,IAAK,IAAI,EAAQ,EAAG,EAAQ,EAAM,OAAQ,IACpC,EAAQ,EAAM,GAAQ,EAAO,EAAM,EACrC,EAAO,KAAK,EAAS,EAAM,GAAQ,EAAO,EAAM,CAAC,CAIrD,OAAO"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Predicate } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Selects elements from an array based on a callback function and an optional predicate function.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* const arr = [1, 2, 3, 4];
|
|
8
|
+
* select(arr, x => x * x, x => x > 2) // [9, 16]
|
|
9
|
+
* select(arr, x => x * x) // [1, 4, 9, 16]
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* @param array - The array to select from.
|
|
13
|
+
* @param callback - The function to map the values.
|
|
14
|
+
* @param [predicate] - (optional) The function to filter the values.
|
|
15
|
+
*
|
|
16
|
+
* @returns A new array with the selected values.
|
|
17
|
+
*
|
|
18
|
+
* @throws {TypeError} If the provided array is not an array.
|
|
19
|
+
*/
|
|
20
|
+
export declare function select<T, R>(array: T[], callback: (item: T, index: number, array: T[]) => R, predicate?: Predicate<T>): R[];
|
|
21
|
+
//# sourceMappingURL=select.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"select.d.ts","sourceRoot":"","sources":["../../src/array/select.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAM1C;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,CAAC,EACzB,KAAK,EAAE,CAAC,EAAE,EACV,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,CAAC,EACnD,SAAS,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,GACvB,CAAC,EAAE,CAaL"}
|
package/dist/array/select.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import { assert as
|
|
2
|
-
import { IS_ARRAY_ERROR_MSG as
|
|
3
|
-
import { isNil as
|
|
4
|
-
|
|
5
|
-
function
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { assert as e } from "../function/assert.js";
|
|
2
|
+
import { IS_ARRAY_ERROR_MSG as t, isArray as n } from "../typed/isArray.js";
|
|
3
|
+
import { isNil as r } from "../typed/isNil.js";
|
|
4
|
+
//#region src/array/select.ts
|
|
5
|
+
function i(i, a, o) {
|
|
6
|
+
e(n(i), t, {
|
|
7
|
+
args: { array: i },
|
|
8
|
+
type: TypeError
|
|
9
|
+
});
|
|
10
|
+
let s = o ?? ((e) => !r(e)), c = [];
|
|
11
|
+
for (let e = 0; e < i.length; e++) s(i[e], e, i) && c.push(a(i[e], e, i));
|
|
12
|
+
return c;
|
|
11
13
|
}
|
|
12
|
-
|
|
13
|
-
export {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
//# sourceMappingURL=select.js.map
|
|
14
|
+
//#endregion
|
|
15
|
+
export { i as select };
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=select.js.map
|
package/dist/array/select.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"select.js","sources":["../../src/array/select.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"select.js","names":[],"sources":["../../src/array/select.ts"],"sourcesContent":["import type { Predicate } from '../types';\n\nimport { assert } from '../function/assert';\nimport { IS_ARRAY_ERROR_MSG, isArray } from '../typed/isArray';\nimport { isNil } from '../typed/isNil';\n\n/**\n * Selects elements from an array based on a callback function and an optional predicate function.\n *\n * @example\n * ```ts\n * const arr = [1, 2, 3, 4];\n * select(arr, x => x * x, x => x > 2) // [9, 16]\n * select(arr, x => x * x) // [1, 4, 9, 16]\n * ```\n *\n * @param array - The array to select from.\n * @param callback - The function to map the values.\n * @param [predicate] - (optional) The function to filter the values.\n *\n * @returns A new array with the selected values.\n *\n * @throws {TypeError} If the provided array is not an array.\n */\nexport function select<T, R>(\n array: T[],\n callback: (item: T, index: number, array: T[]) => R,\n predicate?: Predicate<T>,\n): R[] {\n assert(isArray(array), IS_ARRAY_ERROR_MSG, { args: { array }, type: TypeError });\n\n const isValid = predicate ?? ((value: T) => !isNil(value));\n const result: R[] = [];\n\n for (let index = 0; index < array.length; index++) {\n if (isValid(array[index], index, array)) {\n result.push(callback(array[index], index, array));\n }\n }\n\n return result;\n}\n"],"mappings":";;;;AAwBA,SAAgB,EACd,GACA,GACA,GACK;AACL,GAAO,EAAQ,EAAM,EAAE,GAAoB;EAAE,MAAM,EAAE,UAAO;EAAE,MAAM;EAAW,CAAC;CAEhF,IAAM,IAAU,OAAe,MAAa,CAAC,EAAM,EAAM,GACnD,IAAc,EAAE;AAEtB,MAAK,IAAI,IAAQ,GAAG,IAAQ,EAAM,QAAQ,IACxC,CAAI,EAAQ,EAAM,IAAQ,GAAO,EAAM,IACrC,EAAO,KAAK,EAAS,EAAM,IAAQ,GAAO,EAAM,CAAC;AAIrD,QAAO"}
|
package/dist/array/sort.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=sort.cjs.map
|
|
1
|
+
const e=require(`../function/assert.cjs`),t=require(`../typed/isArray.cjs`),n=require(`../function/compare.cjs`),r=require(`../function/compareBy.cjs`);function i(i,a,o=`asc`){if(e.assert(t.isArray(i),t.IS_ARRAY_ERROR_MSG,{args:{array:i},type:TypeError}),typeof a==`function`){let e=o===`desc`?-1:1;return[...i].sort((t,r)=>n.compare(a(t),a(r))*e)}return[...i].sort(r.compareBy(a))}exports.sort=i;
|
|
2
|
+
//# sourceMappingURL=sort.cjs.map
|
package/dist/array/sort.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sort.cjs","sources":["../../src/array/sort.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { compare } from '../function/compare';\nimport { IS_ARRAY_ERROR_MSG, isArray } from '../typed/isArray';\n\n/**\n * Sorts an array
|
|
1
|
+
{"version":3,"file":"sort.cjs","names":[],"sources":["../../src/array/sort.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { compare } from '../function/compare';\nimport { compareBy } from '../function/compareBy';\nimport { IS_ARRAY_ERROR_MSG, isArray } from '../typed/isArray';\n\nexport type SortDirection = 'asc' | 'desc';\nexport type SortSelectors<T> = Partial<Record<keyof T, SortDirection>>;\n\n/**\n * Sorts an array by a selector function (single-field) or by a multi-field\n * object of `{ key: 'asc' | 'desc' }` entries.\n *\n * @example\n * ```ts\n * // Single field\n * sort([{ a: 2 }, { a: 1 }], item => item.a); // [{ a:1 }, { a:2 }]\n * sort([{ a: 2 }, { a: 1 }], item => item.a, 'desc'); // [{ a:2 }, { a:1 }]\n *\n * // Multi-field\n * sort(users, { name: 'asc', age: 'desc' });\n * ```\n *\n * @param array - The array to sort.\n * @param selector - A function extracting the sort key, or a multi-field object.\n * @param direction - `'asc'` (default) or `'desc'` — only applies to single-field mode.\n * @returns A new sorted array.\n *\n * @throws {TypeError} If the first argument is not an array.\n */\nexport function sort<T>(array: T[], selector: (item: T) => unknown, direction?: SortDirection): T[];\nexport function sort<T>(array: T[], selectors: SortSelectors<T>): T[];\nexport function sort<T>(\n array: T[],\n selectorOrSelectors: ((item: T) => unknown) | SortSelectors<T>,\n direction: SortDirection = 'asc',\n): T[] {\n assert(isArray(array), IS_ARRAY_ERROR_MSG, { args: { array }, type: TypeError });\n\n if (typeof selectorOrSelectors === 'function') {\n const multiplier = direction === 'desc' ? -1 : 1;\n\n return [...array].sort((a, b) => compare(selectorOrSelectors(a), selectorOrSelectors(b)) * multiplier);\n }\n\n return [...array].sort(compareBy(selectorOrSelectors));\n}\n"],"mappings":"wJA+BA,SAAgB,EACd,EACA,EACA,EAA2B,MACtB,CAGL,GAFA,EAAA,OAAO,EAAA,QAAQ,EAAM,CAAE,EAAA,mBAAoB,CAAE,KAAM,CAAE,QAAO,CAAE,KAAM,UAAW,CAAC,CAE5E,OAAO,GAAwB,WAAY,CAC7C,IAAM,EAAa,IAAc,OAAS,GAAK,EAE/C,MAAO,CAAC,GAAG,EAAM,CAAC,MAAM,EAAG,IAAM,EAAA,QAAQ,EAAoB,EAAE,CAAE,EAAoB,EAAE,CAAC,CAAG,EAAW,CAGxG,MAAO,CAAC,GAAG,EAAM,CAAC,KAAK,EAAA,UAAU,EAAoB,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export type SortDirection = 'asc' | 'desc';
|
|
2
|
+
export type SortSelectors<T> = Partial<Record<keyof T, SortDirection>>;
|
|
3
|
+
/**
|
|
4
|
+
* Sorts an array by a selector function (single-field) or by a multi-field
|
|
5
|
+
* object of `{ key: 'asc' | 'desc' }` entries.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* // Single field
|
|
10
|
+
* sort([{ a: 2 }, { a: 1 }], item => item.a); // [{ a:1 }, { a:2 }]
|
|
11
|
+
* sort([{ a: 2 }, { a: 1 }], item => item.a, 'desc'); // [{ a:2 }, { a:1 }]
|
|
12
|
+
*
|
|
13
|
+
* // Multi-field
|
|
14
|
+
* sort(users, { name: 'asc', age: 'desc' });
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @param array - The array to sort.
|
|
18
|
+
* @param selector - A function extracting the sort key, or a multi-field object.
|
|
19
|
+
* @param direction - `'asc'` (default) or `'desc'` — only applies to single-field mode.
|
|
20
|
+
* @returns A new sorted array.
|
|
21
|
+
*
|
|
22
|
+
* @throws {TypeError} If the first argument is not an array.
|
|
23
|
+
*/
|
|
24
|
+
export declare function sort<T>(array: T[], selector: (item: T) => unknown, direction?: SortDirection): T[];
|
|
25
|
+
export declare function sort<T>(array: T[], selectors: SortSelectors<T>): T[];
|
|
26
|
+
//# sourceMappingURL=sort.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sort.d.ts","sourceRoot":"","sources":["../../src/array/sort.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,MAAM,CAAC;AAC3C,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC;AAEvE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,EAAE,SAAS,CAAC,EAAE,aAAa,GAAG,CAAC,EAAE,CAAC;AACpG,wBAAgB,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC"}
|
package/dist/array/sort.js
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
import { assert as e } from "../function/assert.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
2
|
+
import { IS_ARRAY_ERROR_MSG as t, isArray as n } from "../typed/isArray.js";
|
|
3
|
+
import { compare as r } from "../function/compare.js";
|
|
4
|
+
import { compareBy as i } from "../function/compareBy.js";
|
|
5
|
+
//#region src/array/sort.ts
|
|
6
|
+
function a(a, o, s = "asc") {
|
|
7
|
+
if (e(n(a), t, {
|
|
8
|
+
args: { array: a },
|
|
9
|
+
type: TypeError
|
|
10
|
+
}), typeof o == "function") {
|
|
11
|
+
let e = s === "desc" ? -1 : 1;
|
|
12
|
+
return [...a].sort((t, n) => r(o(t), o(n)) * e);
|
|
13
|
+
}
|
|
14
|
+
return [...a].sort(i(o));
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
export { a as sort };
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=sort.js.map
|
package/dist/array/sort.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sort.js","sources":["../../src/array/sort.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { compare } from '../function/compare';\nimport { IS_ARRAY_ERROR_MSG, isArray } from '../typed/isArray';\n\n/**\n * Sorts an array
|
|
1
|
+
{"version":3,"file":"sort.js","names":[],"sources":["../../src/array/sort.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { compare } from '../function/compare';\nimport { compareBy } from '../function/compareBy';\nimport { IS_ARRAY_ERROR_MSG, isArray } from '../typed/isArray';\n\nexport type SortDirection = 'asc' | 'desc';\nexport type SortSelectors<T> = Partial<Record<keyof T, SortDirection>>;\n\n/**\n * Sorts an array by a selector function (single-field) or by a multi-field\n * object of `{ key: 'asc' | 'desc' }` entries.\n *\n * @example\n * ```ts\n * // Single field\n * sort([{ a: 2 }, { a: 1 }], item => item.a); // [{ a:1 }, { a:2 }]\n * sort([{ a: 2 }, { a: 1 }], item => item.a, 'desc'); // [{ a:2 }, { a:1 }]\n *\n * // Multi-field\n * sort(users, { name: 'asc', age: 'desc' });\n * ```\n *\n * @param array - The array to sort.\n * @param selector - A function extracting the sort key, or a multi-field object.\n * @param direction - `'asc'` (default) or `'desc'` — only applies to single-field mode.\n * @returns A new sorted array.\n *\n * @throws {TypeError} If the first argument is not an array.\n */\nexport function sort<T>(array: T[], selector: (item: T) => unknown, direction?: SortDirection): T[];\nexport function sort<T>(array: T[], selectors: SortSelectors<T>): T[];\nexport function sort<T>(\n array: T[],\n selectorOrSelectors: ((item: T) => unknown) | SortSelectors<T>,\n direction: SortDirection = 'asc',\n): T[] {\n assert(isArray(array), IS_ARRAY_ERROR_MSG, { args: { array }, type: TypeError });\n\n if (typeof selectorOrSelectors === 'function') {\n const multiplier = direction === 'desc' ? -1 : 1;\n\n return [...array].sort((a, b) => compare(selectorOrSelectors(a), selectorOrSelectors(b)) * multiplier);\n }\n\n return [...array].sort(compareBy(selectorOrSelectors));\n}\n"],"mappings":";;;;;AA+BA,SAAgB,EACd,GACA,GACA,IAA2B,OACtB;AAGL,KAFA,EAAO,EAAQ,EAAM,EAAE,GAAoB;EAAE,MAAM,EAAE,UAAO;EAAE,MAAM;EAAW,CAAC,EAE5E,OAAO,KAAwB,YAAY;EAC7C,IAAM,IAAa,MAAc,SAAS,KAAK;AAE/C,SAAO,CAAC,GAAG,EAAM,CAAC,MAAM,GAAG,MAAM,EAAQ,EAAoB,EAAE,EAAE,EAAoB,EAAE,CAAC,GAAG,EAAW;;AAGxG,QAAO,CAAC,GAAG,EAAM,CAAC,KAAK,EAAU,EAAoB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toggle.cjs","names":[],"sources":["../../src/array/toggle.ts"],"sourcesContent":["import type { Primitive } from '../types';\n\n/**\n * Either adds or removes an item from an array, based on whether it already\n * exists in the array (toggle behaviour).\n *\n * @example\n * ```ts\n * toggle([1, 2, 3], 4) // [1, 2, 3, 4]\n * toggle([1, 2, 3], 2) // [1, 3]\n *\n * toggle(\n * [{ id: 1 }, { id: 2 }],\n * { id: 3 },\n * (obj) => obj.id,\n * { strategy: 'prepend' }\n * ) // [{ id: 3 }, { id: 1 }, { id: 2 }]\n * ```\n *\n * @param array - The array to modify.\n * @param item - The item to add or remove.\n * @param selector - A function to determine item identity.\n * @param [options] - Options for the toggle operation.\n * @param [options.strategy] - Where to insert when adding: 'prepend' or 'append' (default).\n * @returns A new array with the item toggled.\n */\nexport function toggle<T>(\n array: T[],\n item: T,\n selector?: (item: T) => Primitive,\n options: { strategy?: 'prepend' | 'append' } = {},\n): T[] {\n const { strategy = 'append' } = options;\n const compareFn = selector ? (el: T) => selector(el) === selector(item) : (el: T) => el === item;\n\n const index = array.findIndex(compareFn);\n\n if (index !== -1) {\n return [...array.slice(0, index), ...array.slice(index + 1)];\n }\n\n return strategy === 'prepend' ? [item, ...array] : [...array, item];\n}\n"],"mappings":"AA0BA,SAAgB,EACd,EACA,EACA,EACA,EAA+C,EAAE,CAC5C,CACL,GAAM,CAAE,WAAW,UAAa,EAC1B,EAAY,EAAY,GAAU,EAAS,EAAG,GAAK,EAAS,EAAK,CAAI,GAAU,IAAO,EAEtF,EAAQ,EAAM,UAAU,EAAU,CAMxC,OAJI,IAAU,GAIP,IAAa,UAAY,CAAC,EAAM,GAAG,EAAM,CAAG,CAAC,GAAG,EAAO,EAAK,CAH1D,CAAC,GAAG,EAAM,MAAM,EAAG,EAAM,CAAE,GAAG,EAAM,MAAM,EAAQ,EAAE,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Primitive } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Either adds or removes an item from an array, based on whether it already
|
|
4
|
+
* exists in the array (toggle behaviour).
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* toggle([1, 2, 3], 4) // [1, 2, 3, 4]
|
|
9
|
+
* toggle([1, 2, 3], 2) // [1, 3]
|
|
10
|
+
*
|
|
11
|
+
* toggle(
|
|
12
|
+
* [{ id: 1 }, { id: 2 }],
|
|
13
|
+
* { id: 3 },
|
|
14
|
+
* (obj) => obj.id,
|
|
15
|
+
* { strategy: 'prepend' }
|
|
16
|
+
* ) // [{ id: 3 }, { id: 1 }, { id: 2 }]
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @param array - The array to modify.
|
|
20
|
+
* @param item - The item to add or remove.
|
|
21
|
+
* @param selector - A function to determine item identity.
|
|
22
|
+
* @param [options] - Options for the toggle operation.
|
|
23
|
+
* @param [options.strategy] - Where to insert when adding: 'prepend' or 'append' (default).
|
|
24
|
+
* @returns A new array with the item toggled.
|
|
25
|
+
*/
|
|
26
|
+
export declare function toggle<T>(array: T[], item: T, selector?: (item: T) => Primitive, options?: {
|
|
27
|
+
strategy?: 'prepend' | 'append';
|
|
28
|
+
}): T[];
|
|
29
|
+
//# sourceMappingURL=toggle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toggle.d.ts","sourceRoot":"","sources":["../../src/array/toggle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE1C;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,MAAM,CAAC,CAAC,EACtB,KAAK,EAAE,CAAC,EAAE,EACV,IAAI,EAAE,CAAC,EACP,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,SAAS,EACjC,OAAO,GAAE;IAAE,QAAQ,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAA;CAAO,GAChD,CAAC,EAAE,CAWL"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/array/toggle.ts
|
|
2
|
+
function e(e, t, n, r = {}) {
|
|
3
|
+
let { strategy: i = "append" } = r, a = n ? (e) => n(e) === n(t) : (e) => e === t, o = e.findIndex(a);
|
|
4
|
+
return o === -1 ? i === "prepend" ? [t, ...e] : [...e, t] : [...e.slice(0, o), ...e.slice(o + 1)];
|
|
5
|
+
}
|
|
6
|
+
//#endregion
|
|
7
|
+
export { e as toggle };
|
|
8
|
+
|
|
9
|
+
//# sourceMappingURL=toggle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toggle.js","names":[],"sources":["../../src/array/toggle.ts"],"sourcesContent":["import type { Primitive } from '../types';\n\n/**\n * Either adds or removes an item from an array, based on whether it already\n * exists in the array (toggle behaviour).\n *\n * @example\n * ```ts\n * toggle([1, 2, 3], 4) // [1, 2, 3, 4]\n * toggle([1, 2, 3], 2) // [1, 3]\n *\n * toggle(\n * [{ id: 1 }, { id: 2 }],\n * { id: 3 },\n * (obj) => obj.id,\n * { strategy: 'prepend' }\n * ) // [{ id: 3 }, { id: 1 }, { id: 2 }]\n * ```\n *\n * @param array - The array to modify.\n * @param item - The item to add or remove.\n * @param selector - A function to determine item identity.\n * @param [options] - Options for the toggle operation.\n * @param [options.strategy] - Where to insert when adding: 'prepend' or 'append' (default).\n * @returns A new array with the item toggled.\n */\nexport function toggle<T>(\n array: T[],\n item: T,\n selector?: (item: T) => Primitive,\n options: { strategy?: 'prepend' | 'append' } = {},\n): T[] {\n const { strategy = 'append' } = options;\n const compareFn = selector ? (el: T) => selector(el) === selector(item) : (el: T) => el === item;\n\n const index = array.findIndex(compareFn);\n\n if (index !== -1) {\n return [...array.slice(0, index), ...array.slice(index + 1)];\n }\n\n return strategy === 'prepend' ? [item, ...array] : [...array, item];\n}\n"],"mappings":";AA0BA,SAAgB,EACd,GACA,GACA,GACA,IAA+C,EAAE,EAC5C;CACL,IAAM,EAAE,cAAW,aAAa,GAC1B,IAAY,KAAY,MAAU,EAAS,EAAG,KAAK,EAAS,EAAK,IAAI,MAAU,MAAO,GAEtF,IAAQ,EAAM,UAAU,EAAU;AAMxC,QAJI,MAAU,KAIP,MAAa,YAAY,CAAC,GAAM,GAAG,EAAM,GAAG,CAAC,GAAG,GAAO,EAAK,GAH1D,CAAC,GAAG,EAAM,MAAM,GAAG,EAAM,EAAE,GAAG,EAAM,MAAM,IAAQ,EAAE,CAAC"}
|
package/dist/array/uniq.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=uniq.cjs.map
|
|
1
|
+
const e=require(`../function/assert.cjs`),t=require(`../typed/isArray.cjs`);function n(n,r){if(e.assert(t.isArray(n),t.IS_ARRAY_ERROR_MSG,{type:TypeError}),n.length<=1)return[...n];if(!r)return[...new Set(n)];let i=new Set,a=typeof r==`function`?r:e=>e[r];return n.filter(e=>{let t=a(e);return i.has(t)?!1:(i.add(t),!0)})}exports.uniq=n;
|
|
2
|
+
//# sourceMappingURL=uniq.cjs.map
|
package/dist/array/uniq.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uniq.cjs","sources":["../../src/array/uniq.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"uniq.cjs","names":[],"sources":["../../src/array/uniq.ts"],"sourcesContent":["import type { Primitive, Selector } from '../types';\n\nimport { assert } from '../function/assert';\nimport { IS_ARRAY_ERROR_MSG, isArray } from '../typed/isArray';\n\n/**\n * Creates a new array with duplicate values removed.\n *\n * @example\n * ```ts\n * uniq([1, 2, 2, 3, 3, 3]); // [1, 2, 3]\n * const arrObj = [{ id: 1 }, { id: 2 }, { id: 2 }, { id: 3 }, { id: 3 }, { id: 3 }];\n * uniq(arrObj, 'id'); // [{ id: 1 }, { id: 2 }, { id: 3 }]\n * uniq(arrObj, item => item.id); // [{ id: 1 }, { id: 2 }, { id: 3 }]\n * ```\n *\n * @param array - The array to process.\n * @param [selector] - The key(s) to compare objects or a function to generate comparison values.\n\n * @returns A new duplicate-free array.\n\n * @throws {TypeError} - If the input is not an array or if the key is invalid.\n */\nexport function uniq<T>(array: T[], selector?: Selector<T>): T[] {\n assert(isArray(array), IS_ARRAY_ERROR_MSG, { type: TypeError });\n\n if (array.length <= 1) {\n return [...array];\n }\n\n if (!selector) {\n return [...new Set(array)];\n }\n\n const seen = new Set<Primitive>();\n const getKey = typeof selector === 'function' ? selector : (item: T) => item[selector];\n\n return array.filter((item) => {\n const key = getKey(item) as Primitive;\n\n if (seen.has(key)) {\n return false;\n }\n\n seen.add(key);\n\n return true;\n });\n}\n"],"mappings":"4EAuBA,SAAgB,EAAQ,EAAY,EAA6B,CAG/D,GAFA,EAAA,OAAO,EAAA,QAAQ,EAAM,CAAE,EAAA,mBAAoB,CAAE,KAAM,UAAW,CAAC,CAE3D,EAAM,QAAU,EAClB,MAAO,CAAC,GAAG,EAAM,CAGnB,GAAI,CAAC,EACH,MAAO,CAAC,GAAG,IAAI,IAAI,EAAM,CAAC,CAG5B,IAAM,EAAO,IAAI,IACX,EAAS,OAAO,GAAa,WAAa,EAAY,GAAY,EAAK,GAE7E,OAAO,EAAM,OAAQ,GAAS,CAC5B,IAAM,EAAM,EAAO,EAAK,CAQxB,OANI,EAAK,IAAI,EAAI,CACR,IAGT,EAAK,IAAI,EAAI,CAEN,KACP"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Selector } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a new array with duplicate values removed.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* uniq([1, 2, 2, 3, 3, 3]); // [1, 2, 3]
|
|
8
|
+
* const arrObj = [{ id: 1 }, { id: 2 }, { id: 2 }, { id: 3 }, { id: 3 }, { id: 3 }];
|
|
9
|
+
* uniq(arrObj, 'id'); // [{ id: 1 }, { id: 2 }, { id: 3 }]
|
|
10
|
+
* uniq(arrObj, item => item.id); // [{ id: 1 }, { id: 2 }, { id: 3 }]
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* @param array - The array to process.
|
|
14
|
+
* @param [selector] - The key(s) to compare objects or a function to generate comparison values.
|
|
15
|
+
|
|
16
|
+
* @returns A new duplicate-free array.
|
|
17
|
+
|
|
18
|
+
* @throws {TypeError} - If the input is not an array or if the key is invalid.
|
|
19
|
+
*/
|
|
20
|
+
export declare function uniq<T>(array: T[], selector?: Selector<T>): T[];
|
|
21
|
+
//# sourceMappingURL=uniq.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uniq.d.ts","sourceRoot":"","sources":["../../src/array/uniq.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAa,QAAQ,EAAE,MAAM,UAAU,CAAC;AAKpD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,QAAQ,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAyB/D"}
|
package/dist/array/uniq.js
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
import { assert as
|
|
2
|
-
import { IS_ARRAY_ERROR_MSG as
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
});
|
|
1
|
+
import { assert as e } from "../function/assert.js";
|
|
2
|
+
import { IS_ARRAY_ERROR_MSG as t, isArray as n } from "../typed/isArray.js";
|
|
3
|
+
//#region src/array/uniq.ts
|
|
4
|
+
function r(r, i) {
|
|
5
|
+
if (e(n(r), t, { type: TypeError }), r.length <= 1) return [...r];
|
|
6
|
+
if (!i) return [...new Set(r)];
|
|
7
|
+
let a = /* @__PURE__ */ new Set(), o = typeof i == "function" ? i : (e) => e[i];
|
|
8
|
+
return r.filter((e) => {
|
|
9
|
+
let t = o(e);
|
|
10
|
+
return a.has(t) ? !1 : (a.add(t), !0);
|
|
11
|
+
});
|
|
13
12
|
}
|
|
14
|
-
|
|
15
|
-
export {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
//# sourceMappingURL=uniq.js.map
|
|
13
|
+
//#endregion
|
|
14
|
+
export { r as uniq };
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=uniq.js.map
|
package/dist/array/uniq.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uniq.js","sources":["../../src/array/uniq.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"uniq.js","names":[],"sources":["../../src/array/uniq.ts"],"sourcesContent":["import type { Primitive, Selector } from '../types';\n\nimport { assert } from '../function/assert';\nimport { IS_ARRAY_ERROR_MSG, isArray } from '../typed/isArray';\n\n/**\n * Creates a new array with duplicate values removed.\n *\n * @example\n * ```ts\n * uniq([1, 2, 2, 3, 3, 3]); // [1, 2, 3]\n * const arrObj = [{ id: 1 }, { id: 2 }, { id: 2 }, { id: 3 }, { id: 3 }, { id: 3 }];\n * uniq(arrObj, 'id'); // [{ id: 1 }, { id: 2 }, { id: 3 }]\n * uniq(arrObj, item => item.id); // [{ id: 1 }, { id: 2 }, { id: 3 }]\n * ```\n *\n * @param array - The array to process.\n * @param [selector] - The key(s) to compare objects or a function to generate comparison values.\n\n * @returns A new duplicate-free array.\n\n * @throws {TypeError} - If the input is not an array or if the key is invalid.\n */\nexport function uniq<T>(array: T[], selector?: Selector<T>): T[] {\n assert(isArray(array), IS_ARRAY_ERROR_MSG, { type: TypeError });\n\n if (array.length <= 1) {\n return [...array];\n }\n\n if (!selector) {\n return [...new Set(array)];\n }\n\n const seen = new Set<Primitive>();\n const getKey = typeof selector === 'function' ? selector : (item: T) => item[selector];\n\n return array.filter((item) => {\n const key = getKey(item) as Primitive;\n\n if (seen.has(key)) {\n return false;\n }\n\n seen.add(key);\n\n return true;\n });\n}\n"],"mappings":";;;AAuBA,SAAgB,EAAQ,GAAY,GAA6B;AAG/D,KAFA,EAAO,EAAQ,EAAM,EAAE,GAAoB,EAAE,MAAM,WAAW,CAAC,EAE3D,EAAM,UAAU,EAClB,QAAO,CAAC,GAAG,EAAM;AAGnB,KAAI,CAAC,EACH,QAAO,CAAC,GAAG,IAAI,IAAI,EAAM,CAAC;CAG5B,IAAM,oBAAO,IAAI,KAAgB,EAC3B,IAAS,OAAO,KAAa,aAAa,KAAY,MAAY,EAAK;AAE7E,QAAO,EAAM,QAAQ,MAAS;EAC5B,IAAM,IAAM,EAAO,EAAK;AAQxB,SANI,EAAK,IAAI,EAAI,GACR,MAGT,EAAK,IAAI,EAAI,EAEN;GACP"}
|