es-toolkit 1.48.1 → 1.49.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/CHANGELOG.md +23 -0
- package/dist/array/chunkBy.d.mts +32 -0
- package/dist/array/chunkBy.d.ts +32 -0
- package/dist/array/chunkBy.js +42 -0
- package/dist/array/chunkBy.mjs +42 -0
- package/dist/array/index.d.mts +2 -1
- package/dist/array/index.d.ts +2 -1
- package/dist/array/index.js +2 -0
- package/dist/array/index.mjs +2 -1
- package/dist/array/take.d.mts +1 -7
- package/dist/array/take.d.ts +1 -7
- package/dist/array/take.js +1 -9
- package/dist/array/take.mjs +1 -9
- package/dist/array/takeRight.d.mts +2 -2
- package/dist/array/takeRight.d.ts +2 -2
- package/dist/array/takeRight.js +2 -4
- package/dist/array/takeRight.mjs +2 -4
- package/dist/array/windowed.d.mts +1 -1
- package/dist/array/windowed.d.ts +1 -1
- package/dist/browser.global.js +3 -3
- package/dist/compat/array/chunk.js +4 -2
- package/dist/compat/array/chunk.mjs +4 -2
- package/dist/compat/array/differenceBy.js +5 -5
- package/dist/compat/array/differenceBy.mjs +5 -5
- package/dist/compat/array/drop.d.mts +2 -3
- package/dist/compat/array/drop.d.ts +2 -3
- package/dist/compat/array/drop.js +4 -4
- package/dist/compat/array/drop.mjs +4 -4
- package/dist/compat/array/dropRight.js +1 -1
- package/dist/compat/array/dropRight.mjs +1 -1
- package/dist/compat/array/dropRightWhile.d.mts +1 -1
- package/dist/compat/array/dropRightWhile.d.ts +1 -1
- package/dist/compat/array/dropRightWhile.js +5 -4
- package/dist/compat/array/dropRightWhile.mjs +5 -4
- package/dist/compat/array/dropWhile.d.mts +2 -2
- package/dist/compat/array/dropWhile.d.ts +2 -2
- package/dist/compat/array/dropWhile.js +4 -4
- package/dist/compat/array/dropWhile.mjs +4 -4
- package/dist/compat/array/findLast.js +1 -1
- package/dist/compat/array/findLast.mjs +1 -1
- package/dist/compat/array/includes.js +1 -1
- package/dist/compat/array/includes.mjs +1 -1
- package/dist/compat/array/nth.js +1 -1
- package/dist/compat/array/nth.mjs +1 -1
- package/dist/compat/array/slice.js +1 -1
- package/dist/compat/array/slice.mjs +1 -1
- package/dist/compat/array/sortedIndexBy.js +1 -1
- package/dist/compat/array/sortedIndexBy.mjs +1 -1
- package/dist/compat/array/take.js +2 -2
- package/dist/compat/array/take.mjs +2 -2
- package/dist/compat/array/takeRight.js +1 -1
- package/dist/compat/array/takeRight.mjs +1 -1
- package/dist/compat/compat.js +4 -4
- package/dist/compat/compat.mjs +4 -4
- package/dist/compat/index.js +4 -4
- package/dist/compat/index.mjs +4 -4
- package/dist/compat/math/add.js +1 -1
- package/dist/compat/math/add.mjs +1 -1
- package/dist/compat/math/divide.js +1 -1
- package/dist/compat/math/divide.mjs +1 -1
- package/dist/compat/math/multiply.js +1 -1
- package/dist/compat/math/multiply.mjs +1 -1
- package/dist/compat/math/random.js +3 -1
- package/dist/compat/math/random.mjs +3 -1
- package/dist/compat/math/subtract.js +1 -1
- package/dist/compat/math/subtract.mjs +1 -1
- package/dist/compat/object/get.js +1 -1
- package/dist/compat/object/get.mjs +1 -1
- package/dist/compat/object/omitBy.js +1 -1
- package/dist/compat/object/omitBy.mjs +1 -1
- package/dist/compat/object/pick.js +1 -1
- package/dist/compat/object/pick.mjs +1 -1
- package/dist/compat/object/pickBy.js +1 -1
- package/dist/compat/object/pickBy.mjs +1 -1
- package/dist/compat/string/repeat.js +1 -1
- package/dist/compat/string/repeat.mjs +1 -1
- package/dist/fp/_internal/lazy.js +58 -0
- package/dist/fp/_internal/lazy.mjs +57 -0
- package/dist/fp/array/at.d.mts +20 -0
- package/dist/fp/array/at.d.ts +20 -0
- package/dist/fp/array/at.js +25 -0
- package/dist/fp/array/at.mjs +25 -0
- package/dist/fp/array/cartesianProduct.d.mts +61 -0
- package/dist/fp/array/cartesianProduct.d.ts +61 -0
- package/dist/fp/array/cartesianProduct.js +9 -0
- package/dist/fp/array/cartesianProduct.mjs +9 -0
- package/dist/fp/array/chunk.d.mts +19 -0
- package/dist/fp/array/chunk.d.ts +19 -0
- package/dist/fp/array/chunk.js +24 -0
- package/dist/fp/array/chunk.mjs +24 -0
- package/dist/fp/array/chunkBy.d.mts +20 -0
- package/dist/fp/array/chunkBy.d.ts +20 -0
- package/dist/fp/array/chunkBy.js +25 -0
- package/dist/fp/array/chunkBy.mjs +25 -0
- package/dist/fp/array/combinations.d.mts +21 -0
- package/dist/fp/array/combinations.d.ts +21 -0
- package/dist/fp/array/combinations.js +26 -0
- package/dist/fp/array/combinations.mjs +26 -0
- package/dist/fp/array/compact.d.mts +22 -0
- package/dist/fp/array/compact.d.ts +22 -0
- package/dist/fp/array/compact.js +31 -0
- package/dist/fp/array/compact.mjs +30 -0
- package/dist/fp/array/countBy.d.mts +21 -0
- package/dist/fp/array/countBy.d.ts +21 -0
- package/dist/fp/array/countBy.js +26 -0
- package/dist/fp/array/countBy.mjs +26 -0
- package/dist/fp/array/difference.d.mts +21 -0
- package/dist/fp/array/difference.d.ts +21 -0
- package/dist/fp/array/difference.js +32 -0
- package/dist/fp/array/difference.mjs +31 -0
- package/dist/fp/array/differenceBy.d.mts +22 -0
- package/dist/fp/array/differenceBy.d.ts +22 -0
- package/dist/fp/array/differenceBy.js +33 -0
- package/dist/fp/array/differenceBy.mjs +32 -0
- package/dist/fp/array/differenceWith.d.mts +22 -0
- package/dist/fp/array/differenceWith.d.ts +22 -0
- package/dist/fp/array/differenceWith.js +32 -0
- package/dist/fp/array/differenceWith.mjs +31 -0
- package/dist/fp/array/drop.d.mts +20 -0
- package/dist/fp/array/drop.d.ts +20 -0
- package/dist/fp/array/drop.js +31 -0
- package/dist/fp/array/drop.mjs +30 -0
- package/dist/fp/array/dropRight.d.mts +20 -0
- package/dist/fp/array/dropRight.d.ts +20 -0
- package/dist/fp/array/dropRight.js +25 -0
- package/dist/fp/array/dropRight.mjs +25 -0
- package/dist/fp/array/dropRightWhile.d.mts +20 -0
- package/dist/fp/array/dropRightWhile.d.ts +20 -0
- package/dist/fp/array/dropRightWhile.js +25 -0
- package/dist/fp/array/dropRightWhile.mjs +25 -0
- package/dist/fp/array/dropWhile.d.mts +20 -0
- package/dist/fp/array/dropWhile.d.ts +20 -0
- package/dist/fp/array/dropWhile.js +36 -0
- package/dist/fp/array/dropWhile.mjs +36 -0
- package/dist/fp/array/filter.d.mts +45 -0
- package/dist/fp/array/filter.d.ts +45 -0
- package/dist/fp/array/filter.js +13 -0
- package/dist/fp/array/filter.mjs +12 -0
- package/dist/fp/array/find.d.mts +39 -0
- package/dist/fp/array/find.d.ts +39 -0
- package/dist/fp/array/find.js +8 -0
- package/dist/fp/array/find.mjs +8 -0
- package/dist/fp/array/findIndex.d.mts +20 -0
- package/dist/fp/array/findIndex.d.ts +20 -0
- package/dist/fp/array/findIndex.js +24 -0
- package/dist/fp/array/findIndex.mjs +24 -0
- package/dist/fp/array/findLast.d.mts +39 -0
- package/dist/fp/array/findLast.d.ts +39 -0
- package/dist/fp/array/findLast.js +11 -0
- package/dist/fp/array/findLast.mjs +11 -0
- package/dist/fp/array/findLastIndex.d.mts +20 -0
- package/dist/fp/array/findLastIndex.d.ts +20 -0
- package/dist/fp/array/findLastIndex.js +25 -0
- package/dist/fp/array/findLastIndex.mjs +25 -0
- package/dist/fp/array/flatMap.d.mts +28 -0
- package/dist/fp/array/flatMap.d.ts +28 -0
- package/dist/fp/array/flatMap.js +39 -0
- package/dist/fp/array/flatMap.mjs +38 -0
- package/dist/fp/array/flatMapDeep.d.mts +23 -0
- package/dist/fp/array/flatMapDeep.d.ts +23 -0
- package/dist/fp/array/flatMapDeep.js +38 -0
- package/dist/fp/array/flatMapDeep.mjs +37 -0
- package/dist/fp/array/flatten.d.mts +21 -0
- package/dist/fp/array/flatten.d.ts +21 -0
- package/dist/fp/array/flatten.js +39 -0
- package/dist/fp/array/flatten.mjs +38 -0
- package/dist/fp/array/flattenDeep.d.mts +21 -0
- package/dist/fp/array/flattenDeep.d.ts +21 -0
- package/dist/fp/array/flattenDeep.js +36 -0
- package/dist/fp/array/flattenDeep.mjs +35 -0
- package/dist/fp/array/forEach.d.mts +22 -0
- package/dist/fp/array/forEach.d.ts +22 -0
- package/dist/fp/array/forEach.js +33 -0
- package/dist/fp/array/forEach.mjs +32 -0
- package/dist/fp/array/groupBy.d.mts +21 -0
- package/dist/fp/array/groupBy.d.ts +21 -0
- package/dist/fp/array/groupBy.js +26 -0
- package/dist/fp/array/groupBy.mjs +26 -0
- package/dist/fp/array/head.d.mts +35 -0
- package/dist/fp/array/head.d.ts +35 -0
- package/dist/fp/array/head.js +9 -0
- package/dist/fp/array/head.mjs +9 -0
- package/dist/fp/array/index.d.mts +69 -0
- package/dist/fp/array/index.d.ts +69 -0
- package/dist/fp/array/index.js +68 -0
- package/dist/fp/array/index.mjs +68 -0
- package/dist/fp/array/initial.d.mts +19 -0
- package/dist/fp/array/initial.d.ts +19 -0
- package/dist/fp/array/initial.js +24 -0
- package/dist/fp/array/initial.mjs +24 -0
- package/dist/fp/array/intersection.d.mts +21 -0
- package/dist/fp/array/intersection.d.ts +21 -0
- package/dist/fp/array/intersection.js +32 -0
- package/dist/fp/array/intersection.mjs +31 -0
- package/dist/fp/array/intersectionBy.d.mts +22 -0
- package/dist/fp/array/intersectionBy.d.ts +22 -0
- package/dist/fp/array/intersectionBy.js +33 -0
- package/dist/fp/array/intersectionBy.mjs +32 -0
- package/dist/fp/array/intersectionWith.d.mts +22 -0
- package/dist/fp/array/intersectionWith.d.ts +22 -0
- package/dist/fp/array/intersectionWith.js +32 -0
- package/dist/fp/array/intersectionWith.mjs +31 -0
- package/dist/fp/array/isSubset.d.mts +20 -0
- package/dist/fp/array/isSubset.d.ts +20 -0
- package/dist/fp/array/isSubset.js +25 -0
- package/dist/fp/array/isSubset.mjs +25 -0
- package/dist/fp/array/isSubsetWith.d.mts +21 -0
- package/dist/fp/array/isSubsetWith.d.ts +21 -0
- package/dist/fp/array/isSubsetWith.js +26 -0
- package/dist/fp/array/isSubsetWith.mjs +26 -0
- package/dist/fp/array/join.d.mts +20 -0
- package/dist/fp/array/join.d.ts +20 -0
- package/dist/fp/array/join.js +24 -0
- package/dist/fp/array/join.mjs +24 -0
- package/dist/fp/array/keyBy.d.mts +21 -0
- package/dist/fp/array/keyBy.d.ts +21 -0
- package/dist/fp/array/keyBy.js +26 -0
- package/dist/fp/array/keyBy.mjs +26 -0
- package/dist/fp/array/last.d.mts +35 -0
- package/dist/fp/array/last.d.ts +35 -0
- package/dist/fp/array/last.js +9 -0
- package/dist/fp/array/last.mjs +9 -0
- package/dist/fp/array/length.d.mts +18 -0
- package/dist/fp/array/length.d.ts +18 -0
- package/dist/fp/array/length.js +22 -0
- package/dist/fp/array/length.mjs +22 -0
- package/dist/fp/array/map.d.mts +27 -0
- package/dist/fp/array/map.d.ts +27 -0
- package/dist/fp/array/map.js +36 -0
- package/dist/fp/array/map.mjs +35 -0
- package/dist/fp/array/maxBy.d.mts +37 -0
- package/dist/fp/array/maxBy.d.ts +37 -0
- package/dist/fp/array/maxBy.js +9 -0
- package/dist/fp/array/maxBy.mjs +9 -0
- package/dist/fp/array/minBy.d.mts +37 -0
- package/dist/fp/array/minBy.d.ts +37 -0
- package/dist/fp/array/minBy.js +9 -0
- package/dist/fp/array/minBy.mjs +9 -0
- package/dist/fp/array/orderBy.d.mts +21 -0
- package/dist/fp/array/orderBy.d.ts +21 -0
- package/dist/fp/array/orderBy.js +26 -0
- package/dist/fp/array/orderBy.mjs +26 -0
- package/dist/fp/array/partition.d.mts +39 -0
- package/dist/fp/array/partition.d.ts +39 -0
- package/dist/fp/array/partition.js +9 -0
- package/dist/fp/array/partition.mjs +9 -0
- package/dist/fp/array/reverse.d.mts +19 -0
- package/dist/fp/array/reverse.d.ts +19 -0
- package/dist/fp/array/reverse.js +23 -0
- package/dist/fp/array/reverse.mjs +23 -0
- package/dist/fp/array/sample.d.mts +18 -0
- package/dist/fp/array/sample.d.ts +18 -0
- package/dist/fp/array/sample.js +23 -0
- package/dist/fp/array/sample.mjs +23 -0
- package/dist/fp/array/sampleSize.d.mts +20 -0
- package/dist/fp/array/sampleSize.d.ts +20 -0
- package/dist/fp/array/sampleSize.js +25 -0
- package/dist/fp/array/sampleSize.mjs +25 -0
- package/dist/fp/array/shuffle.d.mts +19 -0
- package/dist/fp/array/shuffle.d.ts +19 -0
- package/dist/fp/array/shuffle.js +24 -0
- package/dist/fp/array/shuffle.mjs +24 -0
- package/dist/fp/array/sortBy.d.mts +26 -0
- package/dist/fp/array/sortBy.d.ts +26 -0
- package/dist/fp/array/sortBy.js +31 -0
- package/dist/fp/array/sortBy.mjs +31 -0
- package/dist/fp/array/tail.d.mts +19 -0
- package/dist/fp/array/tail.d.ts +19 -0
- package/dist/fp/array/tail.js +24 -0
- package/dist/fp/array/tail.mjs +24 -0
- package/dist/fp/array/take.d.mts +26 -0
- package/dist/fp/array/take.d.ts +26 -0
- package/dist/fp/array/take.js +39 -0
- package/dist/fp/array/take.mjs +38 -0
- package/dist/fp/array/takeRight.d.mts +20 -0
- package/dist/fp/array/takeRight.d.ts +20 -0
- package/dist/fp/array/takeRight.js +25 -0
- package/dist/fp/array/takeRight.mjs +25 -0
- package/dist/fp/array/takeRightWhile.d.mts +20 -0
- package/dist/fp/array/takeRightWhile.d.ts +20 -0
- package/dist/fp/array/takeRightWhile.js +25 -0
- package/dist/fp/array/takeRightWhile.mjs +25 -0
- package/dist/fp/array/takeWhile.d.mts +21 -0
- package/dist/fp/array/takeWhile.d.ts +21 -0
- package/dist/fp/array/takeWhile.js +32 -0
- package/dist/fp/array/takeWhile.mjs +31 -0
- package/dist/fp/array/toFilled.d.mts +23 -0
- package/dist/fp/array/toFilled.d.ts +23 -0
- package/dist/fp/array/toFilled.js +30 -0
- package/dist/fp/array/toFilled.mjs +30 -0
- package/dist/fp/array/union.d.mts +20 -0
- package/dist/fp/array/union.d.ts +20 -0
- package/dist/fp/array/union.js +25 -0
- package/dist/fp/array/union.mjs +25 -0
- package/dist/fp/array/unionBy.d.mts +22 -0
- package/dist/fp/array/unionBy.d.ts +22 -0
- package/dist/fp/array/unionBy.js +27 -0
- package/dist/fp/array/unionBy.mjs +27 -0
- package/dist/fp/array/unionWith.d.mts +21 -0
- package/dist/fp/array/unionWith.d.ts +21 -0
- package/dist/fp/array/unionWith.js +26 -0
- package/dist/fp/array/unionWith.mjs +26 -0
- package/dist/fp/array/uniq.d.mts +21 -0
- package/dist/fp/array/uniq.d.ts +21 -0
- package/dist/fp/array/uniq.js +36 -0
- package/dist/fp/array/uniq.mjs +36 -0
- package/dist/fp/array/uniqBy.d.mts +21 -0
- package/dist/fp/array/uniqBy.d.ts +21 -0
- package/dist/fp/array/uniqBy.js +38 -0
- package/dist/fp/array/uniqBy.mjs +38 -0
- package/dist/fp/array/uniqWith.d.mts +20 -0
- package/dist/fp/array/uniqWith.d.ts +20 -0
- package/dist/fp/array/uniqWith.js +35 -0
- package/dist/fp/array/uniqWith.mjs +35 -0
- package/dist/fp/array/unzip.d.mts +20 -0
- package/dist/fp/array/unzip.d.ts +20 -0
- package/dist/fp/array/unzip.js +24 -0
- package/dist/fp/array/unzip.mjs +24 -0
- package/dist/fp/array/unzipWith.d.mts +21 -0
- package/dist/fp/array/unzipWith.d.ts +21 -0
- package/dist/fp/array/unzipWith.js +26 -0
- package/dist/fp/array/unzipWith.mjs +26 -0
- package/dist/fp/array/windowed.d.mts +25 -0
- package/dist/fp/array/windowed.d.ts +25 -0
- package/dist/fp/array/windowed.js +50 -0
- package/dist/fp/array/windowed.mjs +50 -0
- package/dist/fp/array/without.d.mts +19 -0
- package/dist/fp/array/without.d.ts +19 -0
- package/dist/fp/array/without.js +30 -0
- package/dist/fp/array/without.mjs +29 -0
- package/dist/fp/array/xor.d.mts +20 -0
- package/dist/fp/array/xor.d.ts +20 -0
- package/dist/fp/array/xor.js +25 -0
- package/dist/fp/array/xor.mjs +25 -0
- package/dist/fp/array/xorBy.d.mts +22 -0
- package/dist/fp/array/xorBy.d.ts +22 -0
- package/dist/fp/array/xorBy.js +27 -0
- package/dist/fp/array/xorBy.mjs +27 -0
- package/dist/fp/array/xorWith.d.mts +21 -0
- package/dist/fp/array/xorWith.d.ts +21 -0
- package/dist/fp/array/xorWith.js +26 -0
- package/dist/fp/array/xorWith.mjs +26 -0
- package/dist/fp/array/zip.d.mts +61 -0
- package/dist/fp/array/zip.d.ts +61 -0
- package/dist/fp/array/zip.js +9 -0
- package/dist/fp/array/zip.mjs +9 -0
- package/dist/fp/array/zipObject.d.mts +21 -0
- package/dist/fp/array/zipObject.d.ts +21 -0
- package/dist/fp/array/zipObject.js +26 -0
- package/dist/fp/array/zipObject.mjs +26 -0
- package/dist/fp/array/zipWith.d.mts +57 -0
- package/dist/fp/array/zipWith.d.ts +57 -0
- package/dist/fp/array/zipWith.js +9 -0
- package/dist/fp/array/zipWith.mjs +9 -0
- package/dist/fp/index.d.mts +75 -0
- package/dist/fp/index.d.ts +75 -0
- package/dist/fp/index.js +150 -0
- package/dist/fp/index.mjs +77 -0
- package/dist/fp/math/add.d.mts +17 -0
- package/dist/fp/math/add.d.ts +17 -0
- package/dist/fp/math/add.js +21 -0
- package/dist/fp/math/add.mjs +21 -0
- package/dist/fp/math/index.d.mts +2 -0
- package/dist/fp/math/index.d.ts +2 -0
- package/dist/fp/math/index.js +2 -0
- package/dist/fp/math/index.mjs +2 -0
- package/dist/fp/math/multiply.d.mts +17 -0
- package/dist/fp/math/multiply.d.ts +17 -0
- package/dist/fp/math/multiply.js +21 -0
- package/dist/fp/math/multiply.mjs +21 -0
- package/dist/fp/object/index.d.mts +2 -0
- package/dist/fp/object/index.d.ts +2 -0
- package/dist/fp/object/index.js +2 -0
- package/dist/fp/object/index.mjs +2 -0
- package/dist/fp/object/omit.d.mts +18 -0
- package/dist/fp/object/omit.d.ts +18 -0
- package/dist/fp/object/omit.js +23 -0
- package/dist/fp/object/omit.mjs +23 -0
- package/dist/fp/object/pick.d.mts +19 -0
- package/dist/fp/object/pick.d.ts +19 -0
- package/dist/fp/object/pick.js +24 -0
- package/dist/fp/object/pick.mjs +24 -0
- package/dist/fp/pipe.d.mts +235 -0
- package/dist/fp/pipe.d.ts +235 -0
- package/dist/fp/pipe.js +116 -0
- package/dist/fp/pipe.mjs +116 -0
- package/dist/index.d.mts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +4 -0
- package/dist/index.mjs +3 -1
- package/dist/predicate/index.d.mts +2 -1
- package/dist/predicate/index.d.ts +2 -1
- package/dist/predicate/index.js +2 -0
- package/dist/predicate/index.mjs +2 -1
- package/dist/predicate/isIterable.d.mts +26 -0
- package/dist/predicate/isIterable.d.ts +26 -0
- package/dist/predicate/isIterable.js +28 -0
- package/dist/predicate/isIterable.mjs +28 -0
- package/dist/string/trimStart.js +1 -0
- package/dist/string/trimStart.mjs +1 -0
- package/fp.d.ts +1 -0
- package/fp.js +1 -0
- package/package.json +22 -1
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region src/fp/array/keyBy.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a function that indexes values by a derived key.
|
|
4
|
+
*
|
|
5
|
+
* The key selector receives each value, index, and full input array. When multiple values
|
|
6
|
+
* produce the same key, the last value wins, matching the main {@link keyBy} behavior.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The type of elements in the array.
|
|
9
|
+
* @template K - The property-key type produced by the selector.
|
|
10
|
+
* @param getKey - Called with each value, index, and array to produce an object key.
|
|
11
|
+
* @returns A function that maps a readonly array to an object keyed by the derived keys.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* import { keyBy, pipe } from 'es-toolkit/fp';
|
|
15
|
+
*
|
|
16
|
+
* pipe([{ id: 'a', value: 1 }, { id: 'b', value: 2 }], keyBy(item => item.id));
|
|
17
|
+
* // => { a: { id: 'a', value: 1 }, b: { id: 'b', value: 2 } }
|
|
18
|
+
*/
|
|
19
|
+
declare function keyBy<T, K extends PropertyKey>(getKey: (item: T, index: number, array: readonly T[]) => K): (array: readonly T[]) => Record<K, T>;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { keyBy };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region src/fp/array/keyBy.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a function that indexes values by a derived key.
|
|
4
|
+
*
|
|
5
|
+
* The key selector receives each value, index, and full input array. When multiple values
|
|
6
|
+
* produce the same key, the last value wins, matching the main {@link keyBy} behavior.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The type of elements in the array.
|
|
9
|
+
* @template K - The property-key type produced by the selector.
|
|
10
|
+
* @param getKey - Called with each value, index, and array to produce an object key.
|
|
11
|
+
* @returns A function that maps a readonly array to an object keyed by the derived keys.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* import { keyBy, pipe } from 'es-toolkit/fp';
|
|
15
|
+
*
|
|
16
|
+
* pipe([{ id: 'a', value: 1 }, { id: 'b', value: 2 }], keyBy(item => item.id));
|
|
17
|
+
* // => { a: { id: 'a', value: 1 }, b: { id: 'b', value: 2 } }
|
|
18
|
+
*/
|
|
19
|
+
declare function keyBy<T, K extends PropertyKey>(getKey: (item: T, index: number, array: readonly T[]) => K): (array: readonly T[]) => Record<K, T>;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { keyBy };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const require_keyBy = require("../../array/keyBy.js");
|
|
2
|
+
//#region src/fp/array/keyBy.ts
|
|
3
|
+
/**
|
|
4
|
+
* Creates a function that indexes values by a derived key.
|
|
5
|
+
*
|
|
6
|
+
* The key selector receives each value, index, and full input array. When multiple values
|
|
7
|
+
* produce the same key, the last value wins, matching the main {@link keyBy} behavior.
|
|
8
|
+
*
|
|
9
|
+
* @template T - The type of elements in the array.
|
|
10
|
+
* @template K - The property-key type produced by the selector.
|
|
11
|
+
* @param getKey - Called with each value, index, and array to produce an object key.
|
|
12
|
+
* @returns A function that maps a readonly array to an object keyed by the derived keys.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* import { keyBy, pipe } from 'es-toolkit/fp';
|
|
16
|
+
*
|
|
17
|
+
* pipe([{ id: 'a', value: 1 }, { id: 'b', value: 2 }], keyBy(item => item.id));
|
|
18
|
+
* // => { a: { id: 'a', value: 1 }, b: { id: 'b', value: 2 } }
|
|
19
|
+
*/
|
|
20
|
+
function keyBy(getKey) {
|
|
21
|
+
return function(array) {
|
|
22
|
+
return require_keyBy.keyBy(array, getKey);
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
exports.keyBy = keyBy;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { keyBy as keyBy$1 } from "../../array/keyBy.mjs";
|
|
2
|
+
//#region src/fp/array/keyBy.ts
|
|
3
|
+
/**
|
|
4
|
+
* Creates a function that indexes values by a derived key.
|
|
5
|
+
*
|
|
6
|
+
* The key selector receives each value, index, and full input array. When multiple values
|
|
7
|
+
* produce the same key, the last value wins, matching the main {@link keyBy} behavior.
|
|
8
|
+
*
|
|
9
|
+
* @template T - The type of elements in the array.
|
|
10
|
+
* @template K - The property-key type produced by the selector.
|
|
11
|
+
* @param getKey - Called with each value, index, and array to produce an object key.
|
|
12
|
+
* @returns A function that maps a readonly array to an object keyed by the derived keys.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* import { keyBy, pipe } from 'es-toolkit/fp';
|
|
16
|
+
*
|
|
17
|
+
* pipe([{ id: 'a', value: 1 }, { id: 'b', value: 2 }], keyBy(item => item.id));
|
|
18
|
+
* // => { a: { id: 'a', value: 1 }, b: { id: 'b', value: 2 } }
|
|
19
|
+
*/
|
|
20
|
+
function keyBy(getKey) {
|
|
21
|
+
return function(array) {
|
|
22
|
+
return keyBy$1(array, getKey);
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
export { keyBy };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
//#region src/fp/array/last.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a function that returns the last element of a non-empty array.
|
|
4
|
+
*
|
|
5
|
+
* This overload preserves the non-empty tuple guarantee: the returned function
|
|
6
|
+
* always returns T when the piped array has at least one element.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The type of elements in the array.
|
|
9
|
+
* @returns A function that maps a non-empty readonly array to its last element.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* import { last, pipe } from 'es-toolkit/fp';
|
|
13
|
+
*
|
|
14
|
+
* pipe([1, 2, 3] as const, last());
|
|
15
|
+
* // => 3
|
|
16
|
+
*/
|
|
17
|
+
declare function last<T>(): (array: readonly [...T[], T]) => T;
|
|
18
|
+
/**
|
|
19
|
+
* Creates a function that returns the last element of an array, or undefined.
|
|
20
|
+
*
|
|
21
|
+
* Empty arrays return undefined, matching the main {@link last} behavior. Use
|
|
22
|
+
* the returned function with {@link pipe}.
|
|
23
|
+
*
|
|
24
|
+
* @template T - The type of elements in the array.
|
|
25
|
+
* @returns A function that maps a readonly array to its last element, or undefined.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* import { last, pipe } from 'es-toolkit/fp';
|
|
29
|
+
*
|
|
30
|
+
* pipe([] as number[], last());
|
|
31
|
+
* // => undefined
|
|
32
|
+
*/
|
|
33
|
+
declare function last<T>(): (array: readonly T[]) => T | undefined;
|
|
34
|
+
//#endregion
|
|
35
|
+
export { last };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
//#region src/fp/array/last.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a function that returns the last element of a non-empty array.
|
|
4
|
+
*
|
|
5
|
+
* This overload preserves the non-empty tuple guarantee: the returned function
|
|
6
|
+
* always returns T when the piped array has at least one element.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The type of elements in the array.
|
|
9
|
+
* @returns A function that maps a non-empty readonly array to its last element.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* import { last, pipe } from 'es-toolkit/fp';
|
|
13
|
+
*
|
|
14
|
+
* pipe([1, 2, 3] as const, last());
|
|
15
|
+
* // => 3
|
|
16
|
+
*/
|
|
17
|
+
declare function last<T>(): (array: readonly [...T[], T]) => T;
|
|
18
|
+
/**
|
|
19
|
+
* Creates a function that returns the last element of an array, or undefined.
|
|
20
|
+
*
|
|
21
|
+
* Empty arrays return undefined, matching the main {@link last} behavior. Use
|
|
22
|
+
* the returned function with {@link pipe}.
|
|
23
|
+
*
|
|
24
|
+
* @template T - The type of elements in the array.
|
|
25
|
+
* @returns A function that maps a readonly array to its last element, or undefined.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* import { last, pipe } from 'es-toolkit/fp';
|
|
29
|
+
*
|
|
30
|
+
* pipe([] as number[], last());
|
|
31
|
+
* // => undefined
|
|
32
|
+
*/
|
|
33
|
+
declare function last<T>(): (array: readonly T[]) => T | undefined;
|
|
34
|
+
//#endregion
|
|
35
|
+
export { last };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/fp/array/length.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a function that returns the length of an array.
|
|
4
|
+
*
|
|
5
|
+
* Use it with {@link pipe} when a pipeline should end with the number of input values.
|
|
6
|
+
*
|
|
7
|
+
* @template T - The type of elements in the array.
|
|
8
|
+
* @returns A function that maps a readonly array to its length.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* import { length, pipe } from 'es-toolkit/fp';
|
|
12
|
+
*
|
|
13
|
+
* pipe(['a', 'b', 'c'], length());
|
|
14
|
+
* // => 3
|
|
15
|
+
*/
|
|
16
|
+
declare function length<T>(): (array: readonly T[]) => number;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { length };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/fp/array/length.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a function that returns the length of an array.
|
|
4
|
+
*
|
|
5
|
+
* Use it with {@link pipe} when a pipeline should end with the number of input values.
|
|
6
|
+
*
|
|
7
|
+
* @template T - The type of elements in the array.
|
|
8
|
+
* @returns A function that maps a readonly array to its length.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* import { length, pipe } from 'es-toolkit/fp';
|
|
12
|
+
*
|
|
13
|
+
* pipe(['a', 'b', 'c'], length());
|
|
14
|
+
* // => 3
|
|
15
|
+
*/
|
|
16
|
+
declare function length<T>(): (array: readonly T[]) => number;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { length };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//#region src/fp/array/length.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a function that returns the length of an array.
|
|
4
|
+
*
|
|
5
|
+
* Use it with {@link pipe} when a pipeline should end with the number of input values.
|
|
6
|
+
*
|
|
7
|
+
* @template T - The type of elements in the array.
|
|
8
|
+
* @returns A function that maps a readonly array to its length.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* import { length, pipe } from 'es-toolkit/fp';
|
|
12
|
+
*
|
|
13
|
+
* pipe(['a', 'b', 'c'], length());
|
|
14
|
+
* // => 3
|
|
15
|
+
*/
|
|
16
|
+
function length() {
|
|
17
|
+
return function(array) {
|
|
18
|
+
return array.length;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
exports.length = length;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//#region src/fp/array/length.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a function that returns the length of an array.
|
|
4
|
+
*
|
|
5
|
+
* Use it with {@link pipe} when a pipeline should end with the number of input values.
|
|
6
|
+
*
|
|
7
|
+
* @template T - The type of elements in the array.
|
|
8
|
+
* @returns A function that maps a readonly array to its length.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* import { length, pipe } from 'es-toolkit/fp';
|
|
12
|
+
*
|
|
13
|
+
* pipe(['a', 'b', 'c'], length());
|
|
14
|
+
* // => 3
|
|
15
|
+
*/
|
|
16
|
+
function length() {
|
|
17
|
+
return function(array) {
|
|
18
|
+
return array.length;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
export { length };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
//#region src/fp/array/map.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a function that builds a new array by calling `callback` on every
|
|
4
|
+
* element, equivalent to `Array.prototype.map`. Use it with {@link pipe}.
|
|
5
|
+
*
|
|
6
|
+
* The returned function is **lazy-capable**: inside a {@link pipe} it is fused
|
|
7
|
+
* with adjacent lazy functions and runs element-by-element, so a trailing
|
|
8
|
+
* `take` can terminate the walk early without mapping the rest of the input.
|
|
9
|
+
*
|
|
10
|
+
* @template T - The type of elements in the input array.
|
|
11
|
+
* @template U - The type of elements in the output array.
|
|
12
|
+
* @param callback - Called with `(value, index)` for each element; its return
|
|
13
|
+
* value becomes the corresponding element of the output array.
|
|
14
|
+
* @returns A function that maps a `readonly T[]` to a new `U[]`.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* import { pipe, map } from 'es-toolkit/fp';
|
|
18
|
+
*
|
|
19
|
+
* pipe([1, 2, 3], map(x => x * 2)); // => [2, 4, 6]
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* // The index is available as the second argument.
|
|
23
|
+
* pipe([10, 20, 30], map((value, index) => value + index)); // => [10, 21, 32]
|
|
24
|
+
*/
|
|
25
|
+
declare function map<T, U>(callback: (value: T, index: number) => U): (array: readonly T[]) => U[];
|
|
26
|
+
//#endregion
|
|
27
|
+
export { map };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
//#region src/fp/array/map.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a function that builds a new array by calling `callback` on every
|
|
4
|
+
* element, equivalent to `Array.prototype.map`. Use it with {@link pipe}.
|
|
5
|
+
*
|
|
6
|
+
* The returned function is **lazy-capable**: inside a {@link pipe} it is fused
|
|
7
|
+
* with adjacent lazy functions and runs element-by-element, so a trailing
|
|
8
|
+
* `take` can terminate the walk early without mapping the rest of the input.
|
|
9
|
+
*
|
|
10
|
+
* @template T - The type of elements in the input array.
|
|
11
|
+
* @template U - The type of elements in the output array.
|
|
12
|
+
* @param callback - Called with `(value, index)` for each element; its return
|
|
13
|
+
* value becomes the corresponding element of the output array.
|
|
14
|
+
* @returns A function that maps a `readonly T[]` to a new `U[]`.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* import { pipe, map } from 'es-toolkit/fp';
|
|
18
|
+
*
|
|
19
|
+
* pipe([1, 2, 3], map(x => x * 2)); // => [2, 4, 6]
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* // The index is available as the second argument.
|
|
23
|
+
* pipe([10, 20, 30], map((value, index) => value + index)); // => [10, 21, 32]
|
|
24
|
+
*/
|
|
25
|
+
declare function map<T, U>(callback: (value: T, index: number) => U): (array: readonly T[]) => U[];
|
|
26
|
+
//#endregion
|
|
27
|
+
export { map };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const require_lazy = require("../_internal/lazy.js");
|
|
2
|
+
//#region src/fp/array/map.ts
|
|
3
|
+
/**
|
|
4
|
+
* Creates a function that builds a new array by calling `callback` on every
|
|
5
|
+
* element, equivalent to `Array.prototype.map`. Use it with {@link pipe}.
|
|
6
|
+
*
|
|
7
|
+
* The returned function is **lazy-capable**: inside a {@link pipe} it is fused
|
|
8
|
+
* with adjacent lazy functions and runs element-by-element, so a trailing
|
|
9
|
+
* `take` can terminate the walk early without mapping the rest of the input.
|
|
10
|
+
*
|
|
11
|
+
* @template T - The type of elements in the input array.
|
|
12
|
+
* @template U - The type of elements in the output array.
|
|
13
|
+
* @param callback - Called with `(value, index)` for each element; its return
|
|
14
|
+
* value becomes the corresponding element of the output array.
|
|
15
|
+
* @returns A function that maps a `readonly T[]` to a new `U[]`.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* import { pipe, map } from 'es-toolkit/fp';
|
|
19
|
+
*
|
|
20
|
+
* pipe([1, 2, 3], map(x => x * 2)); // => [2, 4, 6]
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* // The index is available as the second argument.
|
|
24
|
+
* pipe([10, 20, 30], map((value, index) => value + index)); // => [10, 21, 32]
|
|
25
|
+
*/
|
|
26
|
+
function map(callback) {
|
|
27
|
+
function mapEager(array) {
|
|
28
|
+
return array.map(callback);
|
|
29
|
+
}
|
|
30
|
+
const mapLazy = require_lazy.createLazyFunction((value, index, emit) => {
|
|
31
|
+
emit(callback(value, index));
|
|
32
|
+
});
|
|
33
|
+
return require_lazy.combineEagerAndLazyFunctions(mapEager, mapLazy);
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
exports.map = map;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { combineEagerAndLazyFunctions, createLazyFunction } from "../_internal/lazy.mjs";
|
|
2
|
+
//#region src/fp/array/map.ts
|
|
3
|
+
/**
|
|
4
|
+
* Creates a function that builds a new array by calling `callback` on every
|
|
5
|
+
* element, equivalent to `Array.prototype.map`. Use it with {@link pipe}.
|
|
6
|
+
*
|
|
7
|
+
* The returned function is **lazy-capable**: inside a {@link pipe} it is fused
|
|
8
|
+
* with adjacent lazy functions and runs element-by-element, so a trailing
|
|
9
|
+
* `take` can terminate the walk early without mapping the rest of the input.
|
|
10
|
+
*
|
|
11
|
+
* @template T - The type of elements in the input array.
|
|
12
|
+
* @template U - The type of elements in the output array.
|
|
13
|
+
* @param callback - Called with `(value, index)` for each element; its return
|
|
14
|
+
* value becomes the corresponding element of the output array.
|
|
15
|
+
* @returns A function that maps a `readonly T[]` to a new `U[]`.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* import { pipe, map } from 'es-toolkit/fp';
|
|
19
|
+
*
|
|
20
|
+
* pipe([1, 2, 3], map(x => x * 2)); // => [2, 4, 6]
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* // The index is available as the second argument.
|
|
24
|
+
* pipe([10, 20, 30], map((value, index) => value + index)); // => [10, 21, 32]
|
|
25
|
+
*/
|
|
26
|
+
function map(callback) {
|
|
27
|
+
function mapEager(array) {
|
|
28
|
+
return array.map(callback);
|
|
29
|
+
}
|
|
30
|
+
return combineEagerAndLazyFunctions(mapEager, createLazyFunction((value, index, emit) => {
|
|
31
|
+
emit(callback(value, index));
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
export { map };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
//#region src/fp/array/maxBy.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a function that returns the element with the maximum selected number from a non-empty array.
|
|
4
|
+
*
|
|
5
|
+
* If the selector returns NaN, the element that produced NaN is returned, matching
|
|
6
|
+
* the main {@link maxBy} behavior.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The type of elements in the array.
|
|
9
|
+
* @param getValue - Selects a numeric value from each element, index, and array.
|
|
10
|
+
* @returns A function that maps a non-empty readonly array to the maximum element.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* import { maxBy, pipe } from 'es-toolkit/fp';
|
|
14
|
+
*
|
|
15
|
+
* pipe([{ score: 10 }, { score: 20 }] as const, maxBy(item => item.score));
|
|
16
|
+
* // => { score: 20 }
|
|
17
|
+
*/
|
|
18
|
+
declare function maxBy<T>(getValue: (element: T, index: number, array: readonly T[]) => number): (array: readonly [T, ...T[]]) => T;
|
|
19
|
+
/**
|
|
20
|
+
* Creates a function that returns the element with the maximum selected number.
|
|
21
|
+
*
|
|
22
|
+
* Empty arrays return undefined. If the selector returns NaN, the element that
|
|
23
|
+
* produced NaN is returned, matching the main {@link maxBy} behavior.
|
|
24
|
+
*
|
|
25
|
+
* @template T - The type of elements in the array.
|
|
26
|
+
* @param getValue - Selects a numeric value from each element, index, and array.
|
|
27
|
+
* @returns A function that maps a readonly array to the maximum element, or undefined.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* import { maxBy, pipe } from 'es-toolkit/fp';
|
|
31
|
+
*
|
|
32
|
+
* pipe([] as Array<{ score: number }>, maxBy(item => item.score));
|
|
33
|
+
* // => undefined
|
|
34
|
+
*/
|
|
35
|
+
declare function maxBy<T>(getValue: (element: T, index: number, array: readonly T[]) => number): (array: readonly T[]) => T | undefined;
|
|
36
|
+
//#endregion
|
|
37
|
+
export { maxBy };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
//#region src/fp/array/maxBy.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a function that returns the element with the maximum selected number from a non-empty array.
|
|
4
|
+
*
|
|
5
|
+
* If the selector returns NaN, the element that produced NaN is returned, matching
|
|
6
|
+
* the main {@link maxBy} behavior.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The type of elements in the array.
|
|
9
|
+
* @param getValue - Selects a numeric value from each element, index, and array.
|
|
10
|
+
* @returns A function that maps a non-empty readonly array to the maximum element.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* import { maxBy, pipe } from 'es-toolkit/fp';
|
|
14
|
+
*
|
|
15
|
+
* pipe([{ score: 10 }, { score: 20 }] as const, maxBy(item => item.score));
|
|
16
|
+
* // => { score: 20 }
|
|
17
|
+
*/
|
|
18
|
+
declare function maxBy<T>(getValue: (element: T, index: number, array: readonly T[]) => number): (array: readonly [T, ...T[]]) => T;
|
|
19
|
+
/**
|
|
20
|
+
* Creates a function that returns the element with the maximum selected number.
|
|
21
|
+
*
|
|
22
|
+
* Empty arrays return undefined. If the selector returns NaN, the element that
|
|
23
|
+
* produced NaN is returned, matching the main {@link maxBy} behavior.
|
|
24
|
+
*
|
|
25
|
+
* @template T - The type of elements in the array.
|
|
26
|
+
* @param getValue - Selects a numeric value from each element, index, and array.
|
|
27
|
+
* @returns A function that maps a readonly array to the maximum element, or undefined.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* import { maxBy, pipe } from 'es-toolkit/fp';
|
|
31
|
+
*
|
|
32
|
+
* pipe([] as Array<{ score: number }>, maxBy(item => item.score));
|
|
33
|
+
* // => undefined
|
|
34
|
+
*/
|
|
35
|
+
declare function maxBy<T>(getValue: (element: T, index: number, array: readonly T[]) => number): (array: readonly T[]) => T | undefined;
|
|
36
|
+
//#endregion
|
|
37
|
+
export { maxBy };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
//#region src/fp/array/minBy.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a function that returns the element with the minimum selected number from a non-empty array.
|
|
4
|
+
*
|
|
5
|
+
* If the selector returns NaN, the element that produced NaN is returned, matching
|
|
6
|
+
* the main {@link minBy} behavior.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The type of elements in the array.
|
|
9
|
+
* @param getValue - Selects a numeric value from each element, index, and array.
|
|
10
|
+
* @returns A function that maps a non-empty readonly array to the minimum element.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* import { minBy, pipe } from 'es-toolkit/fp';
|
|
14
|
+
*
|
|
15
|
+
* pipe([{ score: 10 }, { score: 20 }] as const, minBy(item => item.score));
|
|
16
|
+
* // => { score: 10 }
|
|
17
|
+
*/
|
|
18
|
+
declare function minBy<T>(getValue: (element: T, index: number, array: readonly T[]) => number): (array: readonly [T, ...T[]]) => T;
|
|
19
|
+
/**
|
|
20
|
+
* Creates a function that returns the element with the minimum selected number.
|
|
21
|
+
*
|
|
22
|
+
* Empty arrays return undefined. If the selector returns NaN, the element that
|
|
23
|
+
* produced NaN is returned, matching the main {@link minBy} behavior.
|
|
24
|
+
*
|
|
25
|
+
* @template T - The type of elements in the array.
|
|
26
|
+
* @param getValue - Selects a numeric value from each element, index, and array.
|
|
27
|
+
* @returns A function that maps a readonly array to the minimum element, or undefined.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* import { minBy, pipe } from 'es-toolkit/fp';
|
|
31
|
+
*
|
|
32
|
+
* pipe([] as Array<{ score: number }>, minBy(item => item.score));
|
|
33
|
+
* // => undefined
|
|
34
|
+
*/
|
|
35
|
+
declare function minBy<T>(getValue: (element: T, index: number, array: readonly T[]) => number): (array: readonly T[]) => T | undefined;
|
|
36
|
+
//#endregion
|
|
37
|
+
export { minBy };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
//#region src/fp/array/minBy.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a function that returns the element with the minimum selected number from a non-empty array.
|
|
4
|
+
*
|
|
5
|
+
* If the selector returns NaN, the element that produced NaN is returned, matching
|
|
6
|
+
* the main {@link minBy} behavior.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The type of elements in the array.
|
|
9
|
+
* @param getValue - Selects a numeric value from each element, index, and array.
|
|
10
|
+
* @returns A function that maps a non-empty readonly array to the minimum element.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* import { minBy, pipe } from 'es-toolkit/fp';
|
|
14
|
+
*
|
|
15
|
+
* pipe([{ score: 10 }, { score: 20 }] as const, minBy(item => item.score));
|
|
16
|
+
* // => { score: 10 }
|
|
17
|
+
*/
|
|
18
|
+
declare function minBy<T>(getValue: (element: T, index: number, array: readonly T[]) => number): (array: readonly [T, ...T[]]) => T;
|
|
19
|
+
/**
|
|
20
|
+
* Creates a function that returns the element with the minimum selected number.
|
|
21
|
+
*
|
|
22
|
+
* Empty arrays return undefined. If the selector returns NaN, the element that
|
|
23
|
+
* produced NaN is returned, matching the main {@link minBy} behavior.
|
|
24
|
+
*
|
|
25
|
+
* @template T - The type of elements in the array.
|
|
26
|
+
* @param getValue - Selects a numeric value from each element, index, and array.
|
|
27
|
+
* @returns A function that maps a readonly array to the minimum element, or undefined.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* import { minBy, pipe } from 'es-toolkit/fp';
|
|
31
|
+
*
|
|
32
|
+
* pipe([] as Array<{ score: number }>, minBy(item => item.score));
|
|
33
|
+
* // => undefined
|
|
34
|
+
*/
|
|
35
|
+
declare function minBy<T>(getValue: (element: T, index: number, array: readonly T[]) => number): (array: readonly T[]) => T | undefined;
|
|
36
|
+
//#endregion
|
|
37
|
+
export { minBy };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region src/fp/array/orderBy.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a function that sorts objects by criteria and order directions.
|
|
4
|
+
*
|
|
5
|
+
* Criteria can be object keys or selector functions. The returned function does not mutate
|
|
6
|
+
* the input array; it returns a sorted copy following the main {@link orderBy} behavior.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The object type in the array.
|
|
9
|
+
* @param criteria - Keys or selector functions used for comparison.
|
|
10
|
+
* @param orders - Sort directions corresponding to the criteria.
|
|
11
|
+
* @returns A function that maps a readonly array to a sorted copy.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* import { orderBy, pipe } from 'es-toolkit/fp';
|
|
15
|
+
*
|
|
16
|
+
* pipe([{ name: 'a', age: 2 }, { name: 'b', age: 1 }], orderBy(['age'], ['asc']));
|
|
17
|
+
* // => [{ name: 'b', age: 1 }, { name: 'a', age: 2 }]
|
|
18
|
+
*/
|
|
19
|
+
declare function orderBy<T extends object>(criteria: Array<((item: T) => unknown) | keyof T>, orders: Array<'asc' | 'desc'>): (array: readonly T[]) => T[];
|
|
20
|
+
//#endregion
|
|
21
|
+
export { orderBy };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region src/fp/array/orderBy.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a function that sorts objects by criteria and order directions.
|
|
4
|
+
*
|
|
5
|
+
* Criteria can be object keys or selector functions. The returned function does not mutate
|
|
6
|
+
* the input array; it returns a sorted copy following the main {@link orderBy} behavior.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The object type in the array.
|
|
9
|
+
* @param criteria - Keys or selector functions used for comparison.
|
|
10
|
+
* @param orders - Sort directions corresponding to the criteria.
|
|
11
|
+
* @returns A function that maps a readonly array to a sorted copy.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* import { orderBy, pipe } from 'es-toolkit/fp';
|
|
15
|
+
*
|
|
16
|
+
* pipe([{ name: 'a', age: 2 }, { name: 'b', age: 1 }], orderBy(['age'], ['asc']));
|
|
17
|
+
* // => [{ name: 'b', age: 1 }, { name: 'a', age: 2 }]
|
|
18
|
+
*/
|
|
19
|
+
declare function orderBy<T extends object>(criteria: Array<((item: T) => unknown) | keyof T>, orders: Array<'asc' | 'desc'>): (array: readonly T[]) => T[];
|
|
20
|
+
//#endregion
|
|
21
|
+
export { orderBy };
|