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
package/dist/fp/pipe.mjs
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
//#region src/fp/pipe.ts
|
|
2
|
+
/**
|
|
3
|
+
* Performs left-to-right function composition, threading `value` through each
|
|
4
|
+
* function in sequence. Every function receives the output of the previous
|
|
5
|
+
* one, so the data flows top-to-bottom in the same order it is read. This
|
|
6
|
+
* turns deeply nested calls into clear, sequential steps without temporary
|
|
7
|
+
* variables.
|
|
8
|
+
*
|
|
9
|
+
* This is the entry point of `es-toolkit/fp`. Each `es-toolkit/fp` function is
|
|
10
|
+
* called with its configuration (e.g. `map(fn)`, `take(2)`) and returns a
|
|
11
|
+
* function that takes the data, which `pipe` then supplies.
|
|
12
|
+
*
|
|
13
|
+
* When consecutive **lazy-capable** functions (`map`, `filter`, `take`, ...)
|
|
14
|
+
* appear together, `pipe` fuses them and processes the input element-by-element
|
|
15
|
+
* instead of building an intermediate array after every step. This allows
|
|
16
|
+
* early termination: a trailing `take(n)` stops the walk as soon as `n`
|
|
17
|
+
* results exist, so the remaining input is never visited.
|
|
18
|
+
*
|
|
19
|
+
* @param value - The initial value fed into the pipe.
|
|
20
|
+
* @param functions - Data-last operators (or any unary functions) applied in order.
|
|
21
|
+
* @returns The result of applying every function, left to right.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* import { pipe, map, filter, take } from 'es-toolkit/fp';
|
|
25
|
+
*
|
|
26
|
+
* pipe([1, 2, 3], map(x => x * 3)); // => [3, 6, 9]
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* // Lazy evaluation with early termination: only the first two even squares
|
|
30
|
+
* // are ever computed, the rest of the array is never touched.
|
|
31
|
+
* pipe(
|
|
32
|
+
* [1, 2, 3, 4, 5, 6, 7, 8],
|
|
33
|
+
* map(x => x * x),
|
|
34
|
+
* filter(x => x % 2 === 0),
|
|
35
|
+
* take(2)
|
|
36
|
+
* ); // => [4, 16]
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* // Any unary function works inside a pipe, not just es-toolkit operators.
|
|
40
|
+
* pipe(
|
|
41
|
+
* ' Hello ',
|
|
42
|
+
* s => s.trim(),
|
|
43
|
+
* s => s.toLowerCase()
|
|
44
|
+
* ); // => 'hello'
|
|
45
|
+
*/
|
|
46
|
+
function pipe(value, ...functions) {
|
|
47
|
+
let output = value;
|
|
48
|
+
const groups = chunkFunctions(functions);
|
|
49
|
+
for (let groupIndex = 0; groupIndex < groups.length; groupIndex++) {
|
|
50
|
+
const group = groups[groupIndex];
|
|
51
|
+
if (group.lazy && isIterable(output) && (group.shortCircuit || !Array.isArray(output))) output = lazyPipe(output, group);
|
|
52
|
+
else for (let index = 0; index < group.length; index++) output = group[index](output);
|
|
53
|
+
}
|
|
54
|
+
return output;
|
|
55
|
+
}
|
|
56
|
+
function chunkFunctions(functions) {
|
|
57
|
+
if (functions.length === 0) return [];
|
|
58
|
+
let currentGroup = [functions[0]];
|
|
59
|
+
const result = [currentGroup];
|
|
60
|
+
let previousIsLazy = currentGroup[0].lazy != null;
|
|
61
|
+
if (previousIsLazy) currentGroup.lazy = true;
|
|
62
|
+
if (currentGroup[0].shortCircuit) currentGroup.shortCircuit = true;
|
|
63
|
+
for (let index = 1; index < functions.length; index++) {
|
|
64
|
+
const func = functions[index];
|
|
65
|
+
const isLazy = func.lazy != null;
|
|
66
|
+
if (isLazy !== previousIsLazy) {
|
|
67
|
+
currentGroup = [func];
|
|
68
|
+
result.push(currentGroup);
|
|
69
|
+
} else currentGroup.push(func);
|
|
70
|
+
if (isLazy) currentGroup.lazy = true;
|
|
71
|
+
if (func.shortCircuit) currentGroup.shortCircuit = true;
|
|
72
|
+
previousIsLazy = isLazy;
|
|
73
|
+
}
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Fuses a run of lazy functions into a single pass over `data`. The functions'
|
|
78
|
+
* push transforms are composed (last function first) into one sink, then `data`
|
|
79
|
+
* is driven through it element-by-element. A short-circuiting function (e.g.
|
|
80
|
+
* `take`) returns `false`, which stops the drive loop at once, so the functions
|
|
81
|
+
* before it never run on the rest of the input — no intermediate arrays.
|
|
82
|
+
*
|
|
83
|
+
* @param data - The iterable fed into the run (an array, `Set`, generator, ...).
|
|
84
|
+
* @param lazyFunctions - The consecutive lazy functions to fuse, in order.
|
|
85
|
+
* @returns The collected results.
|
|
86
|
+
*/
|
|
87
|
+
function lazyPipe(data, lazyFunctions) {
|
|
88
|
+
const result = [];
|
|
89
|
+
let sink = (value) => {
|
|
90
|
+
result.push(value);
|
|
91
|
+
return true;
|
|
92
|
+
};
|
|
93
|
+
for (let index = lazyFunctions.length - 1; index >= 0; index--) sink = lazyFunctions[index].lazy(sink);
|
|
94
|
+
if (Array.isArray(data)) {
|
|
95
|
+
for (let index = 0; index < data.length; index++) if (sink(data[index]) === false) break;
|
|
96
|
+
} else {
|
|
97
|
+
const iterator = data[Symbol.iterator]();
|
|
98
|
+
let step = iterator.next();
|
|
99
|
+
while (!step.done) {
|
|
100
|
+
if (sink(step.value) === false) break;
|
|
101
|
+
step = iterator.next();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return result;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Whether `value` can be fed through the lazy path. A non-array iterable (a
|
|
108
|
+
* `Set`, a generator, ...) can only go through `lazyPipe`, since the eager path
|
|
109
|
+
* relies on array methods. Primitives and plain objects (no `Symbol.iterator`)
|
|
110
|
+
* fall through to the eager branch.
|
|
111
|
+
*/
|
|
112
|
+
function isIterable(value) {
|
|
113
|
+
return typeof value === "object" && value !== null && Symbol.iterator in value;
|
|
114
|
+
}
|
|
115
|
+
//#endregion
|
|
116
|
+
export { pipe };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { at } from "./array/at.mjs";
|
|
2
2
|
import { cartesianProduct } from "./array/cartesianProduct.mjs";
|
|
3
3
|
import { chunk } from "./array/chunk.mjs";
|
|
4
|
+
import { chunkBy } from "./array/chunkBy.mjs";
|
|
4
5
|
import { combinations } from "./array/combinations.mjs";
|
|
5
6
|
import { compact } from "./array/compact.mjs";
|
|
6
7
|
import { countBy } from "./array/countBy.mjs";
|
|
@@ -133,6 +134,7 @@ import { isEqualWith } from "./predicate/isEqualWith.mjs";
|
|
|
133
134
|
import { isError } from "./predicate/isError.mjs";
|
|
134
135
|
import { isFile } from "./predicate/isFile.mjs";
|
|
135
136
|
import { isFunction } from "./predicate/isFunction.mjs";
|
|
137
|
+
import { isIterable } from "./predicate/isIterable.mjs";
|
|
136
138
|
import { isJSON } from "./predicate/isJSON.mjs";
|
|
137
139
|
import { isJSONArray, isJSONObject, isJSONValue } from "./predicate/isJSONValue.mjs";
|
|
138
140
|
import { isLength } from "./predicate/isLength.mjs";
|
|
@@ -183,4 +185,4 @@ import { words } from "./string/words.mjs";
|
|
|
183
185
|
import { attempt } from "./util/attempt.mjs";
|
|
184
186
|
import { attemptAsync } from "./util/attemptAsync.mjs";
|
|
185
187
|
import { invariant } from "./util/invariant.mjs";
|
|
186
|
-
export { AbortError, DebounceOptions, DebouncedFunction, MemoizeCache, Mutex, Semaphore, ThrottleOptions, ThrottledFunction, TimeoutError, after, allKeyed, ary, invariant as assert, asyncNoop, at, attempt, attemptAsync, before, camelCase, capitalize, cartesianProduct, chunk, clamp, clone, cloneDeep, cloneDeepWith, combinations, compact, constantCase, countBy, curry, curryRight, debounce, deburr, delay, difference, differenceBy, differenceWith, drop, dropRight, dropRightWhile, dropWhile, escape, escapeRegExp, fill, filterAsync, findKey, flatMap, flatMapAsync, flatMapDeep, flatten, flattenDeep, flattenObject, flow, flowRight, forEachAsync, forEachRight, groupBy, head, identity, inRange, initial, intersection, intersectionBy, intersectionWith, invariant, invert, isArrayBuffer, isBlob, isBoolean, isBrowser, isBuffer, isDate, isEmptyObject, isEqual, isEqualWith, isError, isFile, isFunction, isJSON, isJSONArray, isJSONObject, isJSONValue, isLength, isMap, isNil, isNode, isNotNil, isNull, isNumber, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSubset, isSubsetWith, isSymbol, isTypedArray, isUndefined, isWeakMap, isWeakSet, kebabCase, keyBy, last, limitAsync, lowerCase, lowerFirst, mapAsync, mapKeys, mapValues, maxBy, mean, meanBy, median, medianBy, memoize, merge, mergeWith, minBy, negate, noop, omit, omitBy, once, orderBy, pad, partial, partialRight, partition, pascalCase, percentile, pick, pickBy, pull, pullAt, random, randomInt, range, rangeRight, reduceAsync, remove, rest, retry, reverseString, round, sample, sampleSize, shuffle, snakeCase, sortBy, sortKeys, spread, startCase, sum, sumBy, tail, take, takeRight, takeRightWhile, takeWhile, throttle, timeout, toCamelCaseKeys, toFilled, toMerged, toSnakeCaseKeys, trim, trimEnd, trimStart, unary, unescape, union, unionBy, unionWith, uniq, uniqBy, uniqWith, unzip, unzipWith, upperCase, upperFirst, windowed, withTimeout, without, words, xor, xorBy, xorWith, zip, zipObject, zipWith };
|
|
188
|
+
export { AbortError, DebounceOptions, DebouncedFunction, MemoizeCache, Mutex, Semaphore, ThrottleOptions, ThrottledFunction, TimeoutError, after, allKeyed, ary, invariant as assert, asyncNoop, at, attempt, attemptAsync, before, camelCase, capitalize, cartesianProduct, chunk, chunkBy, clamp, clone, cloneDeep, cloneDeepWith, combinations, compact, constantCase, countBy, curry, curryRight, debounce, deburr, delay, difference, differenceBy, differenceWith, drop, dropRight, dropRightWhile, dropWhile, escape, escapeRegExp, fill, filterAsync, findKey, flatMap, flatMapAsync, flatMapDeep, flatten, flattenDeep, flattenObject, flow, flowRight, forEachAsync, forEachRight, groupBy, head, identity, inRange, initial, intersection, intersectionBy, intersectionWith, invariant, invert, isArrayBuffer, isBlob, isBoolean, isBrowser, isBuffer, isDate, isEmptyObject, isEqual, isEqualWith, isError, isFile, isFunction, isIterable, isJSON, isJSONArray, isJSONObject, isJSONValue, isLength, isMap, isNil, isNode, isNotNil, isNull, isNumber, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSubset, isSubsetWith, isSymbol, isTypedArray, isUndefined, isWeakMap, isWeakSet, kebabCase, keyBy, last, limitAsync, lowerCase, lowerFirst, mapAsync, mapKeys, mapValues, maxBy, mean, meanBy, median, medianBy, memoize, merge, mergeWith, minBy, negate, noop, omit, omitBy, once, orderBy, pad, partial, partialRight, partition, pascalCase, percentile, pick, pickBy, pull, pullAt, random, randomInt, range, rangeRight, reduceAsync, remove, rest, retry, reverseString, round, sample, sampleSize, shuffle, snakeCase, sortBy, sortKeys, spread, startCase, sum, sumBy, tail, take, takeRight, takeRightWhile, takeWhile, throttle, timeout, toCamelCaseKeys, toFilled, toMerged, toSnakeCaseKeys, trim, trimEnd, trimStart, unary, unescape, union, unionBy, unionWith, uniq, uniqBy, uniqWith, unzip, unzipWith, upperCase, upperFirst, windowed, withTimeout, without, words, xor, xorBy, xorWith, zip, zipObject, zipWith };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { at } from "./array/at.js";
|
|
2
2
|
import { cartesianProduct } from "./array/cartesianProduct.js";
|
|
3
3
|
import { chunk } from "./array/chunk.js";
|
|
4
|
+
import { chunkBy } from "./array/chunkBy.js";
|
|
4
5
|
import { combinations } from "./array/combinations.js";
|
|
5
6
|
import { compact } from "./array/compact.js";
|
|
6
7
|
import { countBy } from "./array/countBy.js";
|
|
@@ -133,6 +134,7 @@ import { isEqualWith } from "./predicate/isEqualWith.js";
|
|
|
133
134
|
import { isError } from "./predicate/isError.js";
|
|
134
135
|
import { isFile } from "./predicate/isFile.js";
|
|
135
136
|
import { isFunction } from "./predicate/isFunction.js";
|
|
137
|
+
import { isIterable } from "./predicate/isIterable.js";
|
|
136
138
|
import { isJSON } from "./predicate/isJSON.js";
|
|
137
139
|
import { isJSONArray, isJSONObject, isJSONValue } from "./predicate/isJSONValue.js";
|
|
138
140
|
import { isLength } from "./predicate/isLength.js";
|
|
@@ -183,4 +185,4 @@ import { words } from "./string/words.js";
|
|
|
183
185
|
import { attempt } from "./util/attempt.js";
|
|
184
186
|
import { attemptAsync } from "./util/attemptAsync.js";
|
|
185
187
|
import { invariant } from "./util/invariant.js";
|
|
186
|
-
export { AbortError, DebounceOptions, DebouncedFunction, MemoizeCache, Mutex, Semaphore, ThrottleOptions, ThrottledFunction, TimeoutError, after, allKeyed, ary, invariant as assert, asyncNoop, at, attempt, attemptAsync, before, camelCase, capitalize, cartesianProduct, chunk, clamp, clone, cloneDeep, cloneDeepWith, combinations, compact, constantCase, countBy, curry, curryRight, debounce, deburr, delay, difference, differenceBy, differenceWith, drop, dropRight, dropRightWhile, dropWhile, escape, escapeRegExp, fill, filterAsync, findKey, flatMap, flatMapAsync, flatMapDeep, flatten, flattenDeep, flattenObject, flow, flowRight, forEachAsync, forEachRight, groupBy, head, identity, inRange, initial, intersection, intersectionBy, intersectionWith, invariant, invert, isArrayBuffer, isBlob, isBoolean, isBrowser, isBuffer, isDate, isEmptyObject, isEqual, isEqualWith, isError, isFile, isFunction, isJSON, isJSONArray, isJSONObject, isJSONValue, isLength, isMap, isNil, isNode, isNotNil, isNull, isNumber, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSubset, isSubsetWith, isSymbol, isTypedArray, isUndefined, isWeakMap, isWeakSet, kebabCase, keyBy, last, limitAsync, lowerCase, lowerFirst, mapAsync, mapKeys, mapValues, maxBy, mean, meanBy, median, medianBy, memoize, merge, mergeWith, minBy, negate, noop, omit, omitBy, once, orderBy, pad, partial, partialRight, partition, pascalCase, percentile, pick, pickBy, pull, pullAt, random, randomInt, range, rangeRight, reduceAsync, remove, rest, retry, reverseString, round, sample, sampleSize, shuffle, snakeCase, sortBy, sortKeys, spread, startCase, sum, sumBy, tail, take, takeRight, takeRightWhile, takeWhile, throttle, timeout, toCamelCaseKeys, toFilled, toMerged, toSnakeCaseKeys, trim, trimEnd, trimStart, unary, unescape, union, unionBy, unionWith, uniq, uniqBy, uniqWith, unzip, unzipWith, upperCase, upperFirst, windowed, withTimeout, without, words, xor, xorBy, xorWith, zip, zipObject, zipWith };
|
|
188
|
+
export { AbortError, DebounceOptions, DebouncedFunction, MemoizeCache, Mutex, Semaphore, ThrottleOptions, ThrottledFunction, TimeoutError, after, allKeyed, ary, invariant as assert, asyncNoop, at, attempt, attemptAsync, before, camelCase, capitalize, cartesianProduct, chunk, chunkBy, clamp, clone, cloneDeep, cloneDeepWith, combinations, compact, constantCase, countBy, curry, curryRight, debounce, deburr, delay, difference, differenceBy, differenceWith, drop, dropRight, dropRightWhile, dropWhile, escape, escapeRegExp, fill, filterAsync, findKey, flatMap, flatMapAsync, flatMapDeep, flatten, flattenDeep, flattenObject, flow, flowRight, forEachAsync, forEachRight, groupBy, head, identity, inRange, initial, intersection, intersectionBy, intersectionWith, invariant, invert, isArrayBuffer, isBlob, isBoolean, isBrowser, isBuffer, isDate, isEmptyObject, isEqual, isEqualWith, isError, isFile, isFunction, isIterable, isJSON, isJSONArray, isJSONObject, isJSONValue, isLength, isMap, isNil, isNode, isNotNil, isNull, isNumber, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSubset, isSubsetWith, isSymbol, isTypedArray, isUndefined, isWeakMap, isWeakSet, kebabCase, keyBy, last, limitAsync, lowerCase, lowerFirst, mapAsync, mapKeys, mapValues, maxBy, mean, meanBy, median, medianBy, memoize, merge, mergeWith, minBy, negate, noop, omit, omitBy, once, orderBy, pad, partial, partialRight, partition, pascalCase, percentile, pick, pickBy, pull, pullAt, random, randomInt, range, rangeRight, reduceAsync, remove, rest, retry, reverseString, round, sample, sampleSize, shuffle, snakeCase, sortBy, sortKeys, spread, startCase, sum, sumBy, tail, take, takeRight, takeRightWhile, takeWhile, throttle, timeout, toCamelCaseKeys, toFilled, toMerged, toSnakeCaseKeys, trim, trimEnd, trimStart, unary, unescape, union, unionBy, unionWith, uniq, uniqBy, uniqWith, unzip, unzipWith, upperCase, upperFirst, windowed, withTimeout, without, words, xor, xorBy, xorWith, zip, zipObject, zipWith };
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_at = require("./array/at.js");
|
|
3
3
|
const require_cartesianProduct = require("./array/cartesianProduct.js");
|
|
4
4
|
const require_chunk = require("./array/chunk.js");
|
|
5
|
+
const require_chunkBy = require("./array/chunkBy.js");
|
|
5
6
|
const require_combinations = require("./array/combinations.js");
|
|
6
7
|
const require_compact = require("./array/compact.js");
|
|
7
8
|
const require_countBy = require("./array/countBy.js");
|
|
@@ -148,6 +149,7 @@ const require_isEqual = require("./predicate/isEqual.js");
|
|
|
148
149
|
const require_isError = require("./predicate/isError.js");
|
|
149
150
|
const require_isFile = require("./predicate/isFile.js");
|
|
150
151
|
const require_isFunction = require("./predicate/isFunction.js");
|
|
152
|
+
const require_isIterable = require("./predicate/isIterable.js");
|
|
151
153
|
const require_isJSON = require("./predicate/isJSON.js");
|
|
152
154
|
const require_isJSONValue = require("./predicate/isJSONValue.js");
|
|
153
155
|
const require_isLength = require("./predicate/isLength.js");
|
|
@@ -210,6 +212,7 @@ exports.camelCase = require_camelCase.camelCase;
|
|
|
210
212
|
exports.capitalize = require_capitalize.capitalize;
|
|
211
213
|
exports.cartesianProduct = require_cartesianProduct.cartesianProduct;
|
|
212
214
|
exports.chunk = require_chunk.chunk;
|
|
215
|
+
exports.chunkBy = require_chunkBy.chunkBy;
|
|
213
216
|
exports.clamp = require_clamp.clamp;
|
|
214
217
|
exports.clone = require_clone.clone;
|
|
215
218
|
exports.cloneDeep = require_cloneDeep.cloneDeep;
|
|
@@ -267,6 +270,7 @@ exports.isEqualWith = require_isEqualWith.isEqualWith;
|
|
|
267
270
|
exports.isError = require_isError.isError;
|
|
268
271
|
exports.isFile = require_isFile.isFile;
|
|
269
272
|
exports.isFunction = require_isFunction.isFunction;
|
|
273
|
+
exports.isIterable = require_isIterable.isIterable;
|
|
270
274
|
exports.isJSON = require_isJSON.isJSON;
|
|
271
275
|
exports.isJSONArray = require_isJSONValue.isJSONArray;
|
|
272
276
|
exports.isJSONObject = require_isJSONValue.isJSONObject;
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { at } from "./array/at.mjs";
|
|
2
2
|
import { cartesianProduct } from "./array/cartesianProduct.mjs";
|
|
3
3
|
import { chunk } from "./array/chunk.mjs";
|
|
4
|
+
import { chunkBy } from "./array/chunkBy.mjs";
|
|
4
5
|
import { combinations } from "./array/combinations.mjs";
|
|
5
6
|
import { compact } from "./array/compact.mjs";
|
|
6
7
|
import { countBy } from "./array/countBy.mjs";
|
|
@@ -147,6 +148,7 @@ import { isEqual } from "./predicate/isEqual.mjs";
|
|
|
147
148
|
import { isError } from "./predicate/isError.mjs";
|
|
148
149
|
import { isFile } from "./predicate/isFile.mjs";
|
|
149
150
|
import { isFunction } from "./predicate/isFunction.mjs";
|
|
151
|
+
import { isIterable } from "./predicate/isIterable.mjs";
|
|
150
152
|
import { isJSON } from "./predicate/isJSON.mjs";
|
|
151
153
|
import { isJSONArray, isJSONObject, isJSONValue } from "./predicate/isJSONValue.mjs";
|
|
152
154
|
import { isLength } from "./predicate/isLength.mjs";
|
|
@@ -192,4 +194,4 @@ import { attempt } from "./util/attempt.mjs";
|
|
|
192
194
|
import { attemptAsync } from "./util/attemptAsync.mjs";
|
|
193
195
|
import { invariant } from "./util/invariant.mjs";
|
|
194
196
|
import "./util/index.mjs";
|
|
195
|
-
export { AbortError, Mutex, Semaphore, TimeoutError, after, allKeyed, ary, invariant as assert, asyncNoop, at, attempt, attemptAsync, before, camelCase, capitalize, cartesianProduct, chunk, clamp, clone, cloneDeep, cloneDeepWith, combinations, compact, constantCase, countBy, curry, curryRight, debounce, deburr, delay, difference, differenceBy, differenceWith, drop, dropRight, dropRightWhile, dropWhile, escape, escapeRegExp, fill, filterAsync, findKey, flatMap, flatMapAsync, flatMapDeep, flatten, flattenDeep, flattenObject, flow, flowRight, forEachAsync, forEachRight, groupBy, head, identity, inRange, initial, intersection, intersectionBy, intersectionWith, invariant, invert, isArrayBuffer, isBlob, isBoolean, isBrowser, isBuffer, isDate, isEmptyObject, isEqual, isEqualWith, isError, isFile, isFunction, isJSON, isJSONArray, isJSONObject, isJSONValue, isLength, isMap, isNil, isNode, isNotNil, isNull, isNumber, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSubset, isSubsetWith, isSymbol, isTypedArray, isUndefined, isWeakMap, isWeakSet, kebabCase, keyBy, last, limitAsync, lowerCase, lowerFirst, mapAsync, mapKeys, mapValues, maxBy, mean, meanBy, median, medianBy, memoize, merge, mergeWith, minBy, negate, noop, omit, omitBy, once, orderBy, pad, partial, partialRight, partition, pascalCase, percentile, pick, pickBy, pull, pullAt, random, randomInt, range, rangeRight, reduceAsync, remove, rest, retry, reverseString, round, sample, sampleSize, shuffle, snakeCase, sortBy, sortKeys, spread, startCase, sum, sumBy, tail, take, takeRight, takeRightWhile, takeWhile, throttle, timeout, toCamelCaseKeys, toFilled, toMerged, toSnakeCaseKeys, trim, trimEnd, trimStart, unary, unescape, union, unionBy, unionWith, uniq, uniqBy, uniqWith, unzip, unzipWith, upperCase, upperFirst, windowed, withTimeout, without, words, xor, xorBy, xorWith, zip, zipObject, zipWith };
|
|
197
|
+
export { AbortError, Mutex, Semaphore, TimeoutError, after, allKeyed, ary, invariant as assert, asyncNoop, at, attempt, attemptAsync, before, camelCase, capitalize, cartesianProduct, chunk, chunkBy, clamp, clone, cloneDeep, cloneDeepWith, combinations, compact, constantCase, countBy, curry, curryRight, debounce, deburr, delay, difference, differenceBy, differenceWith, drop, dropRight, dropRightWhile, dropWhile, escape, escapeRegExp, fill, filterAsync, findKey, flatMap, flatMapAsync, flatMapDeep, flatten, flattenDeep, flattenObject, flow, flowRight, forEachAsync, forEachRight, groupBy, head, identity, inRange, initial, intersection, intersectionBy, intersectionWith, invariant, invert, isArrayBuffer, isBlob, isBoolean, isBrowser, isBuffer, isDate, isEmptyObject, isEqual, isEqualWith, isError, isFile, isFunction, isIterable, isJSON, isJSONArray, isJSONObject, isJSONValue, isLength, isMap, isNil, isNode, isNotNil, isNull, isNumber, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSubset, isSubsetWith, isSymbol, isTypedArray, isUndefined, isWeakMap, isWeakSet, kebabCase, keyBy, last, limitAsync, lowerCase, lowerFirst, mapAsync, mapKeys, mapValues, maxBy, mean, meanBy, median, medianBy, memoize, merge, mergeWith, minBy, negate, noop, omit, omitBy, once, orderBy, pad, partial, partialRight, partition, pascalCase, percentile, pick, pickBy, pull, pullAt, random, randomInt, range, rangeRight, reduceAsync, remove, rest, retry, reverseString, round, sample, sampleSize, shuffle, snakeCase, sortBy, sortKeys, spread, startCase, sum, sumBy, tail, take, takeRight, takeRightWhile, takeWhile, throttle, timeout, toCamelCaseKeys, toFilled, toMerged, toSnakeCaseKeys, trim, trimEnd, trimStart, unary, unescape, union, unionBy, unionWith, uniq, uniqBy, uniqWith, unzip, unzipWith, upperCase, upperFirst, windowed, withTimeout, without, words, xor, xorBy, xorWith, zip, zipObject, zipWith };
|
|
@@ -10,6 +10,7 @@ import { isEqualWith } from "./isEqualWith.mjs";
|
|
|
10
10
|
import { isError } from "./isError.mjs";
|
|
11
11
|
import { isFile } from "./isFile.mjs";
|
|
12
12
|
import { isFunction } from "./isFunction.mjs";
|
|
13
|
+
import { isIterable } from "./isIterable.mjs";
|
|
13
14
|
import { isJSON } from "./isJSON.mjs";
|
|
14
15
|
import { isJSONArray, isJSONObject, isJSONValue } from "./isJSONValue.mjs";
|
|
15
16
|
import { isLength } from "./isLength.mjs";
|
|
@@ -30,4 +31,4 @@ import { isTypedArray } from "./isTypedArray.mjs";
|
|
|
30
31
|
import { isUndefined } from "./isUndefined.mjs";
|
|
31
32
|
import { isWeakMap } from "./isWeakMap.mjs";
|
|
32
33
|
import { isWeakSet } from "./isWeakSet.mjs";
|
|
33
|
-
export { isArrayBuffer, isBlob, isBoolean, isBrowser, isBuffer, isDate, isEmptyObject, isEqual, isEqualWith, isError, isFile, isFunction, isJSON, isJSONArray, isJSONObject, isJSONValue, isLength, isMap, isNil, isNode, isNotNil, isNull, isNumber, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSymbol, isTypedArray, isUndefined, isWeakMap, isWeakSet };
|
|
34
|
+
export { isArrayBuffer, isBlob, isBoolean, isBrowser, isBuffer, isDate, isEmptyObject, isEqual, isEqualWith, isError, isFile, isFunction, isIterable, isJSON, isJSONArray, isJSONObject, isJSONValue, isLength, isMap, isNil, isNode, isNotNil, isNull, isNumber, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSymbol, isTypedArray, isUndefined, isWeakMap, isWeakSet };
|
|
@@ -10,6 +10,7 @@ import { isEqualWith } from "./isEqualWith.js";
|
|
|
10
10
|
import { isError } from "./isError.js";
|
|
11
11
|
import { isFile } from "./isFile.js";
|
|
12
12
|
import { isFunction } from "./isFunction.js";
|
|
13
|
+
import { isIterable } from "./isIterable.js";
|
|
13
14
|
import { isJSON } from "./isJSON.js";
|
|
14
15
|
import { isJSONArray, isJSONObject, isJSONValue } from "./isJSONValue.js";
|
|
15
16
|
import { isLength } from "./isLength.js";
|
|
@@ -30,4 +31,4 @@ import { isTypedArray } from "./isTypedArray.js";
|
|
|
30
31
|
import { isUndefined } from "./isUndefined.js";
|
|
31
32
|
import { isWeakMap } from "./isWeakMap.js";
|
|
32
33
|
import { isWeakSet } from "./isWeakSet.js";
|
|
33
|
-
export { isArrayBuffer, isBlob, isBoolean, isBrowser, isBuffer, isDate, isEmptyObject, isEqual, isEqualWith, isError, isFile, isFunction, isJSON, isJSONArray, isJSONObject, isJSONValue, isLength, isMap, isNil, isNode, isNotNil, isNull, isNumber, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSymbol, isTypedArray, isUndefined, isWeakMap, isWeakSet };
|
|
34
|
+
export { isArrayBuffer, isBlob, isBoolean, isBrowser, isBuffer, isDate, isEmptyObject, isEqual, isEqualWith, isError, isFile, isFunction, isIterable, isJSON, isJSONArray, isJSONObject, isJSONValue, isLength, isMap, isNil, isNode, isNotNil, isNull, isNumber, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSymbol, isTypedArray, isUndefined, isWeakMap, isWeakSet };
|
package/dist/predicate/index.js
CHANGED
|
@@ -14,6 +14,7 @@ const require_isEqual = require("./isEqual.js");
|
|
|
14
14
|
const require_isError = require("./isError.js");
|
|
15
15
|
const require_isFile = require("./isFile.js");
|
|
16
16
|
const require_isFunction = require("./isFunction.js");
|
|
17
|
+
const require_isIterable = require("./isIterable.js");
|
|
17
18
|
const require_isJSON = require("./isJSON.js");
|
|
18
19
|
const require_isJSONValue = require("./isJSONValue.js");
|
|
19
20
|
const require_isLength = require("./isLength.js");
|
|
@@ -43,6 +44,7 @@ exports.isEqualWith = require_isEqualWith.isEqualWith;
|
|
|
43
44
|
exports.isError = require_isError.isError;
|
|
44
45
|
exports.isFile = require_isFile.isFile;
|
|
45
46
|
exports.isFunction = require_isFunction.isFunction;
|
|
47
|
+
exports.isIterable = require_isIterable.isIterable;
|
|
46
48
|
exports.isJSON = require_isJSON.isJSON;
|
|
47
49
|
exports.isJSONArray = require_isJSONValue.isJSONArray;
|
|
48
50
|
exports.isJSONObject = require_isJSONValue.isJSONObject;
|
package/dist/predicate/index.mjs
CHANGED
|
@@ -13,6 +13,7 @@ import { isEqual } from "./isEqual.mjs";
|
|
|
13
13
|
import { isError } from "./isError.mjs";
|
|
14
14
|
import { isFile } from "./isFile.mjs";
|
|
15
15
|
import { isFunction } from "./isFunction.mjs";
|
|
16
|
+
import { isIterable } from "./isIterable.mjs";
|
|
16
17
|
import { isJSON } from "./isJSON.mjs";
|
|
17
18
|
import { isJSONArray, isJSONObject, isJSONValue } from "./isJSONValue.mjs";
|
|
18
19
|
import { isLength } from "./isLength.mjs";
|
|
@@ -30,4 +31,4 @@ import { isSymbol } from "./isSymbol.mjs";
|
|
|
30
31
|
import { isUndefined } from "./isUndefined.mjs";
|
|
31
32
|
import { isWeakMap } from "./isWeakMap.mjs";
|
|
32
33
|
import { isWeakSet } from "./isWeakSet.mjs";
|
|
33
|
-
export { isArrayBuffer, isBlob, isBoolean, isBrowser, isBuffer, isDate, isEmptyObject, isEqual, isEqualWith, isError, isFile, isFunction, isJSON, isJSONArray, isJSONObject, isJSONValue, isLength, isMap, isNil, isNode, isNotNil, isNull, isNumber, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSymbol, isTypedArray, isUndefined, isWeakMap, isWeakSet };
|
|
34
|
+
export { isArrayBuffer, isBlob, isBoolean, isBrowser, isBuffer, isDate, isEmptyObject, isEqual, isEqualWith, isError, isFile, isFunction, isIterable, isJSON, isJSONArray, isJSONObject, isJSONValue, isLength, isMap, isNil, isNode, isNotNil, isNull, isNumber, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSymbol, isTypedArray, isUndefined, isWeakMap, isWeakSet };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//#region src/predicate/isIterable.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Checks if a value is iterable, i.e. it implements the iterable protocol by
|
|
4
|
+
* providing a `Symbol.iterator` method.
|
|
5
|
+
*
|
|
6
|
+
* Arrays, strings, `Set`, `Map`, typed arrays, and generators are iterable;
|
|
7
|
+
* plain objects, `null`, and `undefined` are not.
|
|
8
|
+
*
|
|
9
|
+
* This function can be used as a TypeScript type predicate to narrow the type of
|
|
10
|
+
* `value` to `Iterable<unknown>`.
|
|
11
|
+
*
|
|
12
|
+
* @param value - The value to check.
|
|
13
|
+
* @returns `true` if `value` is iterable, `false` otherwise.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* isIterable([1, 2, 3]); // true
|
|
17
|
+
* isIterable('abc'); // true
|
|
18
|
+
* isIterable(new Set([1, 2, 3])); // true
|
|
19
|
+
* isIterable(new Map()); // true
|
|
20
|
+
* isIterable({ a: 1 }); // false
|
|
21
|
+
* isIterable(123); // false
|
|
22
|
+
* isIterable(null); // false
|
|
23
|
+
*/
|
|
24
|
+
declare function isIterable(value: unknown): value is Iterable<unknown>;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { isIterable };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//#region src/predicate/isIterable.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Checks if a value is iterable, i.e. it implements the iterable protocol by
|
|
4
|
+
* providing a `Symbol.iterator` method.
|
|
5
|
+
*
|
|
6
|
+
* Arrays, strings, `Set`, `Map`, typed arrays, and generators are iterable;
|
|
7
|
+
* plain objects, `null`, and `undefined` are not.
|
|
8
|
+
*
|
|
9
|
+
* This function can be used as a TypeScript type predicate to narrow the type of
|
|
10
|
+
* `value` to `Iterable<unknown>`.
|
|
11
|
+
*
|
|
12
|
+
* @param value - The value to check.
|
|
13
|
+
* @returns `true` if `value` is iterable, `false` otherwise.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* isIterable([1, 2, 3]); // true
|
|
17
|
+
* isIterable('abc'); // true
|
|
18
|
+
* isIterable(new Set([1, 2, 3])); // true
|
|
19
|
+
* isIterable(new Map()); // true
|
|
20
|
+
* isIterable({ a: 1 }); // false
|
|
21
|
+
* isIterable(123); // false
|
|
22
|
+
* isIterable(null); // false
|
|
23
|
+
*/
|
|
24
|
+
declare function isIterable(value: unknown): value is Iterable<unknown>;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { isIterable };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//#region src/predicate/isIterable.ts
|
|
2
|
+
/**
|
|
3
|
+
* Checks if a value is iterable, i.e. it implements the iterable protocol by
|
|
4
|
+
* providing a `Symbol.iterator` method.
|
|
5
|
+
*
|
|
6
|
+
* Arrays, strings, `Set`, `Map`, typed arrays, and generators are iterable;
|
|
7
|
+
* plain objects, `null`, and `undefined` are not.
|
|
8
|
+
*
|
|
9
|
+
* This function can be used as a TypeScript type predicate to narrow the type of
|
|
10
|
+
* `value` to `Iterable<unknown>`.
|
|
11
|
+
*
|
|
12
|
+
* @param value - The value to check.
|
|
13
|
+
* @returns `true` if `value` is iterable, `false` otherwise.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* isIterable([1, 2, 3]); // true
|
|
17
|
+
* isIterable('abc'); // true
|
|
18
|
+
* isIterable(new Set([1, 2, 3])); // true
|
|
19
|
+
* isIterable(new Map()); // true
|
|
20
|
+
* isIterable({ a: 1 }); // false
|
|
21
|
+
* isIterable(123); // false
|
|
22
|
+
* isIterable(null); // false
|
|
23
|
+
*/
|
|
24
|
+
function isIterable(value) {
|
|
25
|
+
return value != null && typeof value[Symbol.iterator] === "function";
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
exports.isIterable = isIterable;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//#region src/predicate/isIterable.ts
|
|
2
|
+
/**
|
|
3
|
+
* Checks if a value is iterable, i.e. it implements the iterable protocol by
|
|
4
|
+
* providing a `Symbol.iterator` method.
|
|
5
|
+
*
|
|
6
|
+
* Arrays, strings, `Set`, `Map`, typed arrays, and generators are iterable;
|
|
7
|
+
* plain objects, `null`, and `undefined` are not.
|
|
8
|
+
*
|
|
9
|
+
* This function can be used as a TypeScript type predicate to narrow the type of
|
|
10
|
+
* `value` to `Iterable<unknown>`.
|
|
11
|
+
*
|
|
12
|
+
* @param value - The value to check.
|
|
13
|
+
* @returns `true` if `value` is iterable, `false` otherwise.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* isIterable([1, 2, 3]); // true
|
|
17
|
+
* isIterable('abc'); // true
|
|
18
|
+
* isIterable(new Set([1, 2, 3])); // true
|
|
19
|
+
* isIterable(new Map()); // true
|
|
20
|
+
* isIterable({ a: 1 }); // false
|
|
21
|
+
* isIterable(123); // false
|
|
22
|
+
* isIterable(null); // false
|
|
23
|
+
*/
|
|
24
|
+
function isIterable(value) {
|
|
25
|
+
return value != null && typeof value[Symbol.iterator] === "function";
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { isIterable };
|
package/dist/string/trimStart.js
CHANGED
|
@@ -20,6 +20,7 @@ function trimStart(str, chars) {
|
|
|
20
20
|
let startIndex = 0;
|
|
21
21
|
switch (typeof chars) {
|
|
22
22
|
case "string":
|
|
23
|
+
if (chars.length !== 1) throw new Error(`The 'chars' parameter should be a single character string.`);
|
|
23
24
|
while (startIndex < str.length && str[startIndex] === chars) startIndex++;
|
|
24
25
|
break;
|
|
25
26
|
case "object": while (startIndex < str.length && chars.includes(str[startIndex])) startIndex++;
|
|
@@ -20,6 +20,7 @@ function trimStart(str, chars) {
|
|
|
20
20
|
let startIndex = 0;
|
|
21
21
|
switch (typeof chars) {
|
|
22
22
|
case "string":
|
|
23
|
+
if (chars.length !== 1) throw new Error(`The 'chars' parameter should be a single character string.`);
|
|
23
24
|
while (startIndex < str.length && str[startIndex] === chars) startIndex++;
|
|
24
25
|
break;
|
|
25
26
|
case "object": while (startIndex < str.length && chars.includes(str[startIndex])) startIndex++;
|
package/fp.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dist/fp';
|
package/fp.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/fp');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "es-toolkit",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.49.0",
|
|
4
4
|
"description": "A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.",
|
|
5
5
|
"homepage": "https://es-toolkit.dev",
|
|
6
6
|
"bugs": "https://github.com/toss/es-toolkit/issues",
|
|
@@ -74,6 +74,16 @@
|
|
|
74
74
|
"default": "./dist/error/index.js"
|
|
75
75
|
}
|
|
76
76
|
},
|
|
77
|
+
"./fp": {
|
|
78
|
+
"import": {
|
|
79
|
+
"types": "./dist/fp/index.d.mts",
|
|
80
|
+
"default": "./dist/fp/index.mjs"
|
|
81
|
+
},
|
|
82
|
+
"require": {
|
|
83
|
+
"types": "./dist/fp/index.d.ts",
|
|
84
|
+
"default": "./dist/fp/index.js"
|
|
85
|
+
}
|
|
86
|
+
},
|
|
77
87
|
"./function": {
|
|
78
88
|
"import": {
|
|
79
89
|
"types": "./dist/function/index.d.mts",
|
|
@@ -173,6 +183,7 @@
|
|
|
173
183
|
"array.js",
|
|
174
184
|
"compat.js",
|
|
175
185
|
"error.js",
|
|
186
|
+
"fp.js",
|
|
176
187
|
"function.js",
|
|
177
188
|
"map.js",
|
|
178
189
|
"math.js",
|
|
@@ -304,6 +315,16 @@
|
|
|
304
315
|
"default": "./dist/error/index.js"
|
|
305
316
|
}
|
|
306
317
|
},
|
|
318
|
+
"./fp": {
|
|
319
|
+
"import": {
|
|
320
|
+
"types": "./dist/fp/index.d.mts",
|
|
321
|
+
"default": "./dist/fp/index.mjs"
|
|
322
|
+
},
|
|
323
|
+
"require": {
|
|
324
|
+
"types": "./dist/fp/index.d.ts",
|
|
325
|
+
"default": "./dist/fp/index.js"
|
|
326
|
+
}
|
|
327
|
+
},
|
|
307
328
|
"./function": {
|
|
308
329
|
"import": {
|
|
309
330
|
"types": "./dist/function/index.d.mts",
|