@vinicunca/perkakas 0.0.4 → 0.0.8
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/dist/index.cjs +2276 -0
- package/dist/index.d.cts +3230 -0
- package/dist/index.d.ts +3230 -0
- package/dist/index.js +2135 -0
- package/dist/index.min.js +2 -0
- package/dist/index.min.js.map +7 -0
- package/package.json +38 -30
- package/dist/commonjs/aria/index.d.ts +0 -2
- package/dist/commonjs/aria/index.d.ts.map +0 -1
- package/dist/commonjs/aria/index.js +0 -17
- package/dist/commonjs/aria/key-codes.d.ts +0 -23
- package/dist/commonjs/aria/key-codes.d.ts.map +0 -1
- package/dist/commonjs/aria/key-codes.js +0 -25
- package/dist/commonjs/array/all-pass.d.ts +0 -3
- package/dist/commonjs/array/all-pass.d.ts.map +0 -1
- package/dist/commonjs/array/all-pass.js +0 -11
- package/dist/commonjs/array/any-pass.d.ts +0 -3
- package/dist/commonjs/array/any-pass.d.ts.map +0 -1
- package/dist/commonjs/array/any-pass.js +0 -11
- package/dist/commonjs/array/chunk.d.ts +0 -6
- package/dist/commonjs/array/chunk.d.ts.map +0 -1
- package/dist/commonjs/array/chunk.js +0 -17
- package/dist/commonjs/array/compact.d.ts +0 -2
- package/dist/commonjs/array/compact.d.ts.map +0 -1
- package/dist/commonjs/array/compact.js +0 -8
- package/dist/commonjs/array/concat.d.ts +0 -3
- package/dist/commonjs/array/concat.d.ts.map +0 -1
- package/dist/commonjs/array/concat.js +0 -11
- package/dist/commonjs/array/count-by.d.ts +0 -8
- package/dist/commonjs/array/count-by.d.ts.map +0 -1
- package/dist/commonjs/array/count-by.js +0 -22
- package/dist/commonjs/array/difference-with.d.ts +0 -9
- package/dist/commonjs/array/difference-with.d.ts.map +0 -1
- package/dist/commonjs/array/difference-with.js +0 -31
- package/dist/commonjs/array/difference.d.ts +0 -7
- package/dist/commonjs/array/difference.d.ts.map +0 -1
- package/dist/commonjs/array/difference.js +0 -32
- package/dist/commonjs/array/drop-last.d.ts +0 -3
- package/dist/commonjs/array/drop-last.d.ts.map +0 -1
- package/dist/commonjs/array/drop-last.js +0 -15
- package/dist/commonjs/array/drop.d.ts +0 -7
- package/dist/commonjs/array/drop.d.ts.map +0 -1
- package/dist/commonjs/array/drop.js +0 -32
- package/dist/commonjs/array/filter.d.ts +0 -17
- package/dist/commonjs/array/filter.d.ts.map +0 -1
- package/dist/commonjs/array/filter.js +0 -41
- package/dist/commonjs/array/find-index.d.ts +0 -32
- package/dist/commonjs/array/find-index.d.ts.map +0 -1
- package/dist/commonjs/array/find-index.js +0 -46
- package/dist/commonjs/array/find-last-index.d.ts +0 -8
- package/dist/commonjs/array/find-last-index.d.ts.map +0 -1
- package/dist/commonjs/array/find-last-index.js +0 -24
- package/dist/commonjs/array/find-last.d.ts +0 -8
- package/dist/commonjs/array/find-last.d.ts.map +0 -1
- package/dist/commonjs/array/find-last.js +0 -23
- package/dist/commonjs/array/find.d.ts +0 -24
- package/dist/commonjs/array/find.d.ts.map +0 -1
- package/dist/commonjs/array/find.js +0 -38
- package/dist/commonjs/array/first.d.ts +0 -16
- package/dist/commonjs/array/first.d.ts.map +0 -1
- package/dist/commonjs/array/first.js +0 -26
- package/dist/commonjs/array/flat-map-to-obj.d.ts +0 -7
- package/dist/commonjs/array/flat-map-to-obj.d.ts.map +0 -1
- package/dist/commonjs/array/flat-map-to-obj.js +0 -25
- package/dist/commonjs/array/flat-map.d.ts +0 -16
- package/dist/commonjs/array/flat-map.d.ts.map +0 -1
- package/dist/commonjs/array/flat-map.js +0 -33
- package/dist/commonjs/array/flatten-deep.d.ts +0 -12
- package/dist/commonjs/array/flatten-deep.d.ts.map +0 -1
- package/dist/commonjs/array/flatten-deep.js +0 -48
- package/dist/commonjs/array/flatten.d.ts +0 -9
- package/dist/commonjs/array/flatten.d.ts.map +0 -1
- package/dist/commonjs/array/flatten.js +0 -32
- package/dist/commonjs/array/for-each.d.ts +0 -13
- package/dist/commonjs/array/for-each.d.ts.map +0 -1
- package/dist/commonjs/array/for-each.js +0 -40
- package/dist/commonjs/array/group-by.d.ts +0 -19
- package/dist/commonjs/array/group-by.d.ts.map +0 -1
- package/dist/commonjs/array/group-by.js +0 -31
- package/dist/commonjs/array/index-by.d.ts +0 -8
- package/dist/commonjs/array/index-by.d.ts.map +0 -1
- package/dist/commonjs/array/index-by.js +0 -24
- package/dist/commonjs/array/index.d.ts +0 -56
- package/dist/commonjs/array/index.d.ts.map +0 -1
- package/dist/commonjs/array/index.js +0 -71
- package/dist/commonjs/array/intersection-with.d.ts +0 -9
- package/dist/commonjs/array/intersection-with.d.ts.map +0 -1
- package/dist/commonjs/array/intersection-with.js +0 -31
- package/dist/commonjs/array/intersection.d.ts +0 -7
- package/dist/commonjs/array/intersection.d.ts.map +0 -1
- package/dist/commonjs/array/intersection.js +0 -32
- package/dist/commonjs/array/join.d.ts +0 -8
- package/dist/commonjs/array/join.d.ts.map +0 -1
- package/dist/commonjs/array/join.js +0 -11
- package/dist/commonjs/array/last.d.ts +0 -5
- package/dist/commonjs/array/last.d.ts.map +0 -1
- package/dist/commonjs/array/last.js +0 -11
- package/dist/commonjs/array/length.d.ts +0 -5
- package/dist/commonjs/array/length.d.ts.map +0 -1
- package/dist/commonjs/array/length.js +0 -11
- package/dist/commonjs/array/map-to-obj.d.ts +0 -7
- package/dist/commonjs/array/map-to-obj.d.ts.map +0 -1
- package/dist/commonjs/array/map-to-obj.js +0 -23
- package/dist/commonjs/array/map.d.ts +0 -26
- package/dist/commonjs/array/map.d.ts.map +0 -1
- package/dist/commonjs/array/map.js +0 -35
- package/dist/commonjs/array/max-by.d.ts +0 -8
- package/dist/commonjs/array/max-by.d.ts.map +0 -1
- package/dist/commonjs/array/max-by.js +0 -28
- package/dist/commonjs/array/mean-by.d.ts +0 -8
- package/dist/commonjs/array/mean-by.d.ts.map +0 -1
- package/dist/commonjs/array/mean-by.js +0 -26
- package/dist/commonjs/array/merge-all.d.ts +0 -7
- package/dist/commonjs/array/merge-all.d.ts.map +0 -1
- package/dist/commonjs/array/merge-all.js +0 -7
- package/dist/commonjs/array/min-by.d.ts +0 -8
- package/dist/commonjs/array/min-by.d.ts.map +0 -1
- package/dist/commonjs/array/min-by.js +0 -28
- package/dist/commonjs/array/partition.d.ts +0 -10
- package/dist/commonjs/array/partition.d.ts.map +0 -1
- package/dist/commonjs/array/partition.js +0 -24
- package/dist/commonjs/array/range.d.ts +0 -3
- package/dist/commonjs/array/range.d.ts.map +0 -1
- package/dist/commonjs/array/range.js +0 -15
- package/dist/commonjs/array/reduce.d.ts +0 -7
- package/dist/commonjs/array/reduce.d.ts.map +0 -1
- package/dist/commonjs/array/reduce.js +0 -19
- package/dist/commonjs/array/reject.d.ts +0 -13
- package/dist/commonjs/array/reject.d.ts.map +0 -1
- package/dist/commonjs/array/reject.js +0 -41
- package/dist/commonjs/array/reverse.d.ts +0 -6
- package/dist/commonjs/array/reverse.d.ts.map +0 -1
- package/dist/commonjs/array/reverse.js +0 -11
- package/dist/commonjs/array/sample.d.ts +0 -11
- package/dist/commonjs/array/sample.d.ts.map +0 -1
- package/dist/commonjs/array/sample.js +0 -34
- package/dist/commonjs/array/shuffle.d.ts +0 -3
- package/dist/commonjs/array/shuffle.d.ts.map +0 -1
- package/dist/commonjs/array/shuffle.js +0 -18
- package/dist/commonjs/array/sort-by.d.ts +0 -27
- package/dist/commonjs/array/sort-by.d.ts.map +0 -1
- package/dist/commonjs/array/sort-by.js +0 -55
- package/dist/commonjs/array/sort.d.ts +0 -15
- package/dist/commonjs/array/sort.d.ts.map +0 -1
- package/dist/commonjs/array/sort.js +0 -16
- package/dist/commonjs/array/split-at.d.ts +0 -3
- package/dist/commonjs/array/split-at.d.ts.map +0 -1
- package/dist/commonjs/array/split-at.js +0 -13
- package/dist/commonjs/array/split-when.d.ts +0 -3
- package/dist/commonjs/array/split-when.d.ts.map +0 -1
- package/dist/commonjs/array/split-when.js +0 -17
- package/dist/commonjs/array/sum-by.d.ts +0 -8
- package/dist/commonjs/array/sum-by.d.ts.map +0 -1
- package/dist/commonjs/array/sum-by.js +0 -24
- package/dist/commonjs/array/swap-indices.d.ts +0 -25
- package/dist/commonjs/array/swap-indices.d.ts.map +0 -1
- package/dist/commonjs/array/swap-indices.js +0 -34
- package/dist/commonjs/array/take-while.d.ts +0 -3
- package/dist/commonjs/array/take-while.d.ts.map +0 -1
- package/dist/commonjs/array/take-while.js +0 -18
- package/dist/commonjs/array/take.d.ts +0 -7
- package/dist/commonjs/array/take.d.ts.map +0 -1
- package/dist/commonjs/array/take.js +0 -38
- package/dist/commonjs/array/uniq-by.d.ts +0 -3
- package/dist/commonjs/array/uniq-by.d.ts.map +0 -1
- package/dist/commonjs/array/uniq-by.js +0 -30
- package/dist/commonjs/array/uniq-with.d.ts +0 -12
- package/dist/commonjs/array/uniq-with.d.ts.map +0 -1
- package/dist/commonjs/array/uniq-with.js +0 -33
- package/dist/commonjs/array/uniq.d.ts +0 -7
- package/dist/commonjs/array/uniq.d.ts.map +0 -1
- package/dist/commonjs/array/uniq.js +0 -32
- package/dist/commonjs/array/zip-obj.d.ts +0 -3
- package/dist/commonjs/array/zip-obj.d.ts.map +0 -1
- package/dist/commonjs/array/zip-obj.js +0 -16
- package/dist/commonjs/array/zip-with.d.ts +0 -4
- package/dist/commonjs/array/zip-with.d.ts.map +0 -1
- package/dist/commonjs/array/zip-with.js +0 -28
- package/dist/commonjs/array/zip.d.ts +0 -3
- package/dist/commonjs/array/zip.d.ts.map +0 -1
- package/dist/commonjs/array/zip.js +0 -16
- package/dist/commonjs/base.d.ts +0 -2
- package/dist/commonjs/base.d.ts.map +0 -1
- package/dist/commonjs/base.js +0 -7
- package/dist/commonjs/function/create-pipe.d.ts +0 -8
- package/dist/commonjs/function/create-pipe.d.ts.map +0 -1
- package/dist/commonjs/function/create-pipe.js +0 -8
- package/dist/commonjs/function/identity.d.ts +0 -2
- package/dist/commonjs/function/identity.d.ts.map +0 -1
- package/dist/commonjs/function/identity.js +0 -7
- package/dist/commonjs/function/index.d.ts +0 -7
- package/dist/commonjs/function/index.d.ts.map +0 -1
- package/dist/commonjs/function/index.js +0 -22
- package/dist/commonjs/function/noop.d.ts +0 -2
- package/dist/commonjs/function/noop.d.ts.map +0 -1
- package/dist/commonjs/function/noop.js +0 -7
- package/dist/commonjs/function/once.d.ts +0 -2
- package/dist/commonjs/function/once.d.ts.map +0 -1
- package/dist/commonjs/function/once.js +0 -15
- package/dist/commonjs/function/pipe.d.ts +0 -16
- package/dist/commonjs/function/pipe.d.ts.map +0 -1
- package/dist/commonjs/function/pipe.js +0 -105
- package/dist/commonjs/function/purry.d.ts +0 -2
- package/dist/commonjs/function/purry.d.ts.map +0 -1
- package/dist/commonjs/function/purry.js +0 -20
- package/dist/commonjs/guard/index.d.ts +0 -16
- package/dist/commonjs/guard/index.d.ts.map +0 -1
- package/dist/commonjs/guard/index.js +0 -31
- package/dist/commonjs/guard/is-array.d.ts +0 -4
- package/dist/commonjs/guard/is-array.d.ts.map +0 -1
- package/dist/commonjs/guard/is-array.js +0 -7
- package/dist/commonjs/guard/is-boolean.d.ts +0 -4
- package/dist/commonjs/guard/is-boolean.d.ts.map +0 -1
- package/dist/commonjs/guard/is-boolean.js +0 -7
- package/dist/commonjs/guard/is-date.d.ts +0 -2
- package/dist/commonjs/guard/is-date.d.ts.map +0 -1
- package/dist/commonjs/guard/is-date.js +0 -7
- package/dist/commonjs/guard/is-defined.d.ts +0 -5
- package/dist/commonjs/guard/is-defined.d.ts.map +0 -1
- package/dist/commonjs/guard/is-defined.js +0 -13
- package/dist/commonjs/guard/is-empty.d.ts +0 -4
- package/dist/commonjs/guard/is-empty.d.ts.map +0 -1
- package/dist/commonjs/guard/is-empty.js +0 -19
- package/dist/commonjs/guard/is-error.d.ts +0 -4
- package/dist/commonjs/guard/is-error.d.ts.map +0 -1
- package/dist/commonjs/guard/is-error.js +0 -7
- package/dist/commonjs/guard/is-function.d.ts +0 -4
- package/dist/commonjs/guard/is-function.d.ts.map +0 -1
- package/dist/commonjs/guard/is-function.js +0 -7
- package/dist/commonjs/guard/is-nil.d.ts +0 -2
- package/dist/commonjs/guard/is-nil.d.ts.map +0 -1
- package/dist/commonjs/guard/is-nil.js +0 -7
- package/dist/commonjs/guard/is-non-null.d.ts +0 -2
- package/dist/commonjs/guard/is-non-null.d.ts.map +0 -1
- package/dist/commonjs/guard/is-non-null.js +0 -7
- package/dist/commonjs/guard/is-not.d.ts +0 -3
- package/dist/commonjs/guard/is-not.d.ts.map +0 -1
- package/dist/commonjs/guard/is-not.js +0 -9
- package/dist/commonjs/guard/is-number.d.ts +0 -4
- package/dist/commonjs/guard/is-number.d.ts.map +0 -1
- package/dist/commonjs/guard/is-number.js +0 -7
- package/dist/commonjs/guard/is-object.d.ts +0 -4
- package/dist/commonjs/guard/is-object.d.ts.map +0 -1
- package/dist/commonjs/guard/is-object.js +0 -8
- package/dist/commonjs/guard/is-promise.d.ts +0 -2
- package/dist/commonjs/guard/is-promise.d.ts.map +0 -1
- package/dist/commonjs/guard/is-promise.js +0 -7
- package/dist/commonjs/guard/is-string.d.ts +0 -4
- package/dist/commonjs/guard/is-string.d.ts.map +0 -1
- package/dist/commonjs/guard/is-string.js +0 -7
- package/dist/commonjs/guard/is-truthy.d.ts +0 -2
- package/dist/commonjs/guard/is-truthy.d.ts.map +0 -1
- package/dist/commonjs/guard/is-truthy.js +0 -7
- package/dist/commonjs/helpers/index.d.ts +0 -8
- package/dist/commonjs/helpers/index.d.ts.map +0 -1
- package/dist/commonjs/helpers/index.js +0 -52
- package/dist/commonjs/index.d.ts +0 -11
- package/dist/commonjs/index.d.ts.map +0 -1
- package/dist/commonjs/index.js +0 -27
- package/dist/commonjs/number/clamp.d.ts +0 -9
- package/dist/commonjs/number/clamp.d.ts.map +0 -1
- package/dist/commonjs/number/clamp.js +0 -17
- package/dist/commonjs/number/index.d.ts +0 -2
- package/dist/commonjs/number/index.d.ts.map +0 -1
- package/dist/commonjs/number/index.js +0 -17
- package/dist/commonjs/object/add-prop.d.ts +0 -7
- package/dist/commonjs/object/add-prop.d.ts.map +0 -1
- package/dist/commonjs/object/add-prop.js +0 -11
- package/dist/commonjs/object/clone.d.ts +0 -2
- package/dist/commonjs/object/clone.d.ts.map +0 -1
- package/dist/commonjs/object/clone.js +0 -49
- package/dist/commonjs/object/equals.d.ts +0 -3
- package/dist/commonjs/object/equals.d.ts.map +0 -1
- package/dist/commonjs/object/equals.js +0 -71
- package/dist/commonjs/object/for-each-obj.d.ts +0 -10
- package/dist/commonjs/object/for-each-obj.d.ts.map +0 -1
- package/dist/commonjs/object/for-each-obj.js +0 -30
- package/dist/commonjs/object/from-pairs.d.ts +0 -21
- package/dist/commonjs/object/from-pairs.d.ts.map +0 -1
- package/dist/commonjs/object/from-pairs.js +0 -14
- package/dist/commonjs/object/index.d.ts +0 -23
- package/dist/commonjs/object/index.d.ts.map +0 -1
- package/dist/commonjs/object/index.js +0 -38
- package/dist/commonjs/object/invert.d.ts +0 -5
- package/dist/commonjs/object/invert.d.ts.map +0 -1
- package/dist/commonjs/object/invert.js +0 -15
- package/dist/commonjs/object/keys.d.ts +0 -15
- package/dist/commonjs/object/keys.d.ts.map +0 -1
- package/dist/commonjs/object/keys.js +0 -10
- package/dist/commonjs/object/map-keys.d.ts +0 -3
- package/dist/commonjs/object/map-keys.d.ts.map +0 -1
- package/dist/commonjs/object/map-keys.js +0 -16
- package/dist/commonjs/object/map-values.d.ts +0 -3
- package/dist/commonjs/object/map-values.d.ts.map +0 -1
- package/dist/commonjs/object/map-values.js +0 -16
- package/dist/commonjs/object/merge.d.ts +0 -3
- package/dist/commonjs/object/merge.d.ts.map +0 -1
- package/dist/commonjs/object/merge.js +0 -11
- package/dist/commonjs/object/omit-by.d.ts +0 -3
- package/dist/commonjs/object/omit-by.d.ts.map +0 -1
- package/dist/commonjs/object/omit-by.js +0 -16
- package/dist/commonjs/object/omit.d.ts +0 -3
- package/dist/commonjs/object/omit.d.ts.map +0 -1
- package/dist/commonjs/object/omit.js +0 -35
- package/dist/commonjs/object/path-or.d.ts +0 -21
- package/dist/commonjs/object/path-or.d.ts.map +0 -1
- package/dist/commonjs/object/path-or.js +0 -18
- package/dist/commonjs/object/pick-by.d.ts +0 -3
- package/dist/commonjs/object/pick-by.d.ts.map +0 -1
- package/dist/commonjs/object/pick-by.js +0 -19
- package/dist/commonjs/object/pick.d.ts +0 -3
- package/dist/commonjs/object/pick.d.ts.map +0 -1
- package/dist/commonjs/object/pick.js +0 -19
- package/dist/commonjs/object/prop.d.ts +0 -2
- package/dist/commonjs/object/prop.d.ts.map +0 -1
- package/dist/commonjs/object/prop.js +0 -5
- package/dist/commonjs/object/set-path.d.ts +0 -6
- package/dist/commonjs/object/set-path.d.ts.map +0 -1
- package/dist/commonjs/object/set-path.js +0 -23
- package/dist/commonjs/object/set.d.ts +0 -3
- package/dist/commonjs/object/set.d.ts.map +0 -1
- package/dist/commonjs/object/set.js +0 -11
- package/dist/commonjs/object/swap-props.d.ts +0 -7
- package/dist/commonjs/object/swap-props.d.ts.map +0 -1
- package/dist/commonjs/object/swap-props.js +0 -12
- package/dist/commonjs/object/to-pairs.d.ts +0 -13
- package/dist/commonjs/object/to-pairs.d.ts.map +0 -1
- package/dist/commonjs/object/to-pairs.js +0 -13
- package/dist/commonjs/object/values.d.ts +0 -2
- package/dist/commonjs/object/values.d.ts.map +0 -1
- package/dist/commonjs/object/values.js +0 -7
- package/dist/commonjs/string/cases-types.d.ts +0 -29
- package/dist/commonjs/string/cases-types.d.ts.map +0 -1
- package/dist/commonjs/string/cases-types.js +0 -2
- package/dist/commonjs/string/cases.d.ts +0 -16
- package/dist/commonjs/string/cases.d.ts.map +0 -1
- package/dist/commonjs/string/cases.js +0 -86
- package/dist/commonjs/string/index.d.ts +0 -4
- package/dist/commonjs/string/index.d.ts.map +0 -1
- package/dist/commonjs/string/index.js +0 -19
- package/dist/commonjs/string/random-string.d.ts +0 -2
- package/dist/commonjs/string/random-string.d.ts.map +0 -1
- package/dist/commonjs/string/random-string.js +0 -10
- package/dist/commonjs/string/string-to-path.d.ts +0 -3
- package/dist/commonjs/string/string-to-path.d.ts.map +0 -1
- package/dist/commonjs/string/string-to-path.js +0 -19
- package/dist/commonjs/type/index.d.ts +0 -2
- package/dist/commonjs/type/index.d.ts.map +0 -1
- package/dist/commonjs/type/index.js +0 -17
- package/dist/commonjs/type/type.d.ts +0 -2
- package/dist/commonjs/type/type.d.ts.map +0 -1
- package/dist/commonjs/type/type.js +0 -11
- package/dist/commonjs/utils/narrow.d.ts +0 -8
- package/dist/commonjs/utils/narrow.d.ts.map +0 -1
- package/dist/commonjs/utils/narrow.js +0 -2
- package/dist/commonjs/utils/paths.d.ts +0 -9
- package/dist/commonjs/utils/paths.d.ts.map +0 -1
- package/dist/commonjs/utils/paths.js +0 -2
- package/dist/commonjs/utils/reduce-lazy.d.ts +0 -22
- package/dist/commonjs/utils/reduce-lazy.d.ts.map +0 -1
- package/dist/commonjs/utils/reduce-lazy.js +0 -18
- package/dist/commonjs/utils/to-lazy-indexed.d.ts +0 -4
- package/dist/commonjs/utils/to-lazy-indexed.d.ts.map +0 -1
- package/dist/commonjs/utils/to-lazy-indexed.js +0 -8
- package/dist/commonjs/utils/to-single.d.ts +0 -4
- package/dist/commonjs/utils/to-single.d.ts.map +0 -1
- package/dist/commonjs/utils/to-single.js +0 -8
- package/dist/commonjs/utils/types.d.ts +0 -6
- package/dist/commonjs/utils/types.d.ts.map +0 -1
- package/dist/commonjs/utils/types.js +0 -2
- package/dist/es/aria/index.d.ts +0 -2
- package/dist/es/aria/index.d.ts.map +0 -1
- package/dist/es/aria/index.js +0 -1
- package/dist/es/aria/key-codes.d.ts +0 -23
- package/dist/es/aria/key-codes.d.ts.map +0 -1
- package/dist/es/aria/key-codes.js +0 -22
- package/dist/es/array/all-pass.d.ts +0 -3
- package/dist/es/array/all-pass.d.ts.map +0 -1
- package/dist/es/array/all-pass.js +0 -7
- package/dist/es/array/any-pass.d.ts +0 -3
- package/dist/es/array/any-pass.d.ts.map +0 -1
- package/dist/es/array/any-pass.js +0 -7
- package/dist/es/array/chunk.d.ts +0 -6
- package/dist/es/array/chunk.d.ts.map +0 -1
- package/dist/es/array/chunk.js +0 -13
- package/dist/es/array/compact.d.ts +0 -2
- package/dist/es/array/compact.d.ts.map +0 -1
- package/dist/es/array/compact.js +0 -4
- package/dist/es/array/concat.d.ts +0 -3
- package/dist/es/array/concat.d.ts.map +0 -1
- package/dist/es/array/concat.js +0 -7
- package/dist/es/array/count-by.d.ts +0 -8
- package/dist/es/array/count-by.d.ts.map +0 -1
- package/dist/es/array/count-by.js +0 -18
- package/dist/es/array/difference-with.d.ts +0 -9
- package/dist/es/array/difference-with.d.ts.map +0 -1
- package/dist/es/array/difference-with.js +0 -27
- package/dist/es/array/difference.d.ts +0 -7
- package/dist/es/array/difference.d.ts.map +0 -1
- package/dist/es/array/difference.js +0 -28
- package/dist/es/array/drop-last.d.ts +0 -3
- package/dist/es/array/drop-last.d.ts.map +0 -1
- package/dist/es/array/drop-last.js +0 -11
- package/dist/es/array/drop.d.ts +0 -7
- package/dist/es/array/drop.d.ts.map +0 -1
- package/dist/es/array/drop.js +0 -28
- package/dist/es/array/filter.d.ts +0 -17
- package/dist/es/array/filter.d.ts.map +0 -1
- package/dist/es/array/filter.js +0 -37
- package/dist/es/array/find-index.d.ts +0 -32
- package/dist/es/array/find-index.d.ts.map +0 -1
- package/dist/es/array/find-index.js +0 -42
- package/dist/es/array/find-last-index.d.ts +0 -8
- package/dist/es/array/find-last-index.d.ts.map +0 -1
- package/dist/es/array/find-last-index.js +0 -20
- package/dist/es/array/find-last.d.ts +0 -8
- package/dist/es/array/find-last.d.ts.map +0 -1
- package/dist/es/array/find-last.js +0 -19
- package/dist/es/array/find.d.ts +0 -24
- package/dist/es/array/find.d.ts.map +0 -1
- package/dist/es/array/find.js +0 -34
- package/dist/es/array/first.d.ts +0 -16
- package/dist/es/array/first.d.ts.map +0 -1
- package/dist/es/array/first.js +0 -22
- package/dist/es/array/flat-map-to-obj.d.ts +0 -7
- package/dist/es/array/flat-map-to-obj.d.ts.map +0 -1
- package/dist/es/array/flat-map-to-obj.js +0 -21
- package/dist/es/array/flat-map.d.ts +0 -16
- package/dist/es/array/flat-map.d.ts.map +0 -1
- package/dist/es/array/flat-map.js +0 -29
- package/dist/es/array/flatten-deep.d.ts +0 -12
- package/dist/es/array/flatten-deep.d.ts.map +0 -1
- package/dist/es/array/flatten-deep.js +0 -44
- package/dist/es/array/flatten.d.ts +0 -9
- package/dist/es/array/flatten.d.ts.map +0 -1
- package/dist/es/array/flatten.js +0 -28
- package/dist/es/array/for-each.d.ts +0 -13
- package/dist/es/array/for-each.d.ts.map +0 -1
- package/dist/es/array/for-each.js +0 -36
- package/dist/es/array/group-by.d.ts +0 -19
- package/dist/es/array/group-by.d.ts.map +0 -1
- package/dist/es/array/group-by.js +0 -27
- package/dist/es/array/index-by.d.ts +0 -8
- package/dist/es/array/index-by.d.ts.map +0 -1
- package/dist/es/array/index-by.js +0 -20
- package/dist/es/array/index.d.ts +0 -56
- package/dist/es/array/index.d.ts.map +0 -1
- package/dist/es/array/index.js +0 -55
- package/dist/es/array/intersection-with.d.ts +0 -9
- package/dist/es/array/intersection-with.d.ts.map +0 -1
- package/dist/es/array/intersection-with.js +0 -27
- package/dist/es/array/intersection.d.ts +0 -7
- package/dist/es/array/intersection.d.ts.map +0 -1
- package/dist/es/array/intersection.js +0 -28
- package/dist/es/array/join.d.ts +0 -8
- package/dist/es/array/join.d.ts.map +0 -1
- package/dist/es/array/join.js +0 -7
- package/dist/es/array/last.d.ts +0 -5
- package/dist/es/array/last.d.ts.map +0 -1
- package/dist/es/array/last.js +0 -7
- package/dist/es/array/length.d.ts +0 -5
- package/dist/es/array/length.d.ts.map +0 -1
- package/dist/es/array/length.js +0 -7
- package/dist/es/array/map-to-obj.d.ts +0 -7
- package/dist/es/array/map-to-obj.d.ts.map +0 -1
- package/dist/es/array/map-to-obj.js +0 -19
- package/dist/es/array/map.d.ts +0 -26
- package/dist/es/array/map.d.ts.map +0 -1
- package/dist/es/array/map.js +0 -31
- package/dist/es/array/max-by.d.ts +0 -8
- package/dist/es/array/max-by.d.ts.map +0 -1
- package/dist/es/array/max-by.js +0 -24
- package/dist/es/array/mean-by.d.ts +0 -8
- package/dist/es/array/mean-by.d.ts.map +0 -1
- package/dist/es/array/mean-by.js +0 -22
- package/dist/es/array/merge-all.d.ts +0 -7
- package/dist/es/array/merge-all.d.ts.map +0 -1
- package/dist/es/array/merge-all.js +0 -3
- package/dist/es/array/min-by.d.ts +0 -8
- package/dist/es/array/min-by.d.ts.map +0 -1
- package/dist/es/array/min-by.js +0 -24
- package/dist/es/array/partition.d.ts +0 -10
- package/dist/es/array/partition.d.ts.map +0 -1
- package/dist/es/array/partition.js +0 -20
- package/dist/es/array/range.d.ts +0 -3
- package/dist/es/array/range.d.ts.map +0 -1
- package/dist/es/array/range.js +0 -11
- package/dist/es/array/reduce.d.ts +0 -7
- package/dist/es/array/reduce.d.ts.map +0 -1
- package/dist/es/array/reduce.js +0 -15
- package/dist/es/array/reject.d.ts +0 -13
- package/dist/es/array/reject.d.ts.map +0 -1
- package/dist/es/array/reject.js +0 -37
- package/dist/es/array/reverse.d.ts +0 -6
- package/dist/es/array/reverse.d.ts.map +0 -1
- package/dist/es/array/reverse.js +0 -7
- package/dist/es/array/sample.d.ts +0 -11
- package/dist/es/array/sample.d.ts.map +0 -1
- package/dist/es/array/sample.js +0 -30
- package/dist/es/array/shuffle.d.ts +0 -3
- package/dist/es/array/shuffle.d.ts.map +0 -1
- package/dist/es/array/shuffle.js +0 -14
- package/dist/es/array/sort-by.d.ts +0 -27
- package/dist/es/array/sort-by.d.ts.map +0 -1
- package/dist/es/array/sort-by.js +0 -51
- package/dist/es/array/sort.d.ts +0 -15
- package/dist/es/array/sort.d.ts.map +0 -1
- package/dist/es/array/sort.js +0 -12
- package/dist/es/array/split-at.d.ts +0 -3
- package/dist/es/array/split-at.d.ts.map +0 -1
- package/dist/es/array/split-at.js +0 -9
- package/dist/es/array/split-when.d.ts +0 -3
- package/dist/es/array/split-when.d.ts.map +0 -1
- package/dist/es/array/split-when.js +0 -13
- package/dist/es/array/sum-by.d.ts +0 -8
- package/dist/es/array/sum-by.d.ts.map +0 -1
- package/dist/es/array/sum-by.js +0 -20
- package/dist/es/array/swap-indices.d.ts +0 -25
- package/dist/es/array/swap-indices.d.ts.map +0 -1
- package/dist/es/array/swap-indices.js +0 -30
- package/dist/es/array/take-while.d.ts +0 -3
- package/dist/es/array/take-while.d.ts.map +0 -1
- package/dist/es/array/take-while.js +0 -14
- package/dist/es/array/take.d.ts +0 -7
- package/dist/es/array/take.d.ts.map +0 -1
- package/dist/es/array/take.js +0 -34
- package/dist/es/array/uniq-by.d.ts +0 -3
- package/dist/es/array/uniq-by.d.ts.map +0 -1
- package/dist/es/array/uniq-by.js +0 -26
- package/dist/es/array/uniq-with.d.ts +0 -12
- package/dist/es/array/uniq-with.d.ts.map +0 -1
- package/dist/es/array/uniq-with.js +0 -29
- package/dist/es/array/uniq.d.ts +0 -7
- package/dist/es/array/uniq.d.ts.map +0 -1
- package/dist/es/array/uniq.js +0 -28
- package/dist/es/array/zip-obj.d.ts +0 -3
- package/dist/es/array/zip-obj.d.ts.map +0 -1
- package/dist/es/array/zip-obj.js +0 -12
- package/dist/es/array/zip-with.d.ts +0 -4
- package/dist/es/array/zip-with.d.ts.map +0 -1
- package/dist/es/array/zip-with.js +0 -24
- package/dist/es/array/zip.d.ts +0 -3
- package/dist/es/array/zip.d.ts.map +0 -1
- package/dist/es/array/zip.js +0 -12
- package/dist/es/base.d.ts +0 -2
- package/dist/es/base.d.ts.map +0 -1
- package/dist/es/base.js +0 -3
- package/dist/es/function/create-pipe.d.ts +0 -8
- package/dist/es/function/create-pipe.d.ts.map +0 -1
- package/dist/es/function/create-pipe.js +0 -4
- package/dist/es/function/identity.d.ts +0 -2
- package/dist/es/function/identity.d.ts.map +0 -1
- package/dist/es/function/identity.js +0 -3
- package/dist/es/function/index.d.ts +0 -7
- package/dist/es/function/index.d.ts.map +0 -1
- package/dist/es/function/index.js +0 -6
- package/dist/es/function/noop.d.ts +0 -2
- package/dist/es/function/noop.d.ts.map +0 -1
- package/dist/es/function/noop.js +0 -3
- package/dist/es/function/once.d.ts +0 -2
- package/dist/es/function/once.d.ts.map +0 -1
- package/dist/es/function/once.js +0 -11
- package/dist/es/function/pipe.d.ts +0 -16
- package/dist/es/function/pipe.d.ts.map +0 -1
- package/dist/es/function/pipe.js +0 -101
- package/dist/es/function/purry.d.ts +0 -2
- package/dist/es/function/purry.d.ts.map +0 -1
- package/dist/es/function/purry.js +0 -16
- package/dist/es/guard/index.d.ts +0 -16
- package/dist/es/guard/index.d.ts.map +0 -1
- package/dist/es/guard/index.js +0 -15
- package/dist/es/guard/is-array.d.ts +0 -4
- package/dist/es/guard/is-array.d.ts.map +0 -1
- package/dist/es/guard/is-array.js +0 -3
- package/dist/es/guard/is-boolean.d.ts +0 -4
- package/dist/es/guard/is-boolean.d.ts.map +0 -1
- package/dist/es/guard/is-boolean.js +0 -3
- package/dist/es/guard/is-date.d.ts +0 -2
- package/dist/es/guard/is-date.d.ts.map +0 -1
- package/dist/es/guard/is-date.js +0 -3
- package/dist/es/guard/is-defined.d.ts +0 -5
- package/dist/es/guard/is-defined.d.ts.map +0 -1
- package/dist/es/guard/is-defined.js +0 -9
- package/dist/es/guard/is-empty.d.ts +0 -4
- package/dist/es/guard/is-empty.d.ts.map +0 -1
- package/dist/es/guard/is-empty.js +0 -15
- package/dist/es/guard/is-error.d.ts +0 -4
- package/dist/es/guard/is-error.d.ts.map +0 -1
- package/dist/es/guard/is-error.js +0 -3
- package/dist/es/guard/is-function.d.ts +0 -4
- package/dist/es/guard/is-function.d.ts.map +0 -1
- package/dist/es/guard/is-function.js +0 -3
- package/dist/es/guard/is-nil.d.ts +0 -2
- package/dist/es/guard/is-nil.d.ts.map +0 -1
- package/dist/es/guard/is-nil.js +0 -3
- package/dist/es/guard/is-non-null.d.ts +0 -2
- package/dist/es/guard/is-non-null.d.ts.map +0 -1
- package/dist/es/guard/is-non-null.js +0 -3
- package/dist/es/guard/is-not.d.ts +0 -3
- package/dist/es/guard/is-not.d.ts.map +0 -1
- package/dist/es/guard/is-not.js +0 -5
- package/dist/es/guard/is-number.d.ts +0 -4
- package/dist/es/guard/is-number.d.ts.map +0 -1
- package/dist/es/guard/is-number.js +0 -3
- package/dist/es/guard/is-object.d.ts +0 -4
- package/dist/es/guard/is-object.d.ts.map +0 -1
- package/dist/es/guard/is-object.js +0 -4
- package/dist/es/guard/is-promise.d.ts +0 -2
- package/dist/es/guard/is-promise.d.ts.map +0 -1
- package/dist/es/guard/is-promise.js +0 -3
- package/dist/es/guard/is-string.d.ts +0 -4
- package/dist/es/guard/is-string.d.ts.map +0 -1
- package/dist/es/guard/is-string.js +0 -3
- package/dist/es/guard/is-truthy.d.ts +0 -2
- package/dist/es/guard/is-truthy.d.ts.map +0 -1
- package/dist/es/guard/is-truthy.js +0 -3
- package/dist/es/helpers/index.d.ts +0 -8
- package/dist/es/helpers/index.d.ts.map +0 -1
- package/dist/es/helpers/index.js +0 -45
- package/dist/es/index.d.ts +0 -11
- package/dist/es/index.d.ts.map +0 -1
- package/dist/es/index.js +0 -10
- package/dist/es/number/clamp.d.ts +0 -9
- package/dist/es/number/clamp.d.ts.map +0 -1
- package/dist/es/number/clamp.js +0 -13
- package/dist/es/number/index.d.ts +0 -2
- package/dist/es/number/index.d.ts.map +0 -1
- package/dist/es/number/index.js +0 -1
- package/dist/es/object/add-prop.d.ts +0 -7
- package/dist/es/object/add-prop.d.ts.map +0 -1
- package/dist/es/object/add-prop.js +0 -7
- package/dist/es/object/clone.d.ts +0 -2
- package/dist/es/object/clone.d.ts.map +0 -1
- package/dist/es/object/clone.js +0 -45
- package/dist/es/object/equals.d.ts +0 -3
- package/dist/es/object/equals.d.ts.map +0 -1
- package/dist/es/object/equals.js +0 -67
- package/dist/es/object/for-each-obj.d.ts +0 -10
- package/dist/es/object/for-each-obj.d.ts.map +0 -1
- package/dist/es/object/for-each-obj.js +0 -26
- package/dist/es/object/from-pairs.d.ts +0 -21
- package/dist/es/object/from-pairs.d.ts.map +0 -1
- package/dist/es/object/from-pairs.js +0 -10
- package/dist/es/object/index.d.ts +0 -23
- package/dist/es/object/index.d.ts.map +0 -1
- package/dist/es/object/index.js +0 -22
- package/dist/es/object/invert.d.ts +0 -5
- package/dist/es/object/invert.d.ts.map +0 -1
- package/dist/es/object/invert.js +0 -11
- package/dist/es/object/keys.d.ts +0 -15
- package/dist/es/object/keys.d.ts.map +0 -1
- package/dist/es/object/keys.js +0 -6
- package/dist/es/object/map-keys.d.ts +0 -3
- package/dist/es/object/map-keys.d.ts.map +0 -1
- package/dist/es/object/map-keys.js +0 -12
- package/dist/es/object/map-values.d.ts +0 -3
- package/dist/es/object/map-values.d.ts.map +0 -1
- package/dist/es/object/map-values.js +0 -12
- package/dist/es/object/merge.d.ts +0 -3
- package/dist/es/object/merge.d.ts.map +0 -1
- package/dist/es/object/merge.js +0 -7
- package/dist/es/object/omit-by.d.ts +0 -3
- package/dist/es/object/omit-by.d.ts.map +0 -1
- package/dist/es/object/omit-by.js +0 -12
- package/dist/es/object/omit.d.ts +0 -3
- package/dist/es/object/omit.d.ts.map +0 -1
- package/dist/es/object/omit.js +0 -31
- package/dist/es/object/path-or.d.ts +0 -21
- package/dist/es/object/path-or.d.ts.map +0 -1
- package/dist/es/object/path-or.js +0 -14
- package/dist/es/object/pick-by.d.ts +0 -3
- package/dist/es/object/pick-by.d.ts.map +0 -1
- package/dist/es/object/pick-by.js +0 -15
- package/dist/es/object/pick.d.ts +0 -3
- package/dist/es/object/pick.d.ts.map +0 -1
- package/dist/es/object/pick.js +0 -15
- package/dist/es/object/prop.d.ts +0 -2
- package/dist/es/object/prop.d.ts.map +0 -1
- package/dist/es/object/prop.js +0 -1
- package/dist/es/object/set-path.d.ts +0 -6
- package/dist/es/object/set-path.d.ts.map +0 -1
- package/dist/es/object/set-path.js +0 -18
- package/dist/es/object/set.d.ts +0 -3
- package/dist/es/object/set.d.ts.map +0 -1
- package/dist/es/object/set.js +0 -7
- package/dist/es/object/swap-props.d.ts +0 -7
- package/dist/es/object/swap-props.d.ts.map +0 -1
- package/dist/es/object/swap-props.js +0 -8
- package/dist/es/object/to-pairs.d.ts +0 -13
- package/dist/es/object/to-pairs.d.ts.map +0 -1
- package/dist/es/object/to-pairs.js +0 -9
- package/dist/es/object/values.d.ts +0 -2
- package/dist/es/object/values.d.ts.map +0 -1
- package/dist/es/object/values.js +0 -3
- package/dist/es/string/cases-types.d.ts +0 -29
- package/dist/es/string/cases-types.d.ts.map +0 -1
- package/dist/es/string/cases-types.js +0 -1
- package/dist/es/string/cases.d.ts +0 -16
- package/dist/es/string/cases.d.ts.map +0 -1
- package/dist/es/string/cases.js +0 -75
- package/dist/es/string/index.d.ts +0 -4
- package/dist/es/string/index.d.ts.map +0 -1
- package/dist/es/string/index.js +0 -3
- package/dist/es/string/random-string.d.ts +0 -2
- package/dist/es/string/random-string.d.ts.map +0 -1
- package/dist/es/string/random-string.js +0 -6
- package/dist/es/string/string-to-path.d.ts +0 -3
- package/dist/es/string/string-to-path.d.ts.map +0 -1
- package/dist/es/string/string-to-path.js +0 -15
- package/dist/es/type/index.d.ts +0 -2
- package/dist/es/type/index.d.ts.map +0 -1
- package/dist/es/type/index.js +0 -1
- package/dist/es/type/type.d.ts +0 -2
- package/dist/es/type/type.d.ts.map +0 -1
- package/dist/es/type/type.js +0 -7
- package/dist/es/utils/narrow.d.ts +0 -8
- package/dist/es/utils/narrow.d.ts.map +0 -1
- package/dist/es/utils/narrow.js +0 -1
- package/dist/es/utils/paths.d.ts +0 -9
- package/dist/es/utils/paths.d.ts.map +0 -1
- package/dist/es/utils/paths.js +0 -1
- package/dist/es/utils/reduce-lazy.d.ts +0 -22
- package/dist/es/utils/reduce-lazy.d.ts.map +0 -1
- package/dist/es/utils/reduce-lazy.js +0 -14
- package/dist/es/utils/to-lazy-indexed.d.ts +0 -4
- package/dist/es/utils/to-lazy-indexed.d.ts.map +0 -1
- package/dist/es/utils/to-lazy-indexed.js +0 -4
- package/dist/es/utils/to-single.d.ts +0 -4
- package/dist/es/utils/to-single.d.ts.map +0 -1
- package/dist/es/utils/to-single.js +0 -4
- package/dist/es/utils/types.d.ts +0 -6
- package/dist/es/utils/types.d.ts.map +0 -1
- package/dist/es/utils/types.js +0 -1
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,3230 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Using event.code is not predictable since each machine may have different output
|
|
3
|
+
*/
|
|
4
|
+
declare const KEY_CODES: {
|
|
5
|
+
readonly TAB: "Tab";
|
|
6
|
+
readonly ARROW_DOWN: "ArrowDown";
|
|
7
|
+
readonly ARROW_UP: "ArrowUp";
|
|
8
|
+
readonly ARROW_LEFT: "ArrowLeft";
|
|
9
|
+
readonly ARROW_RIGHT: "ArrowRight";
|
|
10
|
+
readonly ENTER: "Enter";
|
|
11
|
+
readonly ESC: "Escape";
|
|
12
|
+
readonly SPACE: "Space";
|
|
13
|
+
readonly SHIFT: "Shift";
|
|
14
|
+
readonly KEY_F: "KEY_F";
|
|
15
|
+
readonly CTRL: "Control";
|
|
16
|
+
readonly ALT: "Alt";
|
|
17
|
+
readonly META: "Meta";
|
|
18
|
+
readonly AT: "@";
|
|
19
|
+
readonly DELETE: "Delete";
|
|
20
|
+
readonly BACKSPACE: "Backspace";
|
|
21
|
+
readonly HOME: "Home";
|
|
22
|
+
readonly END: "End";
|
|
23
|
+
readonly PAGE_UP: "PageUp";
|
|
24
|
+
readonly PAGE_DOWN: "PageDown";
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Determines whether all predicates returns true for the input data.
|
|
29
|
+
* @param data The input data for predicates.
|
|
30
|
+
* @param fns The list of predicates.
|
|
31
|
+
* @signature
|
|
32
|
+
* P.allPass(data, fns)
|
|
33
|
+
* @example
|
|
34
|
+
* const isDivisibleBy3 = (x: number) => x % 3 === 0
|
|
35
|
+
* const isDivisibleBy4 = (x: number) => x % 4 === 0
|
|
36
|
+
* const fns = [isDivisibleBy3, isDivisibleBy4]
|
|
37
|
+
* P.allPass(12, fns) // => true
|
|
38
|
+
* P.allPass(8, fns) // => false
|
|
39
|
+
* @dataFirst
|
|
40
|
+
* @category Array
|
|
41
|
+
*/
|
|
42
|
+
declare function allPass<T>(data: T, fns: ReadonlyArray<(data: T) => boolean>): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Determines whether all predicates returns true for the input data.
|
|
45
|
+
* @param fns The list of predicates.
|
|
46
|
+
* @signature
|
|
47
|
+
* P.allPass(fns)(data)
|
|
48
|
+
* @example
|
|
49
|
+
* const isDivisibleBy3 = (x: number) => x % 3 === 0
|
|
50
|
+
* const isDivisibleBy4 = (x: number) => x % 4 === 0
|
|
51
|
+
* const fns = [isDivisibleBy3, isDivisibleBy4]
|
|
52
|
+
* P.allPass(fns)(12) // => true
|
|
53
|
+
* P.allPass(fns)(8) // => false
|
|
54
|
+
* @dataLast
|
|
55
|
+
* @category Array
|
|
56
|
+
*/
|
|
57
|
+
declare function allPass<T>(fns: ReadonlyArray<(data: T) => boolean>): (data: T) => boolean;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Determines whether any predicate returns true for the input data.
|
|
61
|
+
* @param data The input data for predicates.
|
|
62
|
+
* @param fns The list of predicates.
|
|
63
|
+
* @signature
|
|
64
|
+
* P.anyPass(data, fns)
|
|
65
|
+
* @example
|
|
66
|
+
* const isDivisibleBy3 = (x: number) => x % 3 === 0
|
|
67
|
+
* const isDivisibleBy4 = (x: number) => x % 4 === 0
|
|
68
|
+
* const fns = [isDivisibleBy3, isDivisibleBy4]
|
|
69
|
+
* P.anyPass(8, fns) // => true
|
|
70
|
+
* P.anyPass(11, fns) // => false
|
|
71
|
+
* @dataFirst
|
|
72
|
+
* @category Array
|
|
73
|
+
*/
|
|
74
|
+
declare function anyPass<T>(data: T, fns: ReadonlyArray<(data: T) => boolean>): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Determines whether any predicate returns true for the input data.
|
|
77
|
+
* @param fns The list of predicates.
|
|
78
|
+
* @signature
|
|
79
|
+
* P.anyPass(fns)(data)
|
|
80
|
+
* @example
|
|
81
|
+
* const isDivisibleBy3 = (x: number) => x % 3 === 0
|
|
82
|
+
* const isDivisibleBy4 = (x: number) => x % 4 === 0
|
|
83
|
+
* const fns = [isDivisibleBy3, isDivisibleBy4]
|
|
84
|
+
* P.anyPass(fns)(8) // => true
|
|
85
|
+
* P.anyPass(fns)(11) // => false
|
|
86
|
+
* @dataLast
|
|
87
|
+
* @category Array
|
|
88
|
+
*/
|
|
89
|
+
declare function anyPass<T>(fns: ReadonlyArray<(data: T) => boolean>): (data: T) => boolean;
|
|
90
|
+
|
|
91
|
+
type Pred<T, K> = (input: T) => K;
|
|
92
|
+
type PredIndexed<T, K> = (input: T, index: number, array: Array<T>) => K;
|
|
93
|
+
type PredIndexedOptional<T, K> = (input: T, index?: number, array?: Array<T>) => K;
|
|
94
|
+
type NonEmptyArray<T> = [T, ...Array<T>];
|
|
95
|
+
/**
|
|
96
|
+
* This should only be used for defining generics which extend any kind of JS
|
|
97
|
+
* array under the hood, this includes arrays *AND* tuples (of the form [x, y],
|
|
98
|
+
* and of the form [x, ...y[]], etc...), and their readonly equivalent. This
|
|
99
|
+
* allows us to be more inclusive to what functions can process.
|
|
100
|
+
*
|
|
101
|
+
* @example map<T extends ArrayLike>(items: T) { ... }
|
|
102
|
+
*
|
|
103
|
+
* We would've named this `ArrayLike`, but that's already used by typescript...
|
|
104
|
+
*
|
|
105
|
+
* @see This was inspired by the type-definition of Promise.all (https://github.com/microsoft/TypeScript/blob/1df5717b120cddd325deab8b0f2b2c3eecaf2b01/src/lib/es2015.promise.d.ts#L21)
|
|
106
|
+
*/
|
|
107
|
+
type IterableContainer<T = unknown> = ReadonlyArray<T> | [];
|
|
108
|
+
|
|
109
|
+
type Chunked<T extends IterableContainer> = T[number] extends never ? [] : T extends readonly [unknown, ...Array<unknown>] | readonly [...Array<unknown>, unknown] ? NonEmptyArray<NonEmptyArray<T[number]>> : Array<NonEmptyArray<T[number]>>;
|
|
110
|
+
/**
|
|
111
|
+
* Split an array into groups the length of `size`. If `array` can't be split evenly, the final chunk will be the remaining elements.
|
|
112
|
+
* @param array the array
|
|
113
|
+
* @param size the length of the chunk
|
|
114
|
+
* @signature
|
|
115
|
+
* P.chunk(array, size)
|
|
116
|
+
* @example
|
|
117
|
+
* P.chunk(['a', 'b', 'c', 'd'], 2) // => [['a', 'b'], ['c', 'd']]
|
|
118
|
+
* P.chunk(['a', 'b', 'c', 'd'], 3) // => [['a', 'b', 'c'], ['d']]
|
|
119
|
+
* @dataFirst
|
|
120
|
+
* @category Array
|
|
121
|
+
*/
|
|
122
|
+
declare function chunk<T extends IterableContainer>(array: T, size: number): Chunked<T>;
|
|
123
|
+
/**
|
|
124
|
+
* Split an array into groups the length of `size`. If `array` can't be split evenly, the final chunk will be the remaining elements.
|
|
125
|
+
* @param size the length of the chunk
|
|
126
|
+
* @signature
|
|
127
|
+
* P.chunk(size)(array)
|
|
128
|
+
* @example
|
|
129
|
+
* P.chunk(2)(['a', 'b', 'c', 'd']) // => [['a', 'b'], ['c', 'd']]
|
|
130
|
+
* P.chunk(3)(['a', 'b', 'c', 'd']) // => [['a', 'b', 'c'], ['d']]
|
|
131
|
+
* @dataLast
|
|
132
|
+
* @category Array
|
|
133
|
+
*/
|
|
134
|
+
declare function chunk<T extends IterableContainer>(size: number): (array: T) => Chunked<T>;
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Filter out all falsey values. The values `false`, `null`, `0`, `""`, `undefined`, and `NaN` are falsey.
|
|
138
|
+
* @param items the array to compact
|
|
139
|
+
* @signature
|
|
140
|
+
* P.compact(array)
|
|
141
|
+
* @example
|
|
142
|
+
* P.compact([0, 1, false, 2, '', 3]) // => [1, 2, 3]
|
|
143
|
+
* @category Array
|
|
144
|
+
* @pipeable
|
|
145
|
+
*/
|
|
146
|
+
declare function compact<T>(items: ReadonlyArray<T | null | undefined | false | '' | 0>): Array<T>;
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Combines two arrays.
|
|
150
|
+
* @param arr1 the first array
|
|
151
|
+
* @param arr2 the second array
|
|
152
|
+
* @signature
|
|
153
|
+
* P.concat(arr1, arr2);
|
|
154
|
+
* @example
|
|
155
|
+
* P.concat([1, 2, 3], ['a']) // [1, 2, 3, 'a']
|
|
156
|
+
* @dataFirst
|
|
157
|
+
* @category Array
|
|
158
|
+
*/
|
|
159
|
+
declare function concat<T, K>(arr1: ReadonlyArray<T>, arr2: ReadonlyArray<K>): Array<T | K>;
|
|
160
|
+
/**
|
|
161
|
+
* Combines two arrays.
|
|
162
|
+
* @param arr2 the second array
|
|
163
|
+
* @signature
|
|
164
|
+
* P.concat(arr2)(arr1);
|
|
165
|
+
* @example
|
|
166
|
+
* P.concat(['a'])([1, 2, 3]) // [1, 2, 3, 'a']
|
|
167
|
+
* @dataLast
|
|
168
|
+
* @category Array
|
|
169
|
+
*/
|
|
170
|
+
declare function concat<T, K>(arr2: ReadonlyArray<K>): (arr1: ReadonlyArray<T>) => Array<T | K>;
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Counts how many values of the collection pass the specified predicate.
|
|
174
|
+
* @param items The input data.
|
|
175
|
+
* @param fn The predicate.
|
|
176
|
+
* @signature
|
|
177
|
+
* P.countBy(array, fn)
|
|
178
|
+
* @example
|
|
179
|
+
* P.countBy([1, 2, 3, 4, 5], x => x % 2 === 0) // => 2
|
|
180
|
+
* @dataFirst
|
|
181
|
+
* @indexed
|
|
182
|
+
* @category Array
|
|
183
|
+
*/
|
|
184
|
+
declare function countBy<T>(items: ReadonlyArray<T>, fn: Pred<T, boolean>): number;
|
|
185
|
+
declare function countBy<T>(fn: Pred<T, boolean>): (array: ReadonlyArray<T>) => number;
|
|
186
|
+
declare namespace countBy {
|
|
187
|
+
function indexed<T>(array: ReadonlyArray<T>, fn: PredIndexed<T, boolean>): number;
|
|
188
|
+
function indexed<T>(fn: PredIndexed<T, boolean>): (array: ReadonlyArray<T>) => number;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
type LazyResult<T> = LazyEmpty | LazyNext<T> | LazyMany<T>;
|
|
192
|
+
interface LazyEmpty {
|
|
193
|
+
done: boolean;
|
|
194
|
+
hasNext: false;
|
|
195
|
+
hasMany?: false | undefined;
|
|
196
|
+
next?: undefined;
|
|
197
|
+
}
|
|
198
|
+
interface LazyNext<T> {
|
|
199
|
+
done: boolean;
|
|
200
|
+
hasNext: true;
|
|
201
|
+
hasMany?: false | undefined;
|
|
202
|
+
next: T;
|
|
203
|
+
}
|
|
204
|
+
interface LazyMany<T> {
|
|
205
|
+
done: boolean;
|
|
206
|
+
hasNext: true;
|
|
207
|
+
hasMany: true;
|
|
208
|
+
next: Array<T>;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
type IsEquals$1<TFirst, TSecond> = (a: TFirst, b: TSecond) => boolean;
|
|
212
|
+
/**
|
|
213
|
+
* Excludes the values from `other` array.
|
|
214
|
+
* Elements are compared by custom comparator isEquals.
|
|
215
|
+
* @param array the source array
|
|
216
|
+
* @param other the values to exclude
|
|
217
|
+
* @param isEquals the comparator
|
|
218
|
+
* @signature
|
|
219
|
+
* P.differenceWith(array, other, isEquals)
|
|
220
|
+
* @example
|
|
221
|
+
* P.differenceWith(
|
|
222
|
+
* [{a: 1}, {a: 2}, {a: 3}, {a: 4}],
|
|
223
|
+
* [{a: 2}, {a: 5}, {a: 3}],
|
|
224
|
+
* P.equals,
|
|
225
|
+
* ) // => [{a: 1}, {a: 4}]
|
|
226
|
+
* @dataFirst
|
|
227
|
+
* @category Array
|
|
228
|
+
* @pipeable
|
|
229
|
+
*/
|
|
230
|
+
declare function differenceWith<TFirst, TSecond>(array: ReadonlyArray<TFirst>, other: ReadonlyArray<TSecond>, isEquals: IsEquals$1<TFirst, TSecond>): Array<TFirst>;
|
|
231
|
+
/**
|
|
232
|
+
* Excludes the values from `other` array.
|
|
233
|
+
* Elements are compared by custom comparator isEquals.
|
|
234
|
+
* @param other the values to exclude
|
|
235
|
+
* @param isEquals the comparator
|
|
236
|
+
* @signature
|
|
237
|
+
* P.differenceWith(other, isEquals)(array)
|
|
238
|
+
* @example
|
|
239
|
+
* P.differenceWith(
|
|
240
|
+
* [{a: 2}, {a: 5}, {a: 3}],
|
|
241
|
+
* P.equals,
|
|
242
|
+
* )([{a: 1}, {a: 2}, {a: 3}, {a: 4}]) // => [{a: 1}, {a: 4}]
|
|
243
|
+
* P.pipe(
|
|
244
|
+
* [{a: 1}, {a: 2}, {a: 3}, {a: 4}, {a: 5}, {a: 6}], // only 4 iterations
|
|
245
|
+
* P.differenceWith([{a: 2}, {a: 3}], P.equals),
|
|
246
|
+
* P.take(2),
|
|
247
|
+
* ) // => [{a: 1}, {a: 4}]
|
|
248
|
+
* @dataLast
|
|
249
|
+
* @category Array
|
|
250
|
+
* @pipeable
|
|
251
|
+
*/
|
|
252
|
+
declare function differenceWith<TFirst, TSecond>(other: ReadonlyArray<TSecond>, isEquals: IsEquals$1<TFirst, TSecond>): (array: ReadonlyArray<TFirst>) => Array<TFirst>;
|
|
253
|
+
declare namespace differenceWith {
|
|
254
|
+
function lazy<TFirst, TSecond>(other: Array<TSecond>, isEquals: IsEquals$1<TFirst, TSecond>): (value: TFirst) => LazyResult<TFirst>;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Excludes the values from `other` array.
|
|
259
|
+
* @param array the source array
|
|
260
|
+
* @param other the values to exclude
|
|
261
|
+
* @signature
|
|
262
|
+
* P.difference(array, other)
|
|
263
|
+
* @example
|
|
264
|
+
* P.difference([1, 2, 3, 4], [2, 5, 3]) // => [1, 4]
|
|
265
|
+
* @dataFirst
|
|
266
|
+
* @category Array
|
|
267
|
+
* @pipeable
|
|
268
|
+
*/
|
|
269
|
+
declare function difference<T>(array: ReadonlyArray<T>, other: ReadonlyArray<T>): Array<T>;
|
|
270
|
+
/**
|
|
271
|
+
* Excludes the values from `other` array.
|
|
272
|
+
* @param other the values to exclude
|
|
273
|
+
* @signature
|
|
274
|
+
* P.difference(other)(array)
|
|
275
|
+
* @example
|
|
276
|
+
* P.difference([2, 5, 3])([1, 2, 3, 4]) // => [1, 4]
|
|
277
|
+
* P.pipe(
|
|
278
|
+
* [1, 2, 3, 4, 5, 6], // only 4 iterations
|
|
279
|
+
* P.difference([2, 3]),
|
|
280
|
+
* P.take(2)
|
|
281
|
+
* ) // => [1, 4]
|
|
282
|
+
* @dataLast
|
|
283
|
+
* @category Array
|
|
284
|
+
* @pipeable
|
|
285
|
+
*/
|
|
286
|
+
declare function difference<T, K>(other: ReadonlyArray<T>): (array: ReadonlyArray<K>) => Array<T>;
|
|
287
|
+
declare namespace difference {
|
|
288
|
+
function lazy<T>(other: Array<T>): (value: T) => LazyResult<T>;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Removes last `n` elements from the `array`.
|
|
293
|
+
* @param array the target array
|
|
294
|
+
* @param n the number of elements to skip
|
|
295
|
+
* @signature
|
|
296
|
+
* P.dropLast(array, n)
|
|
297
|
+
* @example
|
|
298
|
+
* P.dropLast([1, 2, 3, 4, 5], 2) // => [1, 2, 3]
|
|
299
|
+
* @dataFirst
|
|
300
|
+
* @category Array
|
|
301
|
+
*/
|
|
302
|
+
declare function dropLast<T>(array: ReadonlyArray<T>, n: number): Array<T>;
|
|
303
|
+
/**
|
|
304
|
+
* Removes last `n` elements from the `array`.
|
|
305
|
+
* @param n the number of elements to skip
|
|
306
|
+
* @signature
|
|
307
|
+
* P.dropLast(n)(array)
|
|
308
|
+
* @example
|
|
309
|
+
* P.dropLast(2)([1, 2, 3, 4, 5]) // => [1, 2, 3]
|
|
310
|
+
* @dataLast
|
|
311
|
+
* @category Array
|
|
312
|
+
*/
|
|
313
|
+
declare function dropLast<T>(n: number): (array: ReadonlyArray<T>) => Array<T>;
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Removes first `n` elements from the `array`.
|
|
317
|
+
* @param array the target array
|
|
318
|
+
* @param n the number of elements to skip
|
|
319
|
+
* @signature
|
|
320
|
+
* P.drop(array, n)
|
|
321
|
+
* @example
|
|
322
|
+
* P.drop([1, 2, 3, 4, 5], 2) // => [3, 4, 5]
|
|
323
|
+
* @dataFirst
|
|
324
|
+
* @pipeable
|
|
325
|
+
* @category Array
|
|
326
|
+
*/
|
|
327
|
+
declare function drop<T>(array: ReadonlyArray<T>, n: number): Array<T>;
|
|
328
|
+
/**
|
|
329
|
+
* Removes first `n` elements from the `array`.
|
|
330
|
+
* @param n the number of elements to skip
|
|
331
|
+
* @signature
|
|
332
|
+
* P.drop(n)(array)
|
|
333
|
+
* @example
|
|
334
|
+
* P.drop(2)([1, 2, 3, 4, 5]) // => [3, 4, 5]
|
|
335
|
+
* @dataLast
|
|
336
|
+
* @pipeable
|
|
337
|
+
* @category Array
|
|
338
|
+
*/
|
|
339
|
+
declare function drop<T>(n: number): (array: ReadonlyArray<T>) => Array<T>;
|
|
340
|
+
declare namespace drop {
|
|
341
|
+
function lazy<T>(n: number): (value: T) => LazyResult<T>;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Filter the elements of an array that meet the condition specified in a callback function.
|
|
346
|
+
* @param array The array to filter.
|
|
347
|
+
* @param fn the callback function.
|
|
348
|
+
* @signature
|
|
349
|
+
* P.filter(array, fn)
|
|
350
|
+
* P.filter.indexed(array, fn)
|
|
351
|
+
* @example
|
|
352
|
+
* P.filter([1, 2, 3], x => x % 2 === 1) // => [1, 3]
|
|
353
|
+
* P.filter.indexed([1, 2, 3], (x, i, array) => x % 2 === 1) // => [1, 3]
|
|
354
|
+
* @dataFirst
|
|
355
|
+
* @indexed
|
|
356
|
+
* @pipeable
|
|
357
|
+
* @category Array
|
|
358
|
+
*/
|
|
359
|
+
declare function filter<T, S extends T>(array: ReadonlyArray<T>, fn: (value: T) => value is S): Array<S>;
|
|
360
|
+
declare function filter<T>(array: ReadonlyArray<T>, fn: Pred<T, boolean>): Array<T>;
|
|
361
|
+
/**
|
|
362
|
+
* Filter the elements of an array that meet the condition specified in a callback function.
|
|
363
|
+
* @param fn the callback function.
|
|
364
|
+
* @signature
|
|
365
|
+
* P.filter(fn)(array)
|
|
366
|
+
* P.filter.indexed(fn)(array)
|
|
367
|
+
* @example
|
|
368
|
+
* P.pipe([1, 2, 3], P.filter(x => x % 2 === 1)) // => [1, 3]
|
|
369
|
+
* P.pipe([1, 2, 3], P.filter.indexed((x, i) => x % 2 === 1)) // => [1, 3]
|
|
370
|
+
* @dataLast
|
|
371
|
+
* @indexed
|
|
372
|
+
* @pipeable
|
|
373
|
+
* @category Array
|
|
374
|
+
*/
|
|
375
|
+
declare function filter<T, S extends T>(fn: (input: T) => input is S): (array: ReadonlyArray<T>) => Array<S>;
|
|
376
|
+
declare function filter<T>(fn: Pred<T, boolean>): (array: ReadonlyArray<T>) => Array<T>;
|
|
377
|
+
declare namespace filter {
|
|
378
|
+
function indexed<T, S extends T>(array: ReadonlyArray<T>, fn: (input: T, index: number, array: Array<T>) => input is S): Array<S>;
|
|
379
|
+
function indexed<T>(array: ReadonlyArray<T>, fn: PredIndexed<T, boolean>): Array<T>;
|
|
380
|
+
/**
|
|
381
|
+
* @dataLast
|
|
382
|
+
*/
|
|
383
|
+
function indexed<T, S extends T>(fn: (input: T, index: number, array: Array<T>) => input is S): (array: ReadonlyArray<T>) => Array<S>;
|
|
384
|
+
function indexed<T>(fn: PredIndexed<T, boolean>): (array: ReadonlyArray<T>) => Array<T>;
|
|
385
|
+
const lazy: <T>(fn: PredIndexedOptional<T, boolean>) => (value: T, index?: number | undefined, array?: T[] | undefined) => LazyResult<T>;
|
|
386
|
+
const lazyIndexed: (<T>(fn: PredIndexedOptional<T, boolean>) => (value: T, index?: number | undefined, array?: T[] | undefined) => LazyResult<T>) & {
|
|
387
|
+
indexed: true;
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* Returns the index of the first element in the array where predicate is true, and -1 otherwise.
|
|
393
|
+
* @param items the array
|
|
394
|
+
* @param fn the predicate
|
|
395
|
+
* @signature
|
|
396
|
+
* P.findIndex(items, fn)
|
|
397
|
+
* P.findIndex.indexed(items, fn)
|
|
398
|
+
* @example
|
|
399
|
+
* P.findIndex([1, 3, 4, 6], n => n % 2 === 0) // => 2
|
|
400
|
+
* P.findIndex.indexed([1, 3, 4, 6], (n, i) => n % 2 === 0) // => 2
|
|
401
|
+
* @dataFirst
|
|
402
|
+
* @indexed
|
|
403
|
+
* @pipeable
|
|
404
|
+
* @category Array
|
|
405
|
+
*/
|
|
406
|
+
declare function findIndex<T>(items: ReadonlyArray<T>, fn: Pred<T, boolean>): number;
|
|
407
|
+
/**
|
|
408
|
+
* Returns the index of the first element in the array where predicate is true, and -1 otherwise.
|
|
409
|
+
* @param fn the predicate
|
|
410
|
+
* @signature
|
|
411
|
+
* P.findIndex(fn)(items)
|
|
412
|
+
* P.findIndex.indexed(fn)(items)
|
|
413
|
+
* @example
|
|
414
|
+
* P.pipe(
|
|
415
|
+
* [1, 3, 4, 6],
|
|
416
|
+
* P.findIndex(n => n % 2 === 0)
|
|
417
|
+
* ) // => 2
|
|
418
|
+
* P.pipe(
|
|
419
|
+
* [1, 3, 4, 6],
|
|
420
|
+
* P.findIndex.indexed((n, i) => n % 2 === 0)
|
|
421
|
+
* ) // => 2
|
|
422
|
+
* @dataLast
|
|
423
|
+
* @indexed
|
|
424
|
+
* @pipeable
|
|
425
|
+
* @category Array
|
|
426
|
+
*/
|
|
427
|
+
declare function findIndex<T>(fn: Pred<T, boolean>): (items: ReadonlyArray<T>) => number;
|
|
428
|
+
declare namespace findIndex {
|
|
429
|
+
function indexed<T>(array: ReadonlyArray<T>, fn: PredIndexed<T, boolean>): number;
|
|
430
|
+
function indexed<T>(fn: PredIndexed<T, boolean>): (array: ReadonlyArray<T>) => number;
|
|
431
|
+
const lazy: (<T>(fn: PredIndexedOptional<T, boolean>) => (value: T, index?: number | undefined, array?: T[] | undefined) => {
|
|
432
|
+
done: boolean;
|
|
433
|
+
hasNext: boolean;
|
|
434
|
+
next: number;
|
|
435
|
+
} | {
|
|
436
|
+
done: boolean;
|
|
437
|
+
hasNext: boolean;
|
|
438
|
+
next?: undefined;
|
|
439
|
+
}) & {
|
|
440
|
+
single: true;
|
|
441
|
+
};
|
|
442
|
+
const lazyIndexed: (<T>(fn: PredIndexedOptional<T, boolean>) => (value: T, index?: number | undefined, array?: T[] | undefined) => {
|
|
443
|
+
done: boolean;
|
|
444
|
+
hasNext: boolean;
|
|
445
|
+
next: number;
|
|
446
|
+
} | {
|
|
447
|
+
done: boolean;
|
|
448
|
+
hasNext: boolean;
|
|
449
|
+
next?: undefined;
|
|
450
|
+
}) & {
|
|
451
|
+
indexed: true;
|
|
452
|
+
} & {
|
|
453
|
+
single: true;
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* Returns the index of the last element in the array where predicate is true, and -1 otherwise.
|
|
459
|
+
* @param array the array
|
|
460
|
+
* @param fn the predicate
|
|
461
|
+
* @signature
|
|
462
|
+
* P.findLastIndex(items, fn)
|
|
463
|
+
* P.findLastIndex.indexed(items, fn)
|
|
464
|
+
* @example
|
|
465
|
+
* P.findLastIndex([1, 3, 4, 6], n => n % 2 === 1) // => 1
|
|
466
|
+
* P.findLastIndex.indexed([1, 3, 4, 6], (n, i) => n % 2 === 1) // => 1
|
|
467
|
+
* @dataFirst
|
|
468
|
+
* @indexed
|
|
469
|
+
* @pipeable
|
|
470
|
+
* @category Array
|
|
471
|
+
*/
|
|
472
|
+
declare function findLastIndex<T>(array: ReadonlyArray<T>, fn: Pred<T, boolean>): number;
|
|
473
|
+
/**
|
|
474
|
+
* Returns the index of the last element in the array where predicate is true, and -1 otherwise.
|
|
475
|
+
* @param fn the predicate
|
|
476
|
+
* @signature
|
|
477
|
+
* P.findLastIndex(fn)(items)
|
|
478
|
+
* P.findLastIndex.indexed(fn)(items)
|
|
479
|
+
* @example
|
|
480
|
+
* P.pipe(
|
|
481
|
+
* [1, 3, 4, 6],
|
|
482
|
+
* P.findLastIndex(n => n % 2 === 1)
|
|
483
|
+
* ) // => 1
|
|
484
|
+
* P.pipe(
|
|
485
|
+
* [1, 3, 4, 6],
|
|
486
|
+
* P.findLastIndex.indexed((n, i) => n % 2 === 1)
|
|
487
|
+
* ) // => 1
|
|
488
|
+
* @dataLast
|
|
489
|
+
* @indexed
|
|
490
|
+
* @pipeable
|
|
491
|
+
* @category Array
|
|
492
|
+
*/
|
|
493
|
+
declare function findLastIndex<T>(fn: Pred<T, boolean>): (array: ReadonlyArray<T>) => number;
|
|
494
|
+
declare namespace findLastIndex {
|
|
495
|
+
function indexed<T>(array: ReadonlyArray<T>, fn: PredIndexed<T, boolean>): number;
|
|
496
|
+
function indexed<T>(fn: PredIndexed<T, boolean>): (array: ReadonlyArray<T>) => number;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* Returns the value of the last element in the array where predicate is true, and undefined
|
|
501
|
+
* otherwise.
|
|
502
|
+
* @param array the array
|
|
503
|
+
* @param fn the predicate
|
|
504
|
+
* @signature
|
|
505
|
+
* P.findLast(items, fn)
|
|
506
|
+
* P.findLast.indexed(items, fn)
|
|
507
|
+
* @example
|
|
508
|
+
* P.findLast([1, 3, 4, 6], n => n % 2 === 1) // => 3
|
|
509
|
+
* P.findLast.indexed([1, 3, 4, 6], (n, i) => n % 2 === 1) // => 3
|
|
510
|
+
* @dataFirst
|
|
511
|
+
* @indexed
|
|
512
|
+
* @pipeable
|
|
513
|
+
* @category Array
|
|
514
|
+
*/
|
|
515
|
+
declare function findLast<T>(array: ReadonlyArray<T>, fn: Pred<T, boolean>): T | undefined;
|
|
516
|
+
/**
|
|
517
|
+
* Returns the value of the last element in the array where predicate is true, and undefined
|
|
518
|
+
* otherwise.
|
|
519
|
+
* @param fn the predicate
|
|
520
|
+
* @signature
|
|
521
|
+
* P.findLast(fn)(items)
|
|
522
|
+
* P.findLast.indexed(fn)(items)
|
|
523
|
+
* @example
|
|
524
|
+
* P.pipe(
|
|
525
|
+
* [1, 3, 4, 6],
|
|
526
|
+
* P.findLast(n => n % 2 === 1)
|
|
527
|
+
* ) // => 3
|
|
528
|
+
* P.pipe(
|
|
529
|
+
* [1, 3, 4, 6],
|
|
530
|
+
* P.findLast.indexed((n, i) => n % 2 === 1)
|
|
531
|
+
* ) // => 3
|
|
532
|
+
* @dataLast
|
|
533
|
+
* @indexed
|
|
534
|
+
* @pipeable
|
|
535
|
+
* @category Array
|
|
536
|
+
*/
|
|
537
|
+
declare function findLast<T = never>(fn: Pred<T, boolean>): (array: ReadonlyArray<T>) => T | undefined;
|
|
538
|
+
declare namespace findLast {
|
|
539
|
+
function indexed<T>(array: ReadonlyArray<T>, fn: PredIndexed<T, boolean>): T | undefined;
|
|
540
|
+
function indexed<T>(fn: PredIndexed<T, boolean>): (array: ReadonlyArray<T>) => T | undefined;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
/**
|
|
544
|
+
* Returns the value of the first element in the array where predicate is true, and undefined otherwise.
|
|
545
|
+
* @param items the array
|
|
546
|
+
* @param fn the predicate
|
|
547
|
+
* @signature
|
|
548
|
+
* P.find(items, fn)
|
|
549
|
+
* P.find.indexed(items, fn)
|
|
550
|
+
* @example
|
|
551
|
+
* P.find([1, 3, 4, 6], n => n % 2 === 0) // => 4
|
|
552
|
+
* P.find.indexed([1, 3, 4, 6], (n, i) => n % 2 === 0) // => 4
|
|
553
|
+
* @dataFirst
|
|
554
|
+
* @indexed
|
|
555
|
+
* @pipeable
|
|
556
|
+
* @category Array
|
|
557
|
+
*/
|
|
558
|
+
declare function find<T>(items: ReadonlyArray<T>, fn: Pred<T, boolean>): T | undefined;
|
|
559
|
+
/**
|
|
560
|
+
* Returns the value of the first element in the array where predicate is true, and undefined otherwise.
|
|
561
|
+
* @param fn the predicate
|
|
562
|
+
* @signature
|
|
563
|
+
* P.find(fn)(items)
|
|
564
|
+
* P.find.indexed(fn)(items)
|
|
565
|
+
* @example
|
|
566
|
+
* P.pipe(
|
|
567
|
+
* [1, 3, 4, 6],
|
|
568
|
+
* P.find(n => n % 2 === 0)
|
|
569
|
+
* ) // => 4
|
|
570
|
+
* P.pipe(
|
|
571
|
+
* [1, 3, 4, 6],
|
|
572
|
+
* P.find.indexed((n, i) => n % 2 === 0)
|
|
573
|
+
* ) // => 4
|
|
574
|
+
* @dataLast
|
|
575
|
+
* @indexed
|
|
576
|
+
* @pipeable
|
|
577
|
+
* @category Array
|
|
578
|
+
*/
|
|
579
|
+
declare function find<T = never>(fn: Pred<T, boolean>): (array: ReadonlyArray<T>) => T | undefined;
|
|
580
|
+
declare namespace find {
|
|
581
|
+
function indexed<T>(array: ReadonlyArray<T>, fn: PredIndexed<T, boolean>): T | undefined;
|
|
582
|
+
function indexed<T>(fn: PredIndexed<T, boolean>): (array: ReadonlyArray<T>) => T | undefined;
|
|
583
|
+
const lazy: (<T>(fn: PredIndexedOptional<T, boolean>) => (value: T, index?: number | undefined, array?: T[] | undefined) => {
|
|
584
|
+
done: boolean;
|
|
585
|
+
hasNext: boolean;
|
|
586
|
+
next: T;
|
|
587
|
+
}) & {
|
|
588
|
+
single: true;
|
|
589
|
+
};
|
|
590
|
+
const lazyIndexed: (<T>(fn: PredIndexedOptional<T, boolean>) => (value: T, index?: number | undefined, array?: T[] | undefined) => {
|
|
591
|
+
done: boolean;
|
|
592
|
+
hasNext: boolean;
|
|
593
|
+
next: T;
|
|
594
|
+
}) & {
|
|
595
|
+
indexed: true;
|
|
596
|
+
} & {
|
|
597
|
+
single: true;
|
|
598
|
+
};
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
type FirstOut<T extends IterableContainer> = T extends [] ? undefined : T extends readonly [unknown, ...Array<unknown>] ? T[0] : T extends readonly [...infer Pre, infer Last] ? Pre[0] | Last : T[0] | undefined;
|
|
602
|
+
/**
|
|
603
|
+
* Gets the first element of `array`.
|
|
604
|
+
* Note: In `pipe`, use `first()` form instead of `first`. Otherwise, the inferred type is lost.
|
|
605
|
+
* @param array the array
|
|
606
|
+
* @signature
|
|
607
|
+
* P.first(array)
|
|
608
|
+
* @example
|
|
609
|
+
* P.first([1, 2, 3]) // => 1
|
|
610
|
+
* P.first([]) // => undefined
|
|
611
|
+
* P.pipe(
|
|
612
|
+
* [1, 2, 4, 8, 16],
|
|
613
|
+
* P.filter(x => x > 3),
|
|
614
|
+
* P.first(),
|
|
615
|
+
* x => x + 1
|
|
616
|
+
* ); // => 5
|
|
617
|
+
*
|
|
618
|
+
* @category Array
|
|
619
|
+
* @pipeable
|
|
620
|
+
*/
|
|
621
|
+
declare function first<T extends IterableContainer>(array: Readonly<T>): FirstOut<T>;
|
|
622
|
+
declare function first<T extends IterableContainer>(): (array: Readonly<T>) => FirstOut<T>;
|
|
623
|
+
declare namespace first {
|
|
624
|
+
function lazy<T>(): (value: T) => {
|
|
625
|
+
done: boolean;
|
|
626
|
+
hasNext: boolean;
|
|
627
|
+
next: T;
|
|
628
|
+
};
|
|
629
|
+
namespace lazy {
|
|
630
|
+
const single = true;
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
/**
|
|
635
|
+
* Map each element of an array into an object using a defined callback function and flatten the result.
|
|
636
|
+
* @param array The array to map.
|
|
637
|
+
* @param fn The mapping function, which should return an Array of key-value pairs, similar to Object.fromEntries
|
|
638
|
+
* @returns The new mapped object.
|
|
639
|
+
* @signature
|
|
640
|
+
* P.flatMapToObj(array, fn)
|
|
641
|
+
* P.flatMapToObj.indexed(array, fn)
|
|
642
|
+
* @example
|
|
643
|
+
* P.flatMapToObj([1, 2, 3], (x) =>
|
|
644
|
+
* x % 2 === 1 ? [[String(x), x]] : []
|
|
645
|
+
* ) // => {1: 1, 3: 3}
|
|
646
|
+
* P.flatMapToObj.indexed(['a', 'b'], (x, i) => [
|
|
647
|
+
* [x, i],
|
|
648
|
+
* [x + x, i + i],
|
|
649
|
+
* ]) // => {a: 0, aa: 0, b: 1, bb: 2}
|
|
650
|
+
* @dataFirst
|
|
651
|
+
* @indexed
|
|
652
|
+
* @category Array
|
|
653
|
+
*/
|
|
654
|
+
declare function flatMapToObj<T, K extends keyof any, V>(array: ReadonlyArray<T>, fn: (element: T) => Array<[K, V]>): Record<K, V>;
|
|
655
|
+
/**
|
|
656
|
+
* Map each element of an array into an object using a defined callback function and flatten the result.
|
|
657
|
+
* @param fn The mapping function, which should return an Array of key-value pairs, similar to Object.fromEntries
|
|
658
|
+
* @returns The new mapped object.
|
|
659
|
+
* @signature
|
|
660
|
+
* P.flatMapToObj(fn)(array)
|
|
661
|
+
* P.flatMapToObj(fn)(array)
|
|
662
|
+
* @example
|
|
663
|
+
* P.pipe(
|
|
664
|
+
* [1, 2, 3],
|
|
665
|
+
* P.flatMapToObj(x => (x % 2 === 1 ? [[String(x), x]] : []))
|
|
666
|
+
* ) // => {1: 1, 3: 3}
|
|
667
|
+
* P.pipe(
|
|
668
|
+
* ['a', 'b'],
|
|
669
|
+
* P.flatMapToObj.indexed((x, i) => [
|
|
670
|
+
* [x, i],
|
|
671
|
+
* [x + x, i + i],
|
|
672
|
+
* ])
|
|
673
|
+
* ) // => {a: 0, aa: 0, b: 1, bb: 2}
|
|
674
|
+
* @dataLast
|
|
675
|
+
* @indexed
|
|
676
|
+
* @category Array
|
|
677
|
+
*/
|
|
678
|
+
declare function flatMapToObj<T, K extends keyof any, V>(fn: (element: T) => Array<[K, V]>): (array: ReadonlyArray<T>) => Record<K, V>;
|
|
679
|
+
declare namespace flatMapToObj {
|
|
680
|
+
function indexed<T, K extends keyof any, V>(array: ReadonlyArray<T>, fn: (element: T, index: number, array: ReadonlyArray<T>) => Array<[K, V]>): Record<K, V>;
|
|
681
|
+
function indexed<T, K extends keyof any, V>(fn: (element: T, index: number, array: ReadonlyArray<T>) => Array<[K, V]>): (array: ReadonlyArray<T>) => Record<K, V>;
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
/**
|
|
685
|
+
* Map each element of an array using a defined callback function and flatten the mapped result.
|
|
686
|
+
* @param array The array to map.
|
|
687
|
+
* @param fn The function mapper.
|
|
688
|
+
* @signature
|
|
689
|
+
* P.flatMap(array, fn)
|
|
690
|
+
* @example
|
|
691
|
+
* P.flatMap([1, 2, 3], x => [x, x * 10]) // => [1, 10, 2, 20, 3, 30]
|
|
692
|
+
* @dataFirst
|
|
693
|
+
* @pipeable
|
|
694
|
+
* @category Array
|
|
695
|
+
*/
|
|
696
|
+
declare function flatMap<T, K>(array: ReadonlyArray<T>, fn: (input: T) => K | Array<K>): Array<K>;
|
|
697
|
+
/**
|
|
698
|
+
* Map each element of an array using a defined callback function and flatten the mapped result.
|
|
699
|
+
* @param fn The function mapper.
|
|
700
|
+
* @signature
|
|
701
|
+
* P.flatMap(fn)(array)
|
|
702
|
+
* @example
|
|
703
|
+
* P.pipe([1, 2, 3], P.flatMap(x => [x, x * 10])) // => [1, 10, 2, 20, 3, 30]
|
|
704
|
+
* @dataLast
|
|
705
|
+
* @pipeable
|
|
706
|
+
* @category Array
|
|
707
|
+
*/
|
|
708
|
+
declare function flatMap<T, K>(fn: (input: T) => K | Array<K>): (array: ReadonlyArray<T>) => Array<K>;
|
|
709
|
+
declare namespace flatMap {
|
|
710
|
+
function lazy<T, K>(fn: (input: T) => K | Array<K>): (value: T) => {
|
|
711
|
+
done: boolean;
|
|
712
|
+
hasNext: boolean;
|
|
713
|
+
hasMany: boolean;
|
|
714
|
+
next: K[];
|
|
715
|
+
} | {
|
|
716
|
+
done: boolean;
|
|
717
|
+
hasNext: boolean;
|
|
718
|
+
next: K;
|
|
719
|
+
hasMany?: undefined;
|
|
720
|
+
};
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
type FlattenDeep<T> = T extends ReadonlyArray<infer K> ? FlattenDeep2<K> : T;
|
|
724
|
+
type FlattenDeep2<T> = T extends ReadonlyArray<infer K> ? FlattenDeep3<K> : T;
|
|
725
|
+
type FlattenDeep3<T> = T extends ReadonlyArray<infer K> ? FlattenDeep4<K> : T;
|
|
726
|
+
type FlattenDeep4<T> = T extends ReadonlyArray<infer K> ? K : T;
|
|
727
|
+
/**
|
|
728
|
+
* Recursively flattens `array`.
|
|
729
|
+
* Note: In `pipe`, use `flattenDeep()` form instead of `flattenDeep`. Otherwise, the inferred type is lost.
|
|
730
|
+
* @param items the target array
|
|
731
|
+
* @signature P.flattenDeep(array)
|
|
732
|
+
* @example
|
|
733
|
+
* P.flattenDeep([[1, 2], [[3], [4, 5]]]) // => [1, 2, 3, 4, 5]
|
|
734
|
+
* P.pipe(
|
|
735
|
+
* [[1, 2], [[3], [4, 5]]],
|
|
736
|
+
* P.flattenDeep(),
|
|
737
|
+
* ); // => [1, 2, 3, 4, 5]
|
|
738
|
+
* @category Array
|
|
739
|
+
* @pipeable
|
|
740
|
+
*/
|
|
741
|
+
declare function flattenDeep<T>(items: ReadonlyArray<T>): Array<FlattenDeep<T>>;
|
|
742
|
+
declare function flattenDeep<T>(): (items: ReadonlyArray<T>) => Array<FlattenDeep<T>>;
|
|
743
|
+
declare namespace flattenDeep {
|
|
744
|
+
function lazy(): (value: any) => LazyResult<any>;
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
type Flatten<T> = T extends ReadonlyArray<infer K> ? K : T;
|
|
748
|
+
/**
|
|
749
|
+
* Flattens `array` a single level deep.
|
|
750
|
+
* Note: In `pipe`, use `flatten()` form instead of `flatten`. Otherwise, the inferred type is lost.
|
|
751
|
+
* @param items the target array
|
|
752
|
+
* @signature P.flatten(array)
|
|
753
|
+
* @example
|
|
754
|
+
* P.flatten([[1, 2], [3], [4, 5]]) // => [1, 2, 3, 4, 5]
|
|
755
|
+
* P.pipe(
|
|
756
|
+
* [[1, 2], [3], [4, 5]],
|
|
757
|
+
* P.flatten(),
|
|
758
|
+
* ); // => [1, 2, 3, 4, 5]
|
|
759
|
+
* @category Array
|
|
760
|
+
* @pipeable
|
|
761
|
+
*/
|
|
762
|
+
declare function flatten<T>(items: ReadonlyArray<T>): Array<Flatten<T>>;
|
|
763
|
+
declare function flatten<T>(): (items: ReadonlyArray<T>) => Array<Flatten<T>>;
|
|
764
|
+
declare namespace flatten {
|
|
765
|
+
function lazy<T>(): (next: T) => LazyResult<any>;
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
/**
|
|
769
|
+
* Iterate an array using a defined callback function. The original array is returned instead of `void`.
|
|
770
|
+
* @param array The array.
|
|
771
|
+
* @param fn The callback function.
|
|
772
|
+
* @returns The original array
|
|
773
|
+
* @signature
|
|
774
|
+
* P.forEach(array, fn)
|
|
775
|
+
* P.forEach.indexed(array, fn)
|
|
776
|
+
* @example
|
|
777
|
+
* P.forEach([1, 2, 3], x => {
|
|
778
|
+
* console.log(x)
|
|
779
|
+
* }) // => [1, 2, 3]
|
|
780
|
+
* P.forEach.indexed([1, 2, 3], (x, i) => {
|
|
781
|
+
* console.log(x, i)
|
|
782
|
+
* }) // => [1, 2, 3]
|
|
783
|
+
* @dataFirst
|
|
784
|
+
* @indexed
|
|
785
|
+
* @pipeable
|
|
786
|
+
* @category Array
|
|
787
|
+
*/
|
|
788
|
+
declare function forEach<T>(array: ReadonlyArray<T>, fn: Pred<T, void>): Array<T>;
|
|
789
|
+
/**
|
|
790
|
+
* Iterate an array using a defined callback function. The original array is returned instead of `void`.
|
|
791
|
+
* @param fn the function mapper
|
|
792
|
+
* @signature
|
|
793
|
+
* P.forEach(fn)(array)
|
|
794
|
+
* P.forEach.indexed(fn)(array)
|
|
795
|
+
* @example
|
|
796
|
+
* P.pipe(
|
|
797
|
+
* [1, 2, 3],
|
|
798
|
+
* P.forEach(x => {
|
|
799
|
+
* console.log(x)
|
|
800
|
+
* })
|
|
801
|
+
* ) // => [1, 2, 3]
|
|
802
|
+
* P.pipe(
|
|
803
|
+
* [1, 2, 3],
|
|
804
|
+
* P.forEach.indexed((x, i) => {
|
|
805
|
+
* console.log(x, i)
|
|
806
|
+
* })
|
|
807
|
+
* ) // => [1, 2, 3]
|
|
808
|
+
* @dataLast
|
|
809
|
+
* @indexed
|
|
810
|
+
* @pipeable
|
|
811
|
+
* @category Array
|
|
812
|
+
*/
|
|
813
|
+
declare function forEach<T>(fn: Pred<T, void>): (array: ReadonlyArray<T>) => Array<T>;
|
|
814
|
+
declare namespace forEach {
|
|
815
|
+
function indexed<T>(array: ReadonlyArray<T>, fn: PredIndexed<T, void>): Array<T>;
|
|
816
|
+
function indexed<T>(fn: PredIndexed<T, void>): (array: ReadonlyArray<T>) => Array<T>;
|
|
817
|
+
const lazy: <T>(fn: PredIndexedOptional<T, void>) => (value: T, index?: number | undefined, array?: T[] | undefined) => LazyResult<T>;
|
|
818
|
+
const lazyIndexed: (<T>(fn: PredIndexedOptional<T, void>) => (value: T, index?: number | undefined, array?: T[] | undefined) => LazyResult<T>) & {
|
|
819
|
+
indexed: true;
|
|
820
|
+
};
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
interface Strict$5 {
|
|
824
|
+
<Value, Key extends PropertyKey = PropertyKey>(items: ReadonlyArray<Value>, fn: (item: Value) => Key | undefined): StrictOut$2<Value, Key>;
|
|
825
|
+
<Value, Key extends PropertyKey = PropertyKey>(fn: (item: Value) => Key | undefined): (items: ReadonlyArray<Value>) => StrictOut$2<Value, Key>;
|
|
826
|
+
readonly indexed: {
|
|
827
|
+
<Value, Key extends PropertyKey = PropertyKey>(items: ReadonlyArray<Value>, fn: PredIndexed<Value, Key | undefined>): StrictOut$2<Value, Key>;
|
|
828
|
+
<Value, Key extends PropertyKey = PropertyKey>(fn: PredIndexed<Value, Key | undefined>): (items: ReadonlyArray<Value>) => StrictOut$2<Value, Key>;
|
|
829
|
+
};
|
|
830
|
+
}
|
|
831
|
+
type StrictOut$2<Value, Key extends PropertyKey = PropertyKey> = string extends Key ? Record<Key, NonEmptyArray<Value>> : number extends Key ? Record<Key, NonEmptyArray<Value>> : symbol extends Key ? Record<Key, NonEmptyArray<Value>> : Partial<Record<Key, NonEmptyArray<Value>>>;
|
|
832
|
+
/**
|
|
833
|
+
* Splits a collection into sets, grouped by the result of running each value through `fn`.
|
|
834
|
+
* @param items the items to group
|
|
835
|
+
* @param fn the grouping function. When `undefined` is returned the item would
|
|
836
|
+
* be skipped and not grouped under any key.
|
|
837
|
+
* @signature
|
|
838
|
+
* P.groupBy(array, fn)
|
|
839
|
+
* P.groupBy.strict(array, fn)
|
|
840
|
+
* @example
|
|
841
|
+
* P.groupBy(['one', 'two', 'three'], x => x.length) // => {3: ['one', 'two'], 5: ['three']}
|
|
842
|
+
* P.groupBy.strict([{a: 'cat'}, {a: 'dog'}] as const, prop('a')) // => {cat: [{a: 'cat'}], dog: [{a: 'dog'}]} typed Partial<Record<'cat' | 'dog', NonEmptyArray<{a: 'cat' | 'dog'}>>>
|
|
843
|
+
* P.groupBy([0, 1], x => x % 2 === 0 ? 'even' : undefined) // => {even: [0]}
|
|
844
|
+
* @dataFirst
|
|
845
|
+
* @indexed
|
|
846
|
+
* @strict
|
|
847
|
+
* @category Array
|
|
848
|
+
*/
|
|
849
|
+
declare function groupBy<T>(items: ReadonlyArray<T>, fn: (item: T) => PropertyKey | undefined): Record<PropertyKey, NonEmptyArray<T>>;
|
|
850
|
+
declare function groupBy<T>(fn: (item: T) => PropertyKey | undefined): (array: ReadonlyArray<T>) => Record<PropertyKey, NonEmptyArray<T>>;
|
|
851
|
+
declare namespace groupBy {
|
|
852
|
+
function indexed<T>(array: ReadonlyArray<T>, fn: PredIndexed<T, PropertyKey | undefined>): Record<string, NonEmptyArray<T>>;
|
|
853
|
+
function indexed<T>(fn: PredIndexed<T, PropertyKey | undefined>): (array: ReadonlyArray<T>) => Record<string, NonEmptyArray<T>>;
|
|
854
|
+
const strict: Strict$5;
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
/**
|
|
858
|
+
* Converts a list of objects into an object indexing the objects by the given key.
|
|
859
|
+
* @param array the array
|
|
860
|
+
* @param fn the indexing function
|
|
861
|
+
* @signature
|
|
862
|
+
* P.indexBy(array, fn)
|
|
863
|
+
* @example
|
|
864
|
+
* P.indexBy(['one', 'two', 'three'], x => x.length) // => {3: 'two', 5: 'three'}
|
|
865
|
+
* @dataFirst
|
|
866
|
+
* @indexed
|
|
867
|
+
* @category Array
|
|
868
|
+
*/
|
|
869
|
+
declare function indexBy<T>(array: ReadonlyArray<T>, fn: (item: T) => any): Record<string, T>;
|
|
870
|
+
/**
|
|
871
|
+
* Converts a list of objects into an object indexing the objects by the given key.
|
|
872
|
+
* @param fn the indexing function
|
|
873
|
+
* @signature
|
|
874
|
+
* P.indexBy(fn)(array)
|
|
875
|
+
* @example
|
|
876
|
+
* P.pipe(
|
|
877
|
+
* ['one', 'two', 'three'],
|
|
878
|
+
* P.indexBy(x => x.length)
|
|
879
|
+
* ) // => {3: 'two', 5: 'three'}
|
|
880
|
+
* @dataLast
|
|
881
|
+
* @indexed
|
|
882
|
+
* @category Array
|
|
883
|
+
*/
|
|
884
|
+
declare function indexBy<T>(fn: (item: T) => any): (array: ReadonlyArray<T>) => Record<string, T>;
|
|
885
|
+
declare namespace indexBy {
|
|
886
|
+
function indexed<T>(array: ReadonlyArray<T>, fn: PredIndexed<T, any>): Record<string, T>;
|
|
887
|
+
function indexed<T>(fn: PredIndexed<T, any>): (array: ReadonlyArray<T>) => Record<string, T>;
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
/**
|
|
891
|
+
* Returns a list of elements that exist in both array.
|
|
892
|
+
* @param array the source array
|
|
893
|
+
* @param other the second array
|
|
894
|
+
* @signature
|
|
895
|
+
* P.intersection(array, other)
|
|
896
|
+
* @example
|
|
897
|
+
* P.intersection([1, 2, 3], [2, 3, 5]) // => [2, 3]
|
|
898
|
+
* @dataFirst
|
|
899
|
+
* @category Array
|
|
900
|
+
* @pipeable
|
|
901
|
+
*/
|
|
902
|
+
declare function intersection<T>(array: ReadonlyArray<T>, other: ReadonlyArray<T>): Array<T>;
|
|
903
|
+
/**
|
|
904
|
+
* Returns a list of elements that exist in both array.
|
|
905
|
+
* @param other the second array
|
|
906
|
+
* @signature
|
|
907
|
+
* P.intersection(other)(array)
|
|
908
|
+
* @example
|
|
909
|
+
* P.intersection([2, 3, 5])([1, 2, 3]) // => [2, 3]
|
|
910
|
+
* @dataLast
|
|
911
|
+
* @category Array
|
|
912
|
+
* @pipeable
|
|
913
|
+
*/
|
|
914
|
+
declare function intersection<T, K>(other: ReadonlyArray<T>): (source: ReadonlyArray<K>) => Array<T>;
|
|
915
|
+
declare namespace intersection {
|
|
916
|
+
function lazy<T>(other: Array<T>): (value: T) => LazyResult<T>;
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
type Comparator<TFirst, TSecond> = (a: TFirst, b: TSecond) => boolean;
|
|
920
|
+
/**
|
|
921
|
+
* Returns a list of intersecting values based on a custom
|
|
922
|
+
* comparator function that compares elements of both arrays.
|
|
923
|
+
* @param array the source array
|
|
924
|
+
* @param other the second array
|
|
925
|
+
* @param comparator the custom comparator
|
|
926
|
+
* @signature
|
|
927
|
+
* P.intersectionWith(array, other, comparator)
|
|
928
|
+
* @example
|
|
929
|
+
* P.intersectionWith(
|
|
930
|
+
* [
|
|
931
|
+
* { id: 1, name: 'Ryan' },
|
|
932
|
+
* { id: 3, name: 'Emma' },
|
|
933
|
+
* ],
|
|
934
|
+
* [3, 5],
|
|
935
|
+
* (a, b) => a.id === b,
|
|
936
|
+
* ) // => [{ id: 3, name: 'Emma' }]
|
|
937
|
+
* @dataFirst
|
|
938
|
+
* @category Array
|
|
939
|
+
* @pipeable
|
|
940
|
+
*/
|
|
941
|
+
declare function intersectionWith<TFirst, TSecond>(array: ReadonlyArray<TFirst>, other: ReadonlyArray<TSecond>, comparator: Comparator<TFirst, TSecond>): Array<TFirst>;
|
|
942
|
+
/**
|
|
943
|
+
* Returns a list of intersecting values based on a custom
|
|
944
|
+
* comparator function that compares elements of both arrays.
|
|
945
|
+
* @param other the second array
|
|
946
|
+
* @param comparator the custom comparator
|
|
947
|
+
* @signature
|
|
948
|
+
* P.intersectionWith(other, comparator)(array)
|
|
949
|
+
* @example
|
|
950
|
+
* P.intersectionWith(
|
|
951
|
+
* [3, 5],
|
|
952
|
+
* (a, b) => a.id === b
|
|
953
|
+
* )([
|
|
954
|
+
* { id: 1, name: 'Ryan' },
|
|
955
|
+
* { id: 3, name: 'Emma' },
|
|
956
|
+
* ]); // => [{ id: 3, name: 'Emma' }]
|
|
957
|
+
* @dataLast
|
|
958
|
+
* @category Array
|
|
959
|
+
* @pipeable
|
|
960
|
+
*/
|
|
961
|
+
declare function intersectionWith<TFirst, TSecond>(other: ReadonlyArray<TSecond>,
|
|
962
|
+
/**
|
|
963
|
+
* type inference doesn't work properly for the comparator's first parameter
|
|
964
|
+
* in data last variant
|
|
965
|
+
*/
|
|
966
|
+
comparator: Comparator<TFirst, TSecond>): (array: ReadonlyArray<TFirst>) => Array<TFirst>;
|
|
967
|
+
declare namespace intersectionWith {
|
|
968
|
+
function lazy<TFirst, TSecond>(other: Array<TSecond>, comparator: Comparator<TFirst, TSecond>): (value: TFirst) => LazyResult<TFirst>;
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
type Joinable = bigint | boolean | number | string | null | undefined;
|
|
972
|
+
type Joined<T extends IterableContainer, Glue extends string> = T[number] extends never ? '' : T extends readonly [Joinable?] ? `${NullishCoalesce<T[0], ''>}` : T extends readonly [infer First, ...infer Tail] ? `${NullishCoalesce<First, ''>}${Glue}${Joined<Tail, Glue>}` : T extends readonly [...infer Head, infer Last] ? `${Joined<Head, Glue>}${Glue}${NullishCoalesce<Last, ''>}` : string;
|
|
973
|
+
type NullishCoalesce<T, Fallback> = T extends Joinable ? T extends undefined | null ? NonNullable<T> | Fallback : T : never;
|
|
974
|
+
/**
|
|
975
|
+
* Joins the elements of the array by: casting them to a string and
|
|
976
|
+
* concatenating them one to the other, with the provided glue string in between
|
|
977
|
+
* every two elements.
|
|
978
|
+
*
|
|
979
|
+
* When called on a tuple and with stricter item types (union of literal values,
|
|
980
|
+
* the result is strictly typed to the tuples shape and it's item types).
|
|
981
|
+
*
|
|
982
|
+
* @param data The array to join
|
|
983
|
+
* @param glue The string to put in between every two elements
|
|
984
|
+
* @signature
|
|
985
|
+
* P.join(data, glue)
|
|
986
|
+
* @example
|
|
987
|
+
* P.join([1,2,3], ",") // => "1,2,3" (typed `string`)
|
|
988
|
+
* P.join(['a','b','c'], "") // => "abc" (typed `string`)
|
|
989
|
+
* P.join(['hello', 'world'] as const, " ") // => "hello world" (typed `hello world`)
|
|
990
|
+
* @dataFirst
|
|
991
|
+
* @category Array
|
|
992
|
+
*/
|
|
993
|
+
declare function join<T extends ReadonlyArray<Joinable> | [], Glue extends string>(data: T, glue: Glue): Joined<T, Glue>;
|
|
994
|
+
/**
|
|
995
|
+
* Joins the elements of the array by: casting them to a string and
|
|
996
|
+
* concatenating them one to the other, with the provided glue string in between
|
|
997
|
+
* every two elements.
|
|
998
|
+
*
|
|
999
|
+
* When called on a tuple and with stricter item types (union of literal values,
|
|
1000
|
+
* the result is strictly typed to the tuples shape and it's item types).
|
|
1001
|
+
*
|
|
1002
|
+
* @param glue The string to put in between every two elements
|
|
1003
|
+
* @signature
|
|
1004
|
+
* P.join(glue)(data)
|
|
1005
|
+
* @example
|
|
1006
|
+
* P.pipe([1,2,3], P.join(",")) // => "1,2,3" (typed `string`)
|
|
1007
|
+
* P.pipe(['a','b','c'], P.join("")) // => "abc" (typed `string`)
|
|
1008
|
+
* P.pipe(['hello', 'world'] as const, P.join(" ")) // => "hello world" (typed `hello world`)
|
|
1009
|
+
* @dataLast
|
|
1010
|
+
* @category Array
|
|
1011
|
+
*/
|
|
1012
|
+
declare function join<T extends ReadonlyArray<Joinable> | [], Glue extends string>(glue: Glue): (data: T) => Joined<T, Glue>;
|
|
1013
|
+
|
|
1014
|
+
/**
|
|
1015
|
+
* Gets the last element of `array`.
|
|
1016
|
+
* Note: In `pipe`, use `last()` form instead of `last`. Otherwise, the inferred type is lost.
|
|
1017
|
+
* @param array the array
|
|
1018
|
+
* @signature
|
|
1019
|
+
* P.last(array)
|
|
1020
|
+
* @example
|
|
1021
|
+
* P.last([1, 2, 3]) // => 3
|
|
1022
|
+
* P.last([]) // => undefined
|
|
1023
|
+
* P.pipe(
|
|
1024
|
+
* [1, 2, 4, 8, 16],
|
|
1025
|
+
* P.filter(x => x > 3),
|
|
1026
|
+
* P.last(),
|
|
1027
|
+
* x => x + 1
|
|
1028
|
+
* ); // => 17
|
|
1029
|
+
*
|
|
1030
|
+
* @category Array
|
|
1031
|
+
* @pipeable
|
|
1032
|
+
*/
|
|
1033
|
+
declare function last<T>(array: NonEmptyArray<T>): T;
|
|
1034
|
+
declare function last<T>(array: ReadonlyArray<T>): T | undefined;
|
|
1035
|
+
declare function last<T>(): (array: ReadonlyArray<T>) => T | undefined;
|
|
1036
|
+
|
|
1037
|
+
type Enumerable<T> = ArrayLike<T> | Iterable<T>;
|
|
1038
|
+
/**
|
|
1039
|
+
* Counts values of the collection or iterable.
|
|
1040
|
+
* @param items The input data.
|
|
1041
|
+
* @signature
|
|
1042
|
+
* P.length(array)
|
|
1043
|
+
* @example
|
|
1044
|
+
* P.length([1, 2, 3]) // => 3
|
|
1045
|
+
* @category Array
|
|
1046
|
+
*/
|
|
1047
|
+
declare function length<T>(items: Enumerable<T>): number;
|
|
1048
|
+
declare function length<T>(): (items: Enumerable<T>) => number;
|
|
1049
|
+
|
|
1050
|
+
interface Strict$4 {
|
|
1051
|
+
<T extends IterableContainer, K>(items: T, mapper: Pred<T[number], K>): StrictOut$1<T, K>;
|
|
1052
|
+
<T extends IterableContainer, K>(mapper: Pred<T[number], K>): (items: T) => StrictOut$1<T, K>;
|
|
1053
|
+
readonly indexed: {
|
|
1054
|
+
<T extends IterableContainer, K>(items: T, mapper: PredIndexed<T[number], K>): StrictOut$1<T, K>;
|
|
1055
|
+
<T extends IterableContainer, K>(mapper: PredIndexed<T[number], K>): (items: T) => StrictOut$1<T, K>;
|
|
1056
|
+
};
|
|
1057
|
+
}
|
|
1058
|
+
type StrictOut$1<T extends IterableContainer, K> = {
|
|
1059
|
+
-readonly [P in keyof T]: K;
|
|
1060
|
+
};
|
|
1061
|
+
/**
|
|
1062
|
+
* Map each element of an array using a defined callback function. If the input
|
|
1063
|
+
* array is a tuple use the `strict` variant to maintain it's shape.
|
|
1064
|
+
* @param array The array to map.
|
|
1065
|
+
* @param fn The function mapper.
|
|
1066
|
+
* @returns The new mapped array.
|
|
1067
|
+
* @signature
|
|
1068
|
+
* P.map(array, fn)
|
|
1069
|
+
* P.map.indexed(array, fn)
|
|
1070
|
+
* P.map.strict(array, fn)
|
|
1071
|
+
* P.map.strict.indexed(array, fn)
|
|
1072
|
+
* @example
|
|
1073
|
+
* P.map([1, 2, 3], x => x * 2) // => [2, 4, 6], typed number[]
|
|
1074
|
+
* P.map.indexed([0, 0, 0], (x, i) => i) // => [0, 1, 2], typed number[]
|
|
1075
|
+
* P.map.strict([0, 0] as const, x => x + 1) // => [1, 1], typed [number, number]
|
|
1076
|
+
* P.map.strict.indexed([0, 0] as const, (x, i) => x + i) // => [0, 1], typed [number, number]
|
|
1077
|
+
* @dataFirst
|
|
1078
|
+
* @indexed
|
|
1079
|
+
* @pipeable
|
|
1080
|
+
* @strict
|
|
1081
|
+
* @category Array
|
|
1082
|
+
*/
|
|
1083
|
+
declare function map<T, K>(array: ReadonlyArray<T>, fn: Pred<T, K>): Array<K>;
|
|
1084
|
+
/**
|
|
1085
|
+
* Map each value of an object using a defined callback function.
|
|
1086
|
+
* @param fn the function mapper
|
|
1087
|
+
* @signature
|
|
1088
|
+
* P.map(fn)(array)
|
|
1089
|
+
* P.map.indexed(fn)(array)
|
|
1090
|
+
* @example
|
|
1091
|
+
* P.pipe([0, 1, 2], P.map(x => x * 2)) // => [0, 2, 4]
|
|
1092
|
+
* P.pipe([0, 0, 0], P.map.indexed((x, i) => i)) // => [0, 1, 2]
|
|
1093
|
+
* @dataLast
|
|
1094
|
+
* @indexed
|
|
1095
|
+
* @pipeable
|
|
1096
|
+
* @category Array
|
|
1097
|
+
*/
|
|
1098
|
+
declare function map<T, K>(fn: Pred<T, K>): (array: ReadonlyArray<T>) => Array<K>;
|
|
1099
|
+
declare namespace map {
|
|
1100
|
+
function indexed<T, K>(array: ReadonlyArray<T>, fn: PredIndexed<T, K>): Array<K>;
|
|
1101
|
+
function indexed<T, K>(fn: PredIndexed<T, K>): (array: ReadonlyArray<T>) => Array<K>;
|
|
1102
|
+
const lazy: <T, K>(fn: PredIndexedOptional<T, K>) => (value: T, index?: number | undefined, array?: T[] | undefined) => LazyResult<K>;
|
|
1103
|
+
const lazyIndexed: (<T, K>(fn: PredIndexedOptional<T, K>) => (value: T, index?: number | undefined, array?: T[] | undefined) => LazyResult<K>) & {
|
|
1104
|
+
indexed: true;
|
|
1105
|
+
};
|
|
1106
|
+
const strict: Strict$4;
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
/**
|
|
1110
|
+
* Map each element of an array into an object using a defined callback function.
|
|
1111
|
+
* @param array The array to map.
|
|
1112
|
+
* @param fn The mapping function, which should return a tuple of [key, value], similar to Object.fromEntries
|
|
1113
|
+
* @returns The new mapped object.
|
|
1114
|
+
* @signature
|
|
1115
|
+
* P.mapToObj(array, fn)
|
|
1116
|
+
* P.mapToObj.indexed(array, fn)
|
|
1117
|
+
* @example
|
|
1118
|
+
* P.mapToObj([1, 2, 3], x => [String(x), x * 2]) // => {1: 2, 2: 4, 3: 6}
|
|
1119
|
+
* P.mapToObj.indexed([0, 0, 0], (x, i) => [i, i]) // => {0: 0, 1: 1, 2: 2}
|
|
1120
|
+
* @dataFirst
|
|
1121
|
+
* @indexed
|
|
1122
|
+
* @category Array
|
|
1123
|
+
*/
|
|
1124
|
+
declare function mapToObj<T, K extends keyof any, V>(array: ReadonlyArray<T>, fn: (element: T) => [K, V]): Record<K, V>;
|
|
1125
|
+
/**
|
|
1126
|
+
* Map each element of an array into an object using a defined callback function.
|
|
1127
|
+
* @param fn The mapping function, which should return a tuple of [key, value], similar to Object.fromEntries
|
|
1128
|
+
* @returns The new mapped object.
|
|
1129
|
+
* @signature
|
|
1130
|
+
* P.mapToObj(fn)(array)
|
|
1131
|
+
* P.mapToObj.indexed(fn)(array)
|
|
1132
|
+
* @example
|
|
1133
|
+
* P.pipe(
|
|
1134
|
+
* [1, 2, 3],
|
|
1135
|
+
* P.mapToObj(x => [String(x), x * 2])
|
|
1136
|
+
* ) // => {1: 2, 2: 4, 3: 6}
|
|
1137
|
+
* P.pipe(
|
|
1138
|
+
* [0, 0, 0],
|
|
1139
|
+
* P.mapToObj.indexed((x, i) => [i, i])
|
|
1140
|
+
* ) // => {0: 0, 1: 1, 2: 2}
|
|
1141
|
+
* @dataLast
|
|
1142
|
+
* @indexed
|
|
1143
|
+
* @category Array
|
|
1144
|
+
*/
|
|
1145
|
+
declare function mapToObj<T, K extends keyof any, V>(fn: (element: T) => [K, V]): (array: ReadonlyArray<T>) => Record<K, V>;
|
|
1146
|
+
declare namespace mapToObj {
|
|
1147
|
+
function indexed<T, K extends keyof any, V>(array: ReadonlyArray<T>, fn: (element: T, index: number, array: ReadonlyArray<T>) => [K, V]): Record<K, V>;
|
|
1148
|
+
function indexed<T, K extends keyof any, V>(fn: (element: T, index: number, array: ReadonlyArray<T>) => [K, V]): (array: ReadonlyArray<T>) => Record<K, V>;
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
/**
|
|
1152
|
+
* Returns the max element using the provided predicate.
|
|
1153
|
+
* @param fn the predicate
|
|
1154
|
+
* @signature
|
|
1155
|
+
* P.maxBy(fn)(array)
|
|
1156
|
+
* P.maxBy.indexed(fn)(array)
|
|
1157
|
+
* @example
|
|
1158
|
+
* P.pipe(
|
|
1159
|
+
* [{a: 5}, {a: 1}, {a: 3}],
|
|
1160
|
+
* P.maxBy(x => x.a)
|
|
1161
|
+
* ) // { a: 5 }
|
|
1162
|
+
* @dataLast
|
|
1163
|
+
* @indexed
|
|
1164
|
+
* @category Array
|
|
1165
|
+
*/
|
|
1166
|
+
declare function maxBy<T>(fn: (item: T) => number): (items: ReadonlyArray<T>) => T | undefined;
|
|
1167
|
+
/**
|
|
1168
|
+
* Returns the max element using the provided predicate.
|
|
1169
|
+
* @param items the array
|
|
1170
|
+
* @param fn the predicate
|
|
1171
|
+
* @signature
|
|
1172
|
+
* P.maxBy(array, fn)
|
|
1173
|
+
* P.maxBy.indexed(array, fn)
|
|
1174
|
+
* @example
|
|
1175
|
+
* P.maxBy(
|
|
1176
|
+
* [{a: 5}, {a: 1}, {a: 3}],
|
|
1177
|
+
* x => x.a
|
|
1178
|
+
* ) // { a: 5 }
|
|
1179
|
+
* @dataFirst
|
|
1180
|
+
* @indexed
|
|
1181
|
+
* @category Array
|
|
1182
|
+
*/
|
|
1183
|
+
declare function maxBy<T>(items: ReadonlyArray<T>, fn: (item: T) => number): T | undefined;
|
|
1184
|
+
declare namespace maxBy {
|
|
1185
|
+
function indexed<T>(array: ReadonlyArray<T>, fn: PredIndexed<T, number>): T | undefined;
|
|
1186
|
+
function indexed<T>(fn: PredIndexed<T, number>): (array: ReadonlyArray<T>) => T | undefined;
|
|
1187
|
+
}
|
|
1188
|
+
|
|
1189
|
+
/**
|
|
1190
|
+
* Returns the mean of the elements of an array using the provided predicate.
|
|
1191
|
+
* @param fn predicate function
|
|
1192
|
+
* @signature
|
|
1193
|
+
* P.meanBy(fn)(array)
|
|
1194
|
+
* P.meanBy.indexed(fn)(array)
|
|
1195
|
+
* @example
|
|
1196
|
+
* P.pipe(
|
|
1197
|
+
* [{a: 5}, {a: 1}, {a: 3}],
|
|
1198
|
+
* P.meanBy(x => x.a)
|
|
1199
|
+
* ) // 3
|
|
1200
|
+
* @dataLast
|
|
1201
|
+
* @indexed
|
|
1202
|
+
* @category Array
|
|
1203
|
+
*/
|
|
1204
|
+
declare function meanBy<T>(fn: (item: T) => number): (items: ReadonlyArray<T>) => number;
|
|
1205
|
+
/**
|
|
1206
|
+
* Returns the mean of the elements of an array using the provided predicate.
|
|
1207
|
+
* @param items the array
|
|
1208
|
+
* @param fn predicate function
|
|
1209
|
+
* @signature
|
|
1210
|
+
* P.meanBy(array, fn)
|
|
1211
|
+
* P.meanBy.indexed(array, fn)
|
|
1212
|
+
* @example
|
|
1213
|
+
* P.meanBy(
|
|
1214
|
+
* [{a: 5}, {a: 1}, {a: 3}],
|
|
1215
|
+
* x => x.a
|
|
1216
|
+
* ) // 3
|
|
1217
|
+
* @dataFirst
|
|
1218
|
+
* @indexed
|
|
1219
|
+
* @category Array
|
|
1220
|
+
*/
|
|
1221
|
+
declare function meanBy<T>(items: ReadonlyArray<T>, fn: (item: T) => number): number;
|
|
1222
|
+
declare namespace meanBy {
|
|
1223
|
+
function indexed<T>(array: ReadonlyArray<T>, fn: PredIndexed<T, number>): number;
|
|
1224
|
+
function indexed<T>(fn: PredIndexed<T, number>): (array: ReadonlyArray<T>) => number;
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
/**
|
|
1228
|
+
* Merges a list of objects into a single object.
|
|
1229
|
+
* @param array the array of objects
|
|
1230
|
+
* @signature
|
|
1231
|
+
* P.mergeAll(objects)
|
|
1232
|
+
* @example
|
|
1233
|
+
* P.mergeAll([{ a: 1, b: 1 }, { b: 2, c: 3 }, { d: 10 }]) // => { a: 1, b: 2, c: 3, d: 10 }
|
|
1234
|
+
* @category Array
|
|
1235
|
+
*/
|
|
1236
|
+
declare function mergeAll<A>(array: readonly [A]): A;
|
|
1237
|
+
declare function mergeAll<A, B>(array: readonly [A, B]): A & B;
|
|
1238
|
+
declare function mergeAll<A, B, C>(array: readonly [A, B, C]): A & B & C;
|
|
1239
|
+
declare function mergeAll<A, B, C, D>(array: readonly [A, B, C, D]): A & B & C & D;
|
|
1240
|
+
declare function mergeAll<A, B, C, D, E>(array: [A, B, C, D, E]): A & B & C & D & E;
|
|
1241
|
+
declare function mergeAll(array: ReadonlyArray<object>): object;
|
|
1242
|
+
|
|
1243
|
+
/**
|
|
1244
|
+
* Returns the min element using the provided predicate.
|
|
1245
|
+
* @param fn the predicate
|
|
1246
|
+
* @signature
|
|
1247
|
+
* P.minBy(fn)(array)
|
|
1248
|
+
* P.minBy.indexed(fn)(array)
|
|
1249
|
+
* @example
|
|
1250
|
+
* P.pipe(
|
|
1251
|
+
* [{a: 5}, {a: 1}, {a: 3}],
|
|
1252
|
+
* P.minBy(x => x.a)
|
|
1253
|
+
* ) // { a: 1 }
|
|
1254
|
+
* @dataLast
|
|
1255
|
+
* @indexed
|
|
1256
|
+
* @category Array
|
|
1257
|
+
*/
|
|
1258
|
+
declare function minBy<T>(fn: (item: T) => number): (items: ReadonlyArray<T>) => T | undefined;
|
|
1259
|
+
/**
|
|
1260
|
+
* Returns the min element using the provided predicate.
|
|
1261
|
+
* @param items the array
|
|
1262
|
+
* @param fn the predicate
|
|
1263
|
+
* @signature
|
|
1264
|
+
* P.minBy(array, fn)
|
|
1265
|
+
* P.minBy.indexed(array, fn)
|
|
1266
|
+
* @example
|
|
1267
|
+
* P.minBy(
|
|
1268
|
+
* [{a: 5}, {a: 1}, {a: 3}],
|
|
1269
|
+
* x => x.a
|
|
1270
|
+
* ) // { a: 1 }
|
|
1271
|
+
* @dataFirst
|
|
1272
|
+
* @indexed
|
|
1273
|
+
* @category Array
|
|
1274
|
+
*/
|
|
1275
|
+
declare function minBy<T>(items: ReadonlyArray<T>, fn: (item: T) => number): T | undefined;
|
|
1276
|
+
declare namespace minBy {
|
|
1277
|
+
function indexed<T>(array: ReadonlyArray<T>, fn: PredIndexed<T, number>): T | undefined;
|
|
1278
|
+
function indexed<T>(fn: PredIndexed<T, number>): (array: ReadonlyArray<T>) => T | undefined;
|
|
1279
|
+
}
|
|
1280
|
+
|
|
1281
|
+
/**
|
|
1282
|
+
* Splits a collection into two groups, the first of which contains elements the `predicate` type guard passes, and the second one containing the rest.
|
|
1283
|
+
* @param items the items to split
|
|
1284
|
+
* @param predicate a type guard function to invoke on every item
|
|
1285
|
+
* @returns the array of grouped elements.
|
|
1286
|
+
* @signature
|
|
1287
|
+
* P.partition(array, fn)
|
|
1288
|
+
* @example
|
|
1289
|
+
* P.partition(['one', 'two', 'forty two'], x => x.length === 3) // => [['one', 'two'], ['forty two']]
|
|
1290
|
+
* @dataFirst
|
|
1291
|
+
* @indexed
|
|
1292
|
+
* @category Array
|
|
1293
|
+
*/
|
|
1294
|
+
declare function partition<T, S extends T>(items: ReadonlyArray<T>, predicate: (item: T) => item is S): [Array<S>, Array<Exclude<T, S>>];
|
|
1295
|
+
/**
|
|
1296
|
+
* Splits a collection into two groups, the first of which contains elements the `predicate` function matches, and the second one containing the rest.
|
|
1297
|
+
* @param items the items to split
|
|
1298
|
+
* @param predicate the function invoked per iteration
|
|
1299
|
+
* @returns the array of grouped elements.
|
|
1300
|
+
* @signature
|
|
1301
|
+
* P.partition(array, fn)
|
|
1302
|
+
* @example
|
|
1303
|
+
* P.partition(['one', 'two', 'forty two'], x => x.length === 3) // => [['one', 'two'], ['forty two']]
|
|
1304
|
+
* @dataFirst
|
|
1305
|
+
* @indexed
|
|
1306
|
+
* @category Array
|
|
1307
|
+
*/
|
|
1308
|
+
declare function partition<T>(items: ReadonlyArray<T>, predicate: (item: T) => boolean): [Array<T>, Array<T>];
|
|
1309
|
+
/**
|
|
1310
|
+
* Splits a collection into two groups, the first of which contains elements the `predicate` type guard passes, and the second one containing the rest.
|
|
1311
|
+
* @param predicate the grouping function
|
|
1312
|
+
* @returns the array of grouped elements.
|
|
1313
|
+
* @signature
|
|
1314
|
+
* P.partition(fn)(array)
|
|
1315
|
+
* @example
|
|
1316
|
+
* P.pipe(['one', 'two', 'forty two'], P.partition(x => x.length === 3)) // => [['one', 'two'], ['forty two']]
|
|
1317
|
+
* @dataLast
|
|
1318
|
+
* @indexed
|
|
1319
|
+
* @category Array
|
|
1320
|
+
*/
|
|
1321
|
+
declare function partition<T, S extends T>(predicate: (item: T) => item is S): (array: ReadonlyArray<T>) => [Array<S>, Array<Exclude<T, S>>];
|
|
1322
|
+
/**
|
|
1323
|
+
* Splits a collection into two groups, the first of which contains elements the `predicate` function matches, and the second one containing the rest.
|
|
1324
|
+
* @param predicate the grouping function
|
|
1325
|
+
* @returns the array of grouped elements.
|
|
1326
|
+
* @signature
|
|
1327
|
+
* P.partition(fn)(array)
|
|
1328
|
+
* @example
|
|
1329
|
+
* P.pipe(['one', 'two', 'forty two'], P.partition(x => x.length === 3)) // => [['one', 'two'], ['forty two']]
|
|
1330
|
+
* @dataLast
|
|
1331
|
+
* @indexed
|
|
1332
|
+
* @category Array
|
|
1333
|
+
*/
|
|
1334
|
+
declare function partition<T>(predicate: (item: T) => boolean): (array: ReadonlyArray<T>) => [Array<T>, Array<T>];
|
|
1335
|
+
declare namespace partition {
|
|
1336
|
+
function indexed<T>(array: ReadonlyArray<T>, predicate: PredIndexed<T, boolean>): [Array<T>, Array<T>];
|
|
1337
|
+
function indexed<T>(predicate: PredIndexed<T, boolean>): (array: ReadonlyArray<T>) => [Array<T>, Array<T>];
|
|
1338
|
+
}
|
|
1339
|
+
|
|
1340
|
+
/**
|
|
1341
|
+
* Returns a list of numbers from `start` (inclusive) to `end` (exclusive).
|
|
1342
|
+
* @param start the start number
|
|
1343
|
+
* @param end the end number
|
|
1344
|
+
* @signature range(start, end)
|
|
1345
|
+
* @example
|
|
1346
|
+
* P.range(1, 5) // => [1, 2, 3, 4]
|
|
1347
|
+
* @dataFirst
|
|
1348
|
+
* @category Array
|
|
1349
|
+
*/
|
|
1350
|
+
declare function range(start: number, end: number): Array<number>;
|
|
1351
|
+
/**
|
|
1352
|
+
* Returns a list of numbers from `start` (inclusive) to `end` (exclusive).
|
|
1353
|
+
* @param end the end number
|
|
1354
|
+
* @signature range(end)(start)
|
|
1355
|
+
* @example
|
|
1356
|
+
* P.range(5)(1) // => [1, 2, 3, 4]
|
|
1357
|
+
* @dataFirst
|
|
1358
|
+
* @category Array
|
|
1359
|
+
*/
|
|
1360
|
+
declare function range(end: number): (start: number) => Array<number>;
|
|
1361
|
+
|
|
1362
|
+
/**
|
|
1363
|
+
* Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
|
|
1364
|
+
* @param items the array to reduce
|
|
1365
|
+
* @param fn the callback function
|
|
1366
|
+
* @param initialValue the initial value to use as an accumulator value in the callback function
|
|
1367
|
+
* @signature
|
|
1368
|
+
* P.reduce(items, fn, initialValue)
|
|
1369
|
+
* P.reduce.indexed(items, fn, initialValue)
|
|
1370
|
+
* @example
|
|
1371
|
+
* P.reduce([1, 2, 3, 4, 5], (acc, x) => acc + x, 100) // => 115
|
|
1372
|
+
* P.reduce.indexed([1, 2, 3, 4, 5], (acc, x, i, array) => acc + x, 100) // => 115
|
|
1373
|
+
* @dataFirst
|
|
1374
|
+
* @indexed
|
|
1375
|
+
* @category Array
|
|
1376
|
+
*/
|
|
1377
|
+
declare function reduce<T, K>(items: ReadonlyArray<T>, fn: (acc: K, item: T) => K, initialValue: K): K;
|
|
1378
|
+
/**
|
|
1379
|
+
* Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
|
|
1380
|
+
* @param fn the callback function
|
|
1381
|
+
* @param initialValue the initial value to use as an accumulator value in the callback function
|
|
1382
|
+
* @signature
|
|
1383
|
+
* P.reduce(fn, initialValue)(array)
|
|
1384
|
+
* @example
|
|
1385
|
+
* P.pipe([1, 2, 3, 4, 5], P.reduce((acc, x) => acc + x, 100)) // => 115
|
|
1386
|
+
* P.pipe([1, 2, 3, 4, 5], P.reduce.indexed((acc, x, i, array) => acc + x, 100)) // => 115
|
|
1387
|
+
* @dataLast
|
|
1388
|
+
* @indexed
|
|
1389
|
+
* @category Array
|
|
1390
|
+
*/
|
|
1391
|
+
declare function reduce<T, K>(fn: (acc: K, item: T) => K, initialValue: K): (items: ReadonlyArray<T>) => K;
|
|
1392
|
+
declare namespace reduce {
|
|
1393
|
+
function indexed<T, K>(array: ReadonlyArray<T>, fn: (acc: K, item: T, index: number, items: Array<T>) => K, initialValue: K): K;
|
|
1394
|
+
function indexed<T, K>(fn: (acc: K, item: T, index: number, items: Array<T>) => K, initialValue: K): (array: ReadonlyArray<T>) => K;
|
|
1395
|
+
}
|
|
1396
|
+
|
|
1397
|
+
/**
|
|
1398
|
+
* Reject the elements of an array that meet the condition specified in a callback function.
|
|
1399
|
+
* @param items The array to reject.
|
|
1400
|
+
* @param fn the callback function.
|
|
1401
|
+
* @signature
|
|
1402
|
+
* P.reject(array, fn)
|
|
1403
|
+
* P.reject.indexed(array, fn)
|
|
1404
|
+
* @example
|
|
1405
|
+
* P.reject([1, 2, 3], x => x % 2 === 0) // => [1, 3]
|
|
1406
|
+
* P.reject.indexed([1, 2, 3], (x, i, array) => x % 2 === 0) // => [1, 3]
|
|
1407
|
+
* @dataFirst
|
|
1408
|
+
* @indexed
|
|
1409
|
+
* @pipeable
|
|
1410
|
+
* @category Array
|
|
1411
|
+
*/
|
|
1412
|
+
declare function reject<T>(items: ReadonlyArray<T>, fn: Pred<T, boolean>): Array<T>;
|
|
1413
|
+
/**
|
|
1414
|
+
* Reject the elements of an array that meet the condition specified in a callback function.
|
|
1415
|
+
* @param fn the callback function.
|
|
1416
|
+
* @signature
|
|
1417
|
+
* P.reject(array, fn)
|
|
1418
|
+
* P.reject.indexed(array, fn)
|
|
1419
|
+
* @example
|
|
1420
|
+
* P.reject([1, 2, 3], x => x % 2 === 0) // => [1, 3]
|
|
1421
|
+
* P.reject.indexed([1, 2, 3], (x, i, array) => x % 2 === 0) // => [1, 3]
|
|
1422
|
+
* @dataFirst
|
|
1423
|
+
* @indexed
|
|
1424
|
+
* @pipeable
|
|
1425
|
+
* @category Array
|
|
1426
|
+
*/
|
|
1427
|
+
declare function reject<T>(fn: Pred<T, boolean>): (items: ReadonlyArray<T>) => Array<T>;
|
|
1428
|
+
declare namespace reject {
|
|
1429
|
+
function indexed<T, K>(array: ReadonlyArray<T>, fn: PredIndexed<T, boolean>): Array<K>;
|
|
1430
|
+
function indexed<T, K>(fn: PredIndexed<T, boolean>): (array: ReadonlyArray<T>) => Array<K>;
|
|
1431
|
+
const lazy: <T>(fn: PredIndexedOptional<T, boolean>) => (value: T, index?: number | undefined, array?: T[] | undefined) => LazyResult<T>;
|
|
1432
|
+
const lazyIndexed: (<T>(fn: PredIndexedOptional<T, boolean>) => (value: T, index?: number | undefined, array?: T[] | undefined) => LazyResult<T>) & {
|
|
1433
|
+
indexed: true;
|
|
1434
|
+
};
|
|
1435
|
+
}
|
|
1436
|
+
|
|
1437
|
+
type Reverse<T extends ReadonlyArray<unknown>, R extends ReadonlyArray<unknown> = []> = ReturnType<T extends IsNoTuple<T> ? () => [...T, ...R] : T extends readonly [infer F, ...infer L] ? () => Reverse<L, [F, ...R]> : () => R>;
|
|
1438
|
+
type IsNoTuple<T> = T extends readonly [unknown, ...Array<unknown>] ? never : T;
|
|
1439
|
+
/**
|
|
1440
|
+
* Reverses array.
|
|
1441
|
+
* @param array the array
|
|
1442
|
+
* @signature
|
|
1443
|
+
* P.reverse(arr);
|
|
1444
|
+
* @example
|
|
1445
|
+
* P.reverse([1, 2, 3]) // [3, 2, 1]
|
|
1446
|
+
* @dataFirst
|
|
1447
|
+
* @category Array
|
|
1448
|
+
*/
|
|
1449
|
+
declare function reverse<T extends ReadonlyArray<unknown>>(array: T): Reverse<T>;
|
|
1450
|
+
/**
|
|
1451
|
+
* Reverses array.
|
|
1452
|
+
* @signature
|
|
1453
|
+
* P.reverse()(array);
|
|
1454
|
+
* @example
|
|
1455
|
+
* P.reverse()([1, 2, 3]) // [3, 2, 1]
|
|
1456
|
+
* @dataLast
|
|
1457
|
+
* @category Array
|
|
1458
|
+
*/
|
|
1459
|
+
declare function reverse<T extends ReadonlyArray<unknown>>(): (array: T) => Reverse<T>;
|
|
1460
|
+
|
|
1461
|
+
type Sampled<T extends IterableContainer, N extends number> = number extends N ? SampledGeneric<T> : undefined extends T[N] ? T : SampledLiteral<T, N>;
|
|
1462
|
+
type SampledGeneric<T extends IterableContainer> = T[number] extends never ? T : T extends readonly [infer First, ...infer Rest] ? [First, ...SampledGeneric<Rest>] | SampledGeneric<Rest> : Array<T[number]>;
|
|
1463
|
+
type SampledLiteral<T extends IterableContainer, N extends number, Iteration extends Array<unknown> = []> = Iteration['length'] extends N ? [] : T extends readonly [infer First, ...infer Tail] ? [
|
|
1464
|
+
First | Tail[number],
|
|
1465
|
+
...SampledLiteral<Tail, N, [unknown, ...Iteration]>
|
|
1466
|
+
] : T extends readonly [...infer Head, infer Last] ? [...SampledLiteral<Head, N, [unknown, ...Iteration]>, Last] : [T[number], ...SampledLiteral<T, N, [unknown, ...Iteration]>] | SampledLiteral<T, N, [unknown, ...Iteration]>;
|
|
1467
|
+
/**
|
|
1468
|
+
* Returns a random subset of size `sampleSize` from `array`.
|
|
1469
|
+
*
|
|
1470
|
+
* Maintains and infers most of the typing information that could be passed
|
|
1471
|
+
* along to the output. This means that when using tuples, the output will be
|
|
1472
|
+
* a tuple too, and when using literals, those literals would be preserved.
|
|
1473
|
+
*
|
|
1474
|
+
* The items in the result are kept in the same order as they are in the input.
|
|
1475
|
+
* If you need to get a shuffled response you can pipe the shuffle function
|
|
1476
|
+
* after this one.
|
|
1477
|
+
*
|
|
1478
|
+
* @param data the array
|
|
1479
|
+
* @param sampleSize the number of elements to take
|
|
1480
|
+
* @signature
|
|
1481
|
+
* P.sample(array, sampleSize)
|
|
1482
|
+
* @example
|
|
1483
|
+
* P.sample(["hello", "world"], 1); // => ["hello"] // typed string[]
|
|
1484
|
+
* P.sample(["hello", "world"] as const, 1); // => ["world"] // typed ["hello" | "world"]
|
|
1485
|
+
* @dataFirst
|
|
1486
|
+
* @pipeable
|
|
1487
|
+
* @category Array
|
|
1488
|
+
*/
|
|
1489
|
+
declare function sample<T extends IterableContainer, N extends number = number>(data: T, sampleSize: N): Sampled<T, N>;
|
|
1490
|
+
/**
|
|
1491
|
+
* Returns a random subset of size `sampleSize` from `array`.
|
|
1492
|
+
*
|
|
1493
|
+
* Maintains and infers most of the typing information that could be passed
|
|
1494
|
+
* along to the output. This means that when using tuples, the output will be
|
|
1495
|
+
* a tuple too, and when using literals, those literals would be preserved.
|
|
1496
|
+
*
|
|
1497
|
+
* The items in the result are kept in the same order as they are in the input.
|
|
1498
|
+
* If you need to get a shuffled response you can pipe the shuffle function
|
|
1499
|
+
* after this one.
|
|
1500
|
+
*
|
|
1501
|
+
* @param sampleSize the number of elements to take
|
|
1502
|
+
* @signature
|
|
1503
|
+
* P.sample(sampleSize)(array)
|
|
1504
|
+
* @example
|
|
1505
|
+
* P.sample(1)(["hello", "world"]); // => ["hello"] // typed string[]
|
|
1506
|
+
* P.sample(1)(["hello", "world"] as const); // => ["world"] // typed ["hello" | "world"]
|
|
1507
|
+
* @dataLast
|
|
1508
|
+
* @pipeable
|
|
1509
|
+
* @category Array
|
|
1510
|
+
*/
|
|
1511
|
+
declare function sample<T extends IterableContainer, N extends number = number>(sampleSize: N): (data: T) => Sampled<T, N>;
|
|
1512
|
+
|
|
1513
|
+
/**
|
|
1514
|
+
* Shuffles the input array, returning a new array with the same elements in a random order.
|
|
1515
|
+
* @param items the array to shuffle
|
|
1516
|
+
* @signature
|
|
1517
|
+
* P.shuffle(array)
|
|
1518
|
+
* @example
|
|
1519
|
+
* P.shuffle([4, 2, 7, 5]) // => [7, 5, 4, 2]
|
|
1520
|
+
* @category Array
|
|
1521
|
+
* @dataFirst
|
|
1522
|
+
*/
|
|
1523
|
+
declare function shuffle<T>(items: ReadonlyArray<T>): Array<T>;
|
|
1524
|
+
/**
|
|
1525
|
+
* Shuffles the input array, returning a new array with the same elements in a random order.
|
|
1526
|
+
* @signature
|
|
1527
|
+
* P.shuffle()(array)
|
|
1528
|
+
* @example
|
|
1529
|
+
* P.pipe([4, 2, 7, 5], P.shuffle()) // => [7, 5, 4, 2]
|
|
1530
|
+
* @category Array
|
|
1531
|
+
* @dataLast
|
|
1532
|
+
*/
|
|
1533
|
+
declare function shuffle<T>(): (items: ReadonlyArray<T>) => Array<T>;
|
|
1534
|
+
|
|
1535
|
+
interface Strict$3 {
|
|
1536
|
+
<T extends IterableContainer>(items: T, cmp: (a: T[number], b: T[number]) => number): Sorted<T>;
|
|
1537
|
+
<T extends IterableContainer>(cmp: (a: T[number], b: T[number]) => number): (items: T) => Sorted<T>;
|
|
1538
|
+
}
|
|
1539
|
+
type Sorted<T extends IterableContainer> = {
|
|
1540
|
+
-readonly [P in keyof T]: T[number];
|
|
1541
|
+
};
|
|
1542
|
+
/**
|
|
1543
|
+
* Sorts an array. The comparator function should accept two values at a time and return a negative number if the first value is smaller, a positive number if it's larger, and zero if they are equal.
|
|
1544
|
+
* Sorting is based on a native `sort` function. It's not guaranteed to be stable.
|
|
1545
|
+
*
|
|
1546
|
+
* If the input array is more complex (non-empty array, tuple, etc...) use the
|
|
1547
|
+
* strict mode to maintain it's shape.
|
|
1548
|
+
*
|
|
1549
|
+
* @param items the array to sort
|
|
1550
|
+
* @param cmp the comparator function
|
|
1551
|
+
* @signature
|
|
1552
|
+
* P.sort(items, cmp)
|
|
1553
|
+
* P.sort.strict(items, cmp)
|
|
1554
|
+
* @example
|
|
1555
|
+
* P.sort([4, 2, 7, 5], (a, b) => a - b) // => [2, 4, 5, 7] typed Array<number>
|
|
1556
|
+
* P.sort.strict([4, 2] as [number, number], (a, b) => a - b) // [2, 4] typed [number, number]
|
|
1557
|
+
* @dataFirst
|
|
1558
|
+
* @category Array
|
|
1559
|
+
* @strict
|
|
1560
|
+
*/
|
|
1561
|
+
declare function sort<T>(items: ReadonlyArray<T>, cmp: (a: T, b: T) => number): Array<T>;
|
|
1562
|
+
/**
|
|
1563
|
+
* Sorts an array. The comparator function should accept two values at a time and return a negative number if the first value is smaller, a positive number if it's larger, and zero if they are equal.
|
|
1564
|
+
* Sorting is based on a native `sort` function. It's not guaranteed to be stable.
|
|
1565
|
+
*
|
|
1566
|
+
* If the input array is more complex (non-empty array, tuple, etc...) use the
|
|
1567
|
+
* strict mode to maintain it's shape.
|
|
1568
|
+
*
|
|
1569
|
+
* @param cmp the comparator function
|
|
1570
|
+
* @signature
|
|
1571
|
+
* P.sort(cmp)(items)
|
|
1572
|
+
* P.sort.strict(cmp)(items)
|
|
1573
|
+
* @example
|
|
1574
|
+
* P.pipe([4, 2, 7, 5], P.sort((a, b) => a - b)) // => [2, 4, 5, 7] typed Array<number>
|
|
1575
|
+
* P.pipe([4, 2] as [number, number], P.sort.strict((a, b) => a - b)) // => [2, 4] typed [number, number]
|
|
1576
|
+
* @dataLast
|
|
1577
|
+
* @category Array
|
|
1578
|
+
* @strict
|
|
1579
|
+
*/
|
|
1580
|
+
declare function sort<T>(cmp: (a: T, b: T) => number): (items: ReadonlyArray<T>) => Array<T>;
|
|
1581
|
+
declare namespace sort {
|
|
1582
|
+
const strict: Strict$3;
|
|
1583
|
+
}
|
|
1584
|
+
|
|
1585
|
+
declare const ALL_DIRECTIONS: readonly ["asc", "desc"];
|
|
1586
|
+
type Direction = (typeof ALL_DIRECTIONS)[number];
|
|
1587
|
+
type ComparablePrimitive = number | string | boolean;
|
|
1588
|
+
type Comparable = ComparablePrimitive | {
|
|
1589
|
+
valueOf(): ComparablePrimitive;
|
|
1590
|
+
};
|
|
1591
|
+
type SortProjection<T> = (x: T) => Comparable;
|
|
1592
|
+
type SortPair<T> = readonly [
|
|
1593
|
+
projector: SortProjection<T>,
|
|
1594
|
+
direction: Direction
|
|
1595
|
+
];
|
|
1596
|
+
type SortRule<T> = SortProjection<T> | SortPair<T>;
|
|
1597
|
+
interface Strict$2 {
|
|
1598
|
+
<T extends IterableContainer>(...sortRules: Readonly<NonEmptyArray<SortRule<T[number]>>>): (array: T) => SortedBy<T>;
|
|
1599
|
+
<T extends IterableContainer>(array: T, ...sortRules: Readonly<NonEmptyArray<SortRule<T[number]>>>): SortedBy<T>;
|
|
1600
|
+
}
|
|
1601
|
+
type SortedBy<T extends IterableContainer> = {
|
|
1602
|
+
-readonly [P in keyof T]: T[number];
|
|
1603
|
+
};
|
|
1604
|
+
/**
|
|
1605
|
+
* Sorts the list according to the supplied functions and directions.
|
|
1606
|
+
* Sorting is based on a native `sort` function. It's not guaranteed to be stable.
|
|
1607
|
+
*
|
|
1608
|
+
* Directions are applied to functions in order and default to ascending if not specified.
|
|
1609
|
+
*
|
|
1610
|
+
* If the input array is more complex (non-empty array, tuple, etc...) use the
|
|
1611
|
+
* strict mode to maintain it's shape.
|
|
1612
|
+
*
|
|
1613
|
+
* @param sortRules main sort rule
|
|
1614
|
+
* @signature
|
|
1615
|
+
* P.sortBy(sortRule, ...additionalSortRules)(array)
|
|
1616
|
+
* P.sortBy.strict(sortRule, ...additionalSortRules)(array)
|
|
1617
|
+
* @example
|
|
1618
|
+
* P.pipe(
|
|
1619
|
+
* [{ a: 1 }, { a: 3 }, { a: 7 }, { a: 2 }],
|
|
1620
|
+
* P.sortBy(x => x.a)
|
|
1621
|
+
* ) // => [{ a: 1 }, { a: 2 }, { a: 3 }, { a: 7 }] typed Array<{a:number}>
|
|
1622
|
+
* P.pipe(
|
|
1623
|
+
* [{ a: 1 }, { a: 3 }] as const,
|
|
1624
|
+
* P.sortBy.strict(x => x.a)
|
|
1625
|
+
* ) // => [{ a: 1 }, { a: 3 }] typed [{a: 1 | 3}, {a: 1 | 3}]
|
|
1626
|
+
* @dataLast
|
|
1627
|
+
* @category Array
|
|
1628
|
+
* @strict
|
|
1629
|
+
*/
|
|
1630
|
+
declare function sortBy<T>(...sortRules: Readonly<NonEmptyArray<SortRule<T>>>): (array: ReadonlyArray<T>) => Array<T>;
|
|
1631
|
+
/**
|
|
1632
|
+
* Sorts the list according to the supplied functions and directions.
|
|
1633
|
+
* Sorting is based on a native `sort` function. It's not guaranteed to be stable.
|
|
1634
|
+
*
|
|
1635
|
+
* Directions are applied to functions in order and default to ascending if not specified.
|
|
1636
|
+
*
|
|
1637
|
+
* If the input array is more complex (non-empty array, tuple, etc...) use the
|
|
1638
|
+
* strict mode to maintain it's shape.
|
|
1639
|
+
*
|
|
1640
|
+
* @param array the array to sort
|
|
1641
|
+
* @param sortRules main sort rule
|
|
1642
|
+
* @signature
|
|
1643
|
+
* P.sortBy(array, sortRule, ...additionalSortRules)
|
|
1644
|
+
* P.sortBy.strict(array, sortRule, ...additionalSortRules)
|
|
1645
|
+
* @example
|
|
1646
|
+
* P.sortBy(
|
|
1647
|
+
* [{ a: 1 }, { a: 3 }, { a: 7 }, { a: 2 }],
|
|
1648
|
+
* x => x.a
|
|
1649
|
+
* )
|
|
1650
|
+
* // => [{ a: 1 }, { a: 2 }, { a: 3 }, { a: 7 }] typed Array<{a:number}>
|
|
1651
|
+
*
|
|
1652
|
+
* P.sortBy(
|
|
1653
|
+
* [
|
|
1654
|
+
* {color: 'red', weight: 2},
|
|
1655
|
+
* {color: 'blue', weight: 3},
|
|
1656
|
+
* {color: 'green', weight: 1},
|
|
1657
|
+
* {color: 'purple', weight: 1},
|
|
1658
|
+
* ],
|
|
1659
|
+
* [x => x.weight, 'asc'], x => x.color
|
|
1660
|
+
* )
|
|
1661
|
+
* // =>
|
|
1662
|
+
* // {color: 'green', weight: 1},
|
|
1663
|
+
* // {color: 'purple', weight: 1},
|
|
1664
|
+
* // {color: 'red', weight: 2},
|
|
1665
|
+
* // {color: 'blue', weight: 3},
|
|
1666
|
+
* // typed Array<{color: string, weight: number}>
|
|
1667
|
+
*
|
|
1668
|
+
* P.sortBy.strict(
|
|
1669
|
+
* [{ a: 1 }, { a: 3 }] as const,
|
|
1670
|
+
* x => x.a
|
|
1671
|
+
* )
|
|
1672
|
+
* // => [{ a: 1 }, { a: 3 }] typed [{a: 1 | 3}, {a: 1 | 3}]
|
|
1673
|
+
* @dataFirst
|
|
1674
|
+
* @category Array
|
|
1675
|
+
* @strict
|
|
1676
|
+
*/
|
|
1677
|
+
declare function sortBy<T>(array: ReadonlyArray<T>, ...sortRules: Readonly<NonEmptyArray<SortRule<T>>>): Array<T>;
|
|
1678
|
+
declare namespace sortBy {
|
|
1679
|
+
const strict: Strict$2;
|
|
1680
|
+
}
|
|
1681
|
+
|
|
1682
|
+
/**
|
|
1683
|
+
* Splits a given array at a given index.
|
|
1684
|
+
* @param array the array to split
|
|
1685
|
+
* @param index the index to split at
|
|
1686
|
+
* @signature
|
|
1687
|
+
* P.splitAt(array, index)
|
|
1688
|
+
* @example
|
|
1689
|
+
* P.splitAt([1, 2, 3], 1) // => [[1], [2, 3]]
|
|
1690
|
+
* P.splitAt([1, 2, 3, 4, 5], -1) // => [[1, 2, 3, 4], [5]]
|
|
1691
|
+
* @dataFirst
|
|
1692
|
+
* @category Array
|
|
1693
|
+
*/
|
|
1694
|
+
declare function splitAt<T>(array: ReadonlyArray<T>, index: number): [Array<T>, Array<T>];
|
|
1695
|
+
/**
|
|
1696
|
+
* Splits a given array at a given index.
|
|
1697
|
+
* @param index the index to split at
|
|
1698
|
+
* @signature
|
|
1699
|
+
* P.splitAt(index)(array)
|
|
1700
|
+
* @example
|
|
1701
|
+
* P.splitAt(1)([1, 2, 3]) // => [[1], [2, 3]]
|
|
1702
|
+
* P.splitAt(-1)([1, 2, 3, 4, 5]) // => [[1, 2, 3, 4], [5]]
|
|
1703
|
+
* @dataLast
|
|
1704
|
+
* @category Array
|
|
1705
|
+
*/
|
|
1706
|
+
declare function splitAt<T>(index: number): (array: ReadonlyArray<T>) => [Array<T>, Array<T>];
|
|
1707
|
+
|
|
1708
|
+
/**
|
|
1709
|
+
* Splits a given array at the first index where the given predicate returns true.
|
|
1710
|
+
* @param array the array to split
|
|
1711
|
+
* @param fn the predicate
|
|
1712
|
+
* @signature
|
|
1713
|
+
* P.splitWhen(array, fn)
|
|
1714
|
+
* @example
|
|
1715
|
+
* P.splitWhen([1, 2, 3], x => x === 2) // => [[1], [2, 3]]
|
|
1716
|
+
* @dataFirst
|
|
1717
|
+
* @category Array
|
|
1718
|
+
*/
|
|
1719
|
+
declare function splitWhen<T>(array: ReadonlyArray<T>, fn: (item: T) => boolean): [Array<T>, Array<T>];
|
|
1720
|
+
/**
|
|
1721
|
+
* Splits a given array at an index where the given predicate returns true.
|
|
1722
|
+
* @param fn the predicate
|
|
1723
|
+
* @signature
|
|
1724
|
+
* P.splitWhen(fn)(array)
|
|
1725
|
+
* @example
|
|
1726
|
+
* P.splitWhen(x => x === 2)([1, 2, 3]) // => [[1], [2, 3]]
|
|
1727
|
+
* @dataLast
|
|
1728
|
+
* @category Array
|
|
1729
|
+
*/
|
|
1730
|
+
declare function splitWhen<T>(fn: (item: T) => boolean): (array: ReadonlyArray<T>) => [Array<T>, Array<T>];
|
|
1731
|
+
|
|
1732
|
+
/**
|
|
1733
|
+
* Returns the sum of the elements of an array using the provided predicate.
|
|
1734
|
+
* @param fn predicate function
|
|
1735
|
+
* @signature
|
|
1736
|
+
* P.sumBy(fn)(array)
|
|
1737
|
+
* P.sumBy.indexed(fn)(array)
|
|
1738
|
+
* @example
|
|
1739
|
+
* P.pipe(
|
|
1740
|
+
* [{a: 5}, {a: 1}, {a: 3}],
|
|
1741
|
+
* P.sumBy(x => x.a)
|
|
1742
|
+
* ) // 9
|
|
1743
|
+
* @dataLast
|
|
1744
|
+
* @indexed
|
|
1745
|
+
* @category Array
|
|
1746
|
+
*/
|
|
1747
|
+
declare function sumBy<T>(fn: (item: T) => number): (items: ReadonlyArray<T>) => number;
|
|
1748
|
+
/**
|
|
1749
|
+
* Returns the sum of the elements of an array using the provided predicate.
|
|
1750
|
+
* @param items the array
|
|
1751
|
+
* @param fn predicate function
|
|
1752
|
+
* @signature
|
|
1753
|
+
* P.sumBy(array, fn)
|
|
1754
|
+
* P.sumBy.indexed(array, fn)
|
|
1755
|
+
* @example
|
|
1756
|
+
* P.sumBy(
|
|
1757
|
+
* [{a: 5}, {a: 1}, {a: 3}],
|
|
1758
|
+
* x => x.a
|
|
1759
|
+
* ) // 9
|
|
1760
|
+
* @dataFirst
|
|
1761
|
+
* @indexed
|
|
1762
|
+
* @category Array
|
|
1763
|
+
*/
|
|
1764
|
+
declare function sumBy<T>(items: ReadonlyArray<T>, fn: (item: T) => number): number;
|
|
1765
|
+
declare namespace sumBy {
|
|
1766
|
+
function indexed<T>(array: ReadonlyArray<T>, fn: PredIndexed<T, number>): number;
|
|
1767
|
+
function indexed<T>(fn: PredIndexed<T, number>): (array: ReadonlyArray<T>) => number;
|
|
1768
|
+
}
|
|
1769
|
+
|
|
1770
|
+
/**
|
|
1771
|
+
* @link https://github.com/sindresorhus/type-fest/blob/main/source/is-equal.d.ts
|
|
1772
|
+
*/
|
|
1773
|
+
type isEqual<A, B> = (<G>() => G extends A ? 1 : 2) extends <G>() => G extends B ? 1 : 2 ? true : false;
|
|
1774
|
+
type Difference<A extends number, B extends number> = TupleOfLength<A> extends [
|
|
1775
|
+
...infer U,
|
|
1776
|
+
...TupleOfLength<B>
|
|
1777
|
+
] ? U['length'] : never;
|
|
1778
|
+
type isLessThan<A extends number, B extends number> = isEqual<A, B> extends true ? false : 0 extends A ? true : 0 extends B ? false : isLessThan<Difference<A, 1>, Difference<B, 1>>;
|
|
1779
|
+
type TupleOfLength<L extends number, T extends IterableContainer = []> = T['length'] extends L ? T : TupleOfLength<L, [...T, unknown]>;
|
|
1780
|
+
type IsNonNegative<T extends number> = number extends T ? false : `${T}` extends `-${string}` ? false : true;
|
|
1781
|
+
type CharactersTuple<T extends string> = string extends T ? Array<string> : T extends `${infer C}${infer R}` ? [C, ...CharactersTuple<R>] : [];
|
|
1782
|
+
type SwapArrayInternal<T extends IterableContainer, Index1 extends number, Index2 extends number, Position extends ReadonlyArray<unknown> = [], Original extends IterableContainer = T> = T extends readonly [infer AtPosition, ...infer Rest] ? [
|
|
1783
|
+
Position['length'] extends Index1 ? Original[Index2] : Position['length'] extends Index2 ? Original[Index1] : AtPosition,
|
|
1784
|
+
...SwapArrayInternal<Rest, Index1, Index2, [
|
|
1785
|
+
unknown,
|
|
1786
|
+
...Position
|
|
1787
|
+
], Original>
|
|
1788
|
+
] : T;
|
|
1789
|
+
type SwapString<T extends string, K1 extends number, K2 extends number> = Joined<SwapArray<CharactersTuple<T>, K1, K2>, ''>;
|
|
1790
|
+
type SwapArray<T extends IterableContainer, K1 extends number, K2 extends number> = IsNonNegative<K1> extends false ? Array<T[number]> : IsNonNegative<K2> extends false ? Array<T[number]> : isLessThan<K1, T['length']> extends false ? T : isLessThan<K2, T['length']> extends false ? T : SwapArrayInternal<T, K1, K2>;
|
|
1791
|
+
type SwappedIndices<T extends IterableContainer | string, K1 extends number, K2 extends number> = T extends string ? SwapString<T, K1, K2> : T extends IterableContainer ? SwapArray<T, K1, K2> : never;
|
|
1792
|
+
/**
|
|
1793
|
+
* Swaps the positions of two elements in an array or string at the provided indices.
|
|
1794
|
+
*
|
|
1795
|
+
* Negative indices are supported and would be treated as an offset from the end of the array. The resulting type thought would be less strict than when using positive indices.
|
|
1796
|
+
*
|
|
1797
|
+
* If either index is out of bounds the result would be a shallow copy of the input, as-is.
|
|
1798
|
+
*
|
|
1799
|
+
* @param data the item to be manipulated. This can be an array, or a string.
|
|
1800
|
+
* @param index1 the first index
|
|
1801
|
+
* @param index2 the second index
|
|
1802
|
+
*
|
|
1803
|
+
* @signature
|
|
1804
|
+
* swapIndices(data, index1, index2)
|
|
1805
|
+
*
|
|
1806
|
+
* @example
|
|
1807
|
+
* swapIndices(['a', 'b', 'c'], 0, 1) // => ['b', 'a', 'c']
|
|
1808
|
+
* swapIndices(['a', 'b', 'c'], 1, -1) // => ['c', 'b', 'a']
|
|
1809
|
+
* swapIndices('abc', 0, 1) // => 'bac'
|
|
1810
|
+
*
|
|
1811
|
+
* @category Array
|
|
1812
|
+
*
|
|
1813
|
+
* @returns Returns the manipulated array or string.
|
|
1814
|
+
*
|
|
1815
|
+
* @dataFirst
|
|
1816
|
+
*/
|
|
1817
|
+
declare function swapIndices<T extends IterableContainer | string, K1 extends number, K2 extends number>(data: T, index1: K1, index2: K2): SwappedIndices<T, K1, K2>;
|
|
1818
|
+
/**
|
|
1819
|
+
* @param index1 the first index
|
|
1820
|
+
* @param index2 the second index
|
|
1821
|
+
*
|
|
1822
|
+
* @signature
|
|
1823
|
+
* swapIndices(index1, index2)(data)
|
|
1824
|
+
*
|
|
1825
|
+
* @example
|
|
1826
|
+
* swapIndices(0, 1)(['a', 'b', 'c']) // => ['b', 'a', 'c']
|
|
1827
|
+
* swapIndices(0, -1)('abc') // => 'cba'
|
|
1828
|
+
*
|
|
1829
|
+
* @category Array
|
|
1830
|
+
* @returns Returns the manipulated array or string.
|
|
1831
|
+
* @dataLast
|
|
1832
|
+
*/
|
|
1833
|
+
declare function swapIndices<K1 extends number, K2 extends number>(index1: K1, index2: K2): <T extends IterableContainer | string>(data: T) => SwappedIndices<T, K1, K2>;
|
|
1834
|
+
|
|
1835
|
+
/**
|
|
1836
|
+
* Returns the first `n` elements of `array`.
|
|
1837
|
+
* @param array the array
|
|
1838
|
+
* @param n the number of elements to take
|
|
1839
|
+
* @signature
|
|
1840
|
+
* P.take(array, n)
|
|
1841
|
+
* @example
|
|
1842
|
+
* P.take([1, 2, 3, 4, 3, 2, 1], 3) // => [1, 2, 3]
|
|
1843
|
+
* @dataFirst
|
|
1844
|
+
* @pipeable
|
|
1845
|
+
* @category Array
|
|
1846
|
+
*/
|
|
1847
|
+
declare function take<T>(array: ReadonlyArray<T>, n: number): Array<T>;
|
|
1848
|
+
/**
|
|
1849
|
+
* Returns the first `n` elements of `array`.
|
|
1850
|
+
* @param n the number of elements to take
|
|
1851
|
+
* @signature
|
|
1852
|
+
* P.take(n)(array)
|
|
1853
|
+
* @example
|
|
1854
|
+
* P.pipe([1, 2, 3, 4, 3, 2, 1], P.take(n)) // => [1, 2, 3]
|
|
1855
|
+
* @dataLast
|
|
1856
|
+
* @pipeable
|
|
1857
|
+
* @category Array
|
|
1858
|
+
*/
|
|
1859
|
+
declare function take<T>(n: number): (array: ReadonlyArray<T>) => Array<T>;
|
|
1860
|
+
declare namespace take {
|
|
1861
|
+
function lazy<T>(n: number): (value: T) => LazyResult<T>;
|
|
1862
|
+
}
|
|
1863
|
+
|
|
1864
|
+
/**
|
|
1865
|
+
* Returns elements from the array until predicate returns false.
|
|
1866
|
+
* @param array the array
|
|
1867
|
+
* @param fn the predicate
|
|
1868
|
+
* @signature
|
|
1869
|
+
* P.takeWhile(array, fn)
|
|
1870
|
+
* @example
|
|
1871
|
+
* P.takeWhile([1, 2, 3, 4, 3, 2, 1], x => x !== 4) // => [1, 2, 3]
|
|
1872
|
+
* @dataFirst
|
|
1873
|
+
* @category Array
|
|
1874
|
+
*/
|
|
1875
|
+
declare function takeWhile<T>(array: ReadonlyArray<T>, fn: (item: T) => boolean): Array<T>;
|
|
1876
|
+
/**
|
|
1877
|
+
* Returns elements from the array until predicate returns false.
|
|
1878
|
+
* @param fn the predicate
|
|
1879
|
+
* @signature
|
|
1880
|
+
* P.takeWhile(fn)(array)
|
|
1881
|
+
* @example
|
|
1882
|
+
* P.pipe([1, 2, 3, 4, 3, 2, 1], P.takeWhile(x => x !== 4)) // => [1, 2, 3]
|
|
1883
|
+
* @dataLast
|
|
1884
|
+
* @category Array
|
|
1885
|
+
*/
|
|
1886
|
+
declare function takeWhile<T>(fn: (item: T) => boolean): (array: ReadonlyArray<T>) => Array<T>;
|
|
1887
|
+
|
|
1888
|
+
/**
|
|
1889
|
+
* Returns a new array containing only one copy of each element in the original list.
|
|
1890
|
+
* Elements are compared by reference using Set.
|
|
1891
|
+
* Note: In `pipe`, use `uniq()` form instead of `uniq`. Otherwise, the inferred type is lost.
|
|
1892
|
+
* @param array
|
|
1893
|
+
* @signature
|
|
1894
|
+
* P.uniq(array)
|
|
1895
|
+
* @example
|
|
1896
|
+
* P.uniq([1, 2, 2, 5, 1, 6, 7]) // => [1, 2, 5, 6, 7]
|
|
1897
|
+
* P.pipe(
|
|
1898
|
+
* [1, 2, 2, 5, 1, 6, 7], // only 4 iterations
|
|
1899
|
+
* P.uniq(),
|
|
1900
|
+
* P.take(3)
|
|
1901
|
+
* ) // => [1, 2, 5]
|
|
1902
|
+
* @pipeable
|
|
1903
|
+
* @category Array
|
|
1904
|
+
*/
|
|
1905
|
+
declare function uniq<T>(array: ReadonlyArray<T>): Array<T>;
|
|
1906
|
+
declare function uniq<T>(): (array: ReadonlyArray<T>) => Array<T>;
|
|
1907
|
+
declare namespace uniq {
|
|
1908
|
+
function lazy(): (value: any) => LazyResult<any>;
|
|
1909
|
+
}
|
|
1910
|
+
|
|
1911
|
+
declare function uniqBy<T, K>(array: ReadonlyArray<T>, transformer: (item: T) => K): Array<T>;
|
|
1912
|
+
/**
|
|
1913
|
+
* Returns a new array containing only one copy of each element in the original list transformed by a function.
|
|
1914
|
+
* Elements are compared by reference using Set.
|
|
1915
|
+
* @param array
|
|
1916
|
+
* @signature
|
|
1917
|
+
* P.uniqBy(array, fn)
|
|
1918
|
+
* @example
|
|
1919
|
+
* P.uniqBy(
|
|
1920
|
+
* [{ n: 1 }, { n: 2 }, { n: 2 }, { n: 5 }, { n: 1 }, { n: 6 }, { n: 7 }],
|
|
1921
|
+
* (obj) => obj.n,
|
|
1922
|
+
* ) // => [{n: 1}, {n: 2}, {n: 5}, {n: 6}, {n: 7}]
|
|
1923
|
+
* P.pipe(
|
|
1924
|
+
* [{n: 1}, {n: 2}, {n: 2}, {n: 5}, {n: 1}, {n: 6}, {n: 7}], // only 4 iterations
|
|
1925
|
+
* P.uniqBy(obj => obj.n),
|
|
1926
|
+
* P.take(3)
|
|
1927
|
+
* ) // => [{n: 1}, {n: 2}, {n: 5}]
|
|
1928
|
+
* @pipeable
|
|
1929
|
+
* @category Array
|
|
1930
|
+
*/
|
|
1931
|
+
declare function uniqBy<T, K>(transformer: (item: T) => K): (array: ReadonlyArray<T>) => Array<T>;
|
|
1932
|
+
|
|
1933
|
+
type IsEquals<T> = (a: T, b: T) => boolean;
|
|
1934
|
+
declare function _lazy<T>(isEquals: IsEquals<T>): (value: T, index?: number, array?: Array<T>) => LazyResult<T>;
|
|
1935
|
+
/**
|
|
1936
|
+
* Returns a new array containing only one copy of each element in the original list.
|
|
1937
|
+
* Elements are compared by custom comparator isEquals.
|
|
1938
|
+
* @param array
|
|
1939
|
+
* @param isEquals the comparator
|
|
1940
|
+
* @signature
|
|
1941
|
+
* P.uniqWith(array, isEquals)
|
|
1942
|
+
* @example
|
|
1943
|
+
* P.uniqWith(
|
|
1944
|
+
* [{a: 1}, {a: 2}, {a: 2}, {a: 5}, {a: 1}, {a: 6}, {a: 7}],
|
|
1945
|
+
* P.equals,
|
|
1946
|
+
* ) // => [{a: 1}, {a: 2}, {a: 5}, {a: 6}, {a: 7}]
|
|
1947
|
+
* @dataFirst
|
|
1948
|
+
* @category Array
|
|
1949
|
+
*/
|
|
1950
|
+
declare function uniqWith<T>(array: ReadonlyArray<T>, isEquals: IsEquals<T>): Array<T>;
|
|
1951
|
+
/**
|
|
1952
|
+
* Returns a new array containing only one copy of each element in the original list.
|
|
1953
|
+
* Elements are compared by custom comparator isEquals.
|
|
1954
|
+
* @param isEquals the comparator
|
|
1955
|
+
* @signature P.uniqWith(isEquals)(array)
|
|
1956
|
+
* @example
|
|
1957
|
+
* P.uniqWith(P.equals)(
|
|
1958
|
+
* [{a: 1}, {a: 2}, {a: 2}, {a: 5}, {a: 1}, {a: 6}, {a: 7}],
|
|
1959
|
+
* ) // => [{a: 1}, {a: 2}, {a: 5}, {a: 6}, {a: 7}]
|
|
1960
|
+
* P.pipe(
|
|
1961
|
+
* [{a: 1}, {a: 2}, {a: 2}, {a: 5}, {a: 1}, {a: 6}, {a: 7}], // only 4 iterations
|
|
1962
|
+
* P.uniqWith(P.equals),
|
|
1963
|
+
* P.take(3)
|
|
1964
|
+
* ) // => [{a: 1}, {a: 2}, {a: 5}]
|
|
1965
|
+
* @dataLast
|
|
1966
|
+
* @category Object
|
|
1967
|
+
*/
|
|
1968
|
+
declare function uniqWith<T>(isEquals: IsEquals<T>): (array: ReadonlyArray<T>) => Array<T>;
|
|
1969
|
+
declare namespace uniqWith {
|
|
1970
|
+
const lazy: typeof _lazy & {
|
|
1971
|
+
indexed: true;
|
|
1972
|
+
};
|
|
1973
|
+
}
|
|
1974
|
+
|
|
1975
|
+
/**
|
|
1976
|
+
* Creates a new list from two supplied lists by pairing up equally-positioned items.
|
|
1977
|
+
* The length of the returned list will match the shortest of the two inputs.
|
|
1978
|
+
* @param first the first input list
|
|
1979
|
+
* @param second the second input list
|
|
1980
|
+
* @signature
|
|
1981
|
+
* P.zip(first, second)
|
|
1982
|
+
* @example
|
|
1983
|
+
* P.zip([1, 2], ['a', 'b']) // => [1, 'a'], [2, 'b']
|
|
1984
|
+
* @dataFirst
|
|
1985
|
+
* @category Array
|
|
1986
|
+
*/
|
|
1987
|
+
declare function zip<F, S>(first: ReadonlyArray<F>, second: ReadonlyArray<S>): Array<[F, S]>;
|
|
1988
|
+
/**
|
|
1989
|
+
* Creates a new list from two supplied lists by pairing up equally-positioned items.
|
|
1990
|
+
* The length of the returned list will match the shortest of the two inputs.
|
|
1991
|
+
* @param second the second input list
|
|
1992
|
+
* @signature
|
|
1993
|
+
* P.zip(second)(first)
|
|
1994
|
+
* @example
|
|
1995
|
+
* P.zip(['a', 'b'])([1, 2]) // => [[1, 'a'], [2, 'b']
|
|
1996
|
+
* @dataLast
|
|
1997
|
+
* @category Array
|
|
1998
|
+
*/
|
|
1999
|
+
declare function zip<S>(second: ReadonlyArray<S>): <F>(first: ReadonlyArray<F>) => Array<[F, S]>;
|
|
2000
|
+
|
|
2001
|
+
/**
|
|
2002
|
+
* Creates a new object from two supplied lists by pairing up equally-positioned items.
|
|
2003
|
+
* Key/value pairing is truncated to the length of the shorter of the two lists
|
|
2004
|
+
* @param first the first input list
|
|
2005
|
+
* @param second the second input list
|
|
2006
|
+
* @signature
|
|
2007
|
+
* P.zipObj(first, second)
|
|
2008
|
+
* @example
|
|
2009
|
+
* P.zipObj(['a', 'b'], [1, 2]) // => {a: 1, b: 2}
|
|
2010
|
+
* @dataFirst
|
|
2011
|
+
* @category Array
|
|
2012
|
+
*/
|
|
2013
|
+
declare function zipObj<F extends string | number | symbol, S>(first: ReadonlyArray<F>, second: ReadonlyArray<S>): Record<F, S>;
|
|
2014
|
+
/**
|
|
2015
|
+
* Creates a new object from two supplied lists by pairing up equally-positioned items.
|
|
2016
|
+
* Key/value pairing is truncated to the length of the shorter of the two lists
|
|
2017
|
+
* @param second the second input list
|
|
2018
|
+
* @signature
|
|
2019
|
+
* P.zipObj(second)(first)
|
|
2020
|
+
* @example
|
|
2021
|
+
* P.zipObj([1, 2])(['a', 'b']) // => {a: 1, b: 2}
|
|
2022
|
+
* @dataLast
|
|
2023
|
+
* @category Array
|
|
2024
|
+
*/
|
|
2025
|
+
declare function zipObj<S>(second: ReadonlyArray<S>): <F extends string | number | symbol>(first: ReadonlyArray<F>) => Record<F, S>;
|
|
2026
|
+
|
|
2027
|
+
/**
|
|
2028
|
+
* Creates a new list from two supplied lists by calling the supplied function
|
|
2029
|
+
* with the same-positioned element from each list.
|
|
2030
|
+
* @param first the first input list
|
|
2031
|
+
* @param second the second input list
|
|
2032
|
+
* @param fn the function applied to each position of the list
|
|
2033
|
+
* @signature
|
|
2034
|
+
* P.zipWith(first, second, fn)
|
|
2035
|
+
* @example
|
|
2036
|
+
* P.zipWith(['1', '2', '3'], ['a', 'b', 'c'], (a, b) => a + b) // => ['1a', '2b', '3c']
|
|
2037
|
+
* @dataFirst
|
|
2038
|
+
* @category Array
|
|
2039
|
+
*/
|
|
2040
|
+
declare function zipWith<F, S, R>(first: Array<F>, second: Array<S>, fn: (f: F, s: S) => R): Array<R>;
|
|
2041
|
+
/**
|
|
2042
|
+
* Creates a new list from two supplied lists by calling the supplied function
|
|
2043
|
+
* with the same-positioned element from each list.
|
|
2044
|
+
* @param fn the function applied to each position of the list
|
|
2045
|
+
* @signature
|
|
2046
|
+
* P.zipWith(fn)(first, second)
|
|
2047
|
+
* @example
|
|
2048
|
+
* P.zipWith((a, b) => a + b)(['1', '2', '3'], ['a', 'b', 'c']) // => ['1a', '2b', '3c']
|
|
2049
|
+
* @dataLast
|
|
2050
|
+
* @category Array
|
|
2051
|
+
*/
|
|
2052
|
+
declare function zipWith<F, S, R>(fn: (f: F, s: S) => R): (first: Array<F>, second: Array<S>) => Array<R>;
|
|
2053
|
+
/**
|
|
2054
|
+
* Creates a new list from two supplied lists by calling the supplied function
|
|
2055
|
+
* with the same-positioned element from each list.
|
|
2056
|
+
* @param fn the function applied to each position of the list
|
|
2057
|
+
* @param second the second input list
|
|
2058
|
+
* @signature
|
|
2059
|
+
* P.zipWith(fn)(first, second)
|
|
2060
|
+
* @example
|
|
2061
|
+
* P.zipWith((a, b) => a + b, ['a', 'b', 'c'])(['1', '2', '3']) // => ['1a', '2b', '3c']
|
|
2062
|
+
* @dataLast
|
|
2063
|
+
* @category Array
|
|
2064
|
+
*/
|
|
2065
|
+
declare function zipWith<F, S, R>(fn: (f: F, s: S) => R, second: Array<S>): (first: Array<F>) => Array<R>;
|
|
2066
|
+
|
|
2067
|
+
/**
|
|
2068
|
+
* Creates a data-last pipe function. First function must be always annotated. Other functions are automatically inferred.
|
|
2069
|
+
* @signature
|
|
2070
|
+
* P.createPipe(op1, op2, op3)(data);
|
|
2071
|
+
* @example
|
|
2072
|
+
* P.createPipe(
|
|
2073
|
+
* (x: number) => x * 2,
|
|
2074
|
+
* x => x * 3
|
|
2075
|
+
* )(1) // => 6
|
|
2076
|
+
* @category Function
|
|
2077
|
+
*/
|
|
2078
|
+
declare function createPipe<A, B>(op1: (input: A) => B): (value: A) => B;
|
|
2079
|
+
declare function createPipe<A, B, C>(op1: (input: A) => B, op2: (input: B) => C): (value: A) => C;
|
|
2080
|
+
declare function createPipe<A, B, C, D>(op1: (input: A) => B, op2: (input: B) => C, op3: (input: C) => D): (value: A) => D;
|
|
2081
|
+
declare function createPipe<A, B, C, D, E>(op1: (input: A) => B, op2: (input: B) => C, op3: (input: C) => D, op4: (input: D) => E): (value: A) => E;
|
|
2082
|
+
declare function createPipe<A, B, C, D, E, F>(op1: (input: A) => B, op2: (input: B) => C, op3: (input: C) => D, op4: (input: D) => E, op5: (input: E) => F): (value: A) => F;
|
|
2083
|
+
declare function createPipe<A, B, C, D, E, F, G>(op1: (input: A) => B, op2: (input: B) => C, op3: (input: C) => D, op4: (input: D) => E, op5: (input: E) => F, op6: (input: F) => G): (value: A) => G;
|
|
2084
|
+
declare function createPipe<A, B, C, D, E, F, G, H>(op1: (input: A) => B, op2: (input: B) => C, op3: (input: C) => D, op4: (input: D) => E, op5: (input: E) => F, op6: (input: F) => G, op7: (input: G) => H): (value: A) => H;
|
|
2085
|
+
|
|
2086
|
+
/**
|
|
2087
|
+
* A function that always returns the param passed to it
|
|
2088
|
+
* @signature
|
|
2089
|
+
* P.identity(data)
|
|
2090
|
+
* @example
|
|
2091
|
+
* P.identity('foo') // => 'foo'
|
|
2092
|
+
* @category Function
|
|
2093
|
+
*/
|
|
2094
|
+
declare function identity<T>(value: T): T;
|
|
2095
|
+
|
|
2096
|
+
/**
|
|
2097
|
+
* A function that returns always `undefined`.
|
|
2098
|
+
* @signature
|
|
2099
|
+
* P.noop()
|
|
2100
|
+
* @example
|
|
2101
|
+
* onSomething(P.noop)
|
|
2102
|
+
* @category Function
|
|
2103
|
+
*/
|
|
2104
|
+
declare function noop(): undefined;
|
|
2105
|
+
|
|
2106
|
+
/**
|
|
2107
|
+
* Creates a function that is restricted to invoking `func` once. Repeat calls to the function return the value of the first invocation.
|
|
2108
|
+
* @param fn the function to wrap
|
|
2109
|
+
* @signature P.once(fn)
|
|
2110
|
+
* @example
|
|
2111
|
+
* const initialize = P.once(createApplication);
|
|
2112
|
+
* initialize();
|
|
2113
|
+
* initialize();
|
|
2114
|
+
* // => `createApplication` is invoked once
|
|
2115
|
+
* @category Function
|
|
2116
|
+
*/
|
|
2117
|
+
declare function once<T>(fn: () => T): () => T;
|
|
2118
|
+
|
|
2119
|
+
/**
|
|
2120
|
+
* Perform left-to-right function composition.
|
|
2121
|
+
* @param value The initial value.
|
|
2122
|
+
* @param arguments the list of operations to apply.
|
|
2123
|
+
* @signature P.pipe(data, op1, op2, op3)
|
|
2124
|
+
* @example
|
|
2125
|
+
* P.pipe(
|
|
2126
|
+
* [1, 2, 3, 4],
|
|
2127
|
+
* P.map(x => x * 2),
|
|
2128
|
+
* arr => [arr[0] + arr[1], arr[2] + arr[3]],
|
|
2129
|
+
* ) // => [6, 14]
|
|
2130
|
+
*
|
|
2131
|
+
*
|
|
2132
|
+
* @dataFirst
|
|
2133
|
+
* @category Function
|
|
2134
|
+
*/
|
|
2135
|
+
declare function pipe<A, B>(value: A, op1: (input: A) => B): B;
|
|
2136
|
+
declare function pipe<A, B, C>(value: A, op1: (input: A) => B, op2: (input: B) => C): C;
|
|
2137
|
+
declare function pipe<A, B, C, D>(value: A, op1: (input: A) => B, op2: (input: B) => C, op3: (input: C) => D): D;
|
|
2138
|
+
declare function pipe<A, B, C, D, E>(value: A, op1: (input: A) => B, op2: (input: B) => C, op3: (input: C) => D, op4: (input: D) => E): E;
|
|
2139
|
+
declare function pipe<A, B, C, D, E, F>(value: A, op1: (input: A) => B, op2: (input: B) => C, op3: (input: C) => D, op4: (input: D) => E, op5: (input: E) => F): F;
|
|
2140
|
+
declare function pipe<A, B, C, D, E, F, G>(value: A, op1: (input: A) => B, op2: (input: B) => C, op3: (input: C) => D, op4: (input: D) => E, op5: (input: E) => F, op6: (input: F) => G): G;
|
|
2141
|
+
declare function pipe<A, B, C, D, E, F, G, H>(value: A, op1: (input: A) => B, op2: (input: B) => C, op3: (input: C) => D, op4: (input: D) => E, op5: (input: E) => F, op6: (input: F) => G, op7: (input: G) => H): H;
|
|
2142
|
+
declare function pipe<A, B, C, D, E, F, G, H, I>(value: A, op1: (input: A) => B, op2: (input: B) => C, op3: (input: C) => D, op4: (input: D) => E, op5: (input: E) => F, op6: (input: F) => G, op7: (input: G) => H, op8: (input: H) => I): I;
|
|
2143
|
+
declare function pipe<A, B, C, D, E, F, G, H, I, J>(value: A, op1: (input: A) => B, op2: (input: B) => C, op3: (input: C) => D, op4: (input: D) => E, op5: (input: E) => F, op6: (input: F) => G, op7: (input: G) => H, op8: (input: H) => I, op9: (input: I) => J): J;
|
|
2144
|
+
declare function pipe<A, B, C, D, E, F, G, H, I, J, K>(value: A, op01: (input: A) => B, op02: (input: B) => C, op03: (input: C) => D, op04: (input: D) => E, op05: (input: E) => F, op06: (input: F) => G, op07: (input: G) => H, op08: (input: H) => I, op09: (input: I) => J, op10: (input: J) => K): K;
|
|
2145
|
+
declare function pipe<A, B, C, D, E, F, G, H, I, J, K, L>(value: A, op01: (input: A) => B, op02: (input: B) => C, op03: (input: C) => D, op04: (input: D) => E, op05: (input: E) => F, op06: (input: F) => G, op07: (input: G) => H, op08: (input: H) => I, op09: (input: I) => J, op10: (input: J) => K, op11: (input: K) => L): L;
|
|
2146
|
+
declare function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M>(value: A, op01: (input: A) => B, op02: (input: B) => C, op03: (input: C) => D, op04: (input: D) => E, op05: (input: E) => F, op06: (input: F) => G, op07: (input: G) => H, op08: (input: H) => I, op09: (input: I) => J, op10: (input: J) => K, op11: (input: K) => L, op12: (input: L) => M): M;
|
|
2147
|
+
declare function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(value: A, op01: (input: A) => B, op02: (input: B) => C, op03: (input: C) => D, op04: (input: D) => E, op05: (input: E) => F, op06: (input: F) => G, op07: (input: G) => H, op08: (input: H) => I, op09: (input: I) => J, op10: (input: J) => K, op11: (input: K) => L, op12: (input: L) => M, op13: (input: M) => N): N;
|
|
2148
|
+
declare function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(value: A, op01: (input: A) => B, op02: (input: B) => C, op03: (input: C) => D, op04: (input: D) => E, op05: (input: E) => F, op06: (input: F) => G, op07: (input: G) => H, op08: (input: H) => I, op09: (input: I) => J, op10: (input: J) => K, op11: (input: K) => L, op12: (input: L) => M, op13: (input: M) => N, op14: (input: N) => O): O;
|
|
2149
|
+
declare function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(value: A, op01: (input: A) => B, op02: (input: B) => C, op03: (input: C) => D, op04: (input: D) => E, op05: (input: E) => F, op06: (input: F) => G, op07: (input: G) => H, op08: (input: H) => I, op09: (input: I) => J, op10: (input: J) => K, op11: (input: K) => L, op12: (input: L) => M, op13: (input: M) => N, op14: (input: N) => O, op15: (input: O) => P): P;
|
|
2150
|
+
|
|
2151
|
+
/**
|
|
2152
|
+
* Creates a function with `data-first` and `data-last` signatures.
|
|
2153
|
+
*
|
|
2154
|
+
* `purry` is a dynamic function and it's not type safe. It should be wrapped by a function that have proper typings.
|
|
2155
|
+
* Refer to the example below for correct usage.
|
|
2156
|
+
*
|
|
2157
|
+
* @param fn the function to purry.
|
|
2158
|
+
* @param args the arguments
|
|
2159
|
+
* @signature P.purry(fn, arguments);
|
|
2160
|
+
* @exampleRaw
|
|
2161
|
+
* function _findIndex(array, fn) {
|
|
2162
|
+
* for (let i = 0; i < array.length; i++) {
|
|
2163
|
+
* if (fn(array[i])) {
|
|
2164
|
+
* return i;
|
|
2165
|
+
* }
|
|
2166
|
+
* }
|
|
2167
|
+
* return -1;
|
|
2168
|
+
* }
|
|
2169
|
+
*
|
|
2170
|
+
* // data-first
|
|
2171
|
+
* function findIndex<T>(array: T[], fn: (item: T) => boolean): number;
|
|
2172
|
+
*
|
|
2173
|
+
* // data-last
|
|
2174
|
+
* function findIndex<T>(fn: (item: T) => boolean): (array: T[]) => number;
|
|
2175
|
+
*
|
|
2176
|
+
* function findIndex() {
|
|
2177
|
+
* return P.purry(_findIndex, arguments);
|
|
2178
|
+
* }
|
|
2179
|
+
* @category Function
|
|
2180
|
+
*/
|
|
2181
|
+
declare function purry(fn: any, args: IArguments | ReadonlyArray<any>, lazy?: any): any;
|
|
2182
|
+
|
|
2183
|
+
/**
|
|
2184
|
+
* Delay execution for a given number of milliseconds.
|
|
2185
|
+
*
|
|
2186
|
+
* @param timeout the number of milliseconds to wait
|
|
2187
|
+
* @signature
|
|
2188
|
+
* P.sleep(timeout)
|
|
2189
|
+
* @example
|
|
2190
|
+
* P.sleep(1000) // => Promise<void>
|
|
2191
|
+
* @category Function
|
|
2192
|
+
*/
|
|
2193
|
+
declare function sleep(timeout: number): Promise<void>;
|
|
2194
|
+
|
|
2195
|
+
type DefinitelyArray<T> = Extract<T, Array<any> | ReadonlyArray<any>> extends never ? ReadonlyArray<unknown> : Extract<T, Array<any> | ReadonlyArray<any>>;
|
|
2196
|
+
/**
|
|
2197
|
+
* A function that checks if the passed parameter is an Array and narrows its type accordingly
|
|
2198
|
+
* @param data the variable to check
|
|
2199
|
+
* @signature
|
|
2200
|
+
* P.isArray(data)
|
|
2201
|
+
* @returns true if the passed input is an Array, false otherwise
|
|
2202
|
+
* @example
|
|
2203
|
+
* P.isArray([5]) //=> true
|
|
2204
|
+
* P.isArray([]) //=> true
|
|
2205
|
+
* P.isArray('somethingElse') //=> false
|
|
2206
|
+
* @category Guard
|
|
2207
|
+
*/
|
|
2208
|
+
declare function isArray<T>(data: T | ReadonlyArray<unknown>): data is DefinitelyArray<T>;
|
|
2209
|
+
|
|
2210
|
+
type DefinitelyBoolean<T> = Extract<T, boolean> extends never ? boolean : Extract<T, boolean> extends any ? boolean : Extract<T, number>;
|
|
2211
|
+
/**
|
|
2212
|
+
* A function that checks if the passed parameter is a boolean and narrows its type accordingly
|
|
2213
|
+
* @param data the variable to check
|
|
2214
|
+
* @signature
|
|
2215
|
+
* P.isBoolean(data)
|
|
2216
|
+
* @returns true if the passed input is a boolean, false otherwise
|
|
2217
|
+
* @example
|
|
2218
|
+
* P.isBoolean(true) //=> true
|
|
2219
|
+
* P.isBoolean(false) //=> true
|
|
2220
|
+
* P.isBoolean('somethingElse') //=> false
|
|
2221
|
+
* @category Guard
|
|
2222
|
+
*/
|
|
2223
|
+
declare function isBoolean<T>(data: T | boolean): data is DefinitelyBoolean<T>;
|
|
2224
|
+
|
|
2225
|
+
/**
|
|
2226
|
+
* A function that checks if the passed parameter is a Date and narrows its type accordingly
|
|
2227
|
+
* @param data the variable to check
|
|
2228
|
+
* @signature
|
|
2229
|
+
* P.isDate(data)
|
|
2230
|
+
* @returns true if the passed input is a Date, false otherwise
|
|
2231
|
+
* @example
|
|
2232
|
+
* P.isDate(new Date()) //=> true
|
|
2233
|
+
* P.isDate('somethingElse') //=> false
|
|
2234
|
+
* @category Guard
|
|
2235
|
+
*/
|
|
2236
|
+
declare function isDate(data: unknown): data is Date;
|
|
2237
|
+
|
|
2238
|
+
/**
|
|
2239
|
+
* A function that checks if the passed parameter is defined and narrows its type accordingly.
|
|
2240
|
+
* To test specifically for `undefined` (and not `null`) use the strict variant of this function.
|
|
2241
|
+
* @param data the variable to check
|
|
2242
|
+
* @signature
|
|
2243
|
+
* P.isDefined(data)
|
|
2244
|
+
* P.isDefined.strict(data)
|
|
2245
|
+
* @returns true if the passed input is defined, false otherwise
|
|
2246
|
+
* @example
|
|
2247
|
+
* P.isDefined('string') //=> true
|
|
2248
|
+
* P.isDefined(null) //=> false
|
|
2249
|
+
* P.isDefined(undefined) //=> false
|
|
2250
|
+
* P.isDefined.strict(null) //=> true
|
|
2251
|
+
* P.isDefined.strict(undefined) //=> false
|
|
2252
|
+
* @category Guard
|
|
2253
|
+
* @strict
|
|
2254
|
+
*/
|
|
2255
|
+
declare function isDefined<T>(data: T): data is NonNullable<T>;
|
|
2256
|
+
declare namespace isDefined {
|
|
2257
|
+
function strict<T>(data: T | undefined): data is T;
|
|
2258
|
+
}
|
|
2259
|
+
|
|
2260
|
+
/**
|
|
2261
|
+
* A function that checks if the passed parameter is empty
|
|
2262
|
+
* @param data the variable to check
|
|
2263
|
+
* @signature
|
|
2264
|
+
* P.isEmpty(data)
|
|
2265
|
+
* @returns true if the passed input is empty, false otherwise
|
|
2266
|
+
* @example
|
|
2267
|
+
* P.isEmpty('') //=> true
|
|
2268
|
+
* P.isEmpty([]) //=> true
|
|
2269
|
+
* P.isEmpty({}) //=> true
|
|
2270
|
+
* P.isEmpty('test') //=> false
|
|
2271
|
+
* P.isEmpty([1, 2, 3]) //=> false
|
|
2272
|
+
* P.isEmpty({ length: 0 }) //=> false
|
|
2273
|
+
* @category Function
|
|
2274
|
+
*/
|
|
2275
|
+
declare function isEmpty(data: string): data is '';
|
|
2276
|
+
declare function isEmpty(data: ReadonlyArray<unknown> | []): data is [];
|
|
2277
|
+
declare function isEmpty<T extends Readonly<Record<PropertyKey, unknown>>>(data: T): data is Record<keyof T, never>;
|
|
2278
|
+
|
|
2279
|
+
type DefinitelyError<T> = Extract<T, Error> extends never ? Error : Extract<T, Error>;
|
|
2280
|
+
/**
|
|
2281
|
+
* A function that checks if the passed parameter is an Error and narrows its type accordingly
|
|
2282
|
+
* @param data the variable to check
|
|
2283
|
+
* @signature
|
|
2284
|
+
* P.isError(data)
|
|
2285
|
+
* @returns true if the passed input is an Error, false otherwise
|
|
2286
|
+
* @example
|
|
2287
|
+
* P.isError(new Error('message')) //=> true
|
|
2288
|
+
* P.isError('somethingElse') //=> false
|
|
2289
|
+
* @category Guard
|
|
2290
|
+
*/
|
|
2291
|
+
declare function isError<T>(data: T | Error): data is DefinitelyError<T>;
|
|
2292
|
+
|
|
2293
|
+
type DefinitelyFunction<T> = Extract<T, Function> extends never ? Function : Extract<T, Function>;
|
|
2294
|
+
/**
|
|
2295
|
+
* A function that checks if the passed parameter is a Function and narrows its type accordingly
|
|
2296
|
+
* @param data the variable to check
|
|
2297
|
+
* @signature
|
|
2298
|
+
* P.isFunction(data)
|
|
2299
|
+
* @returns true if the passed input is a Function, false otherwise
|
|
2300
|
+
* @example
|
|
2301
|
+
* P.isFunction(() => {}) //=> true
|
|
2302
|
+
* P.isFunction('somethingElse') //=> false
|
|
2303
|
+
* @category Guard
|
|
2304
|
+
*/
|
|
2305
|
+
declare function isFunction<T>(data: T | Function): data is DefinitelyFunction<T>;
|
|
2306
|
+
|
|
2307
|
+
/**
|
|
2308
|
+
* A function that checks if the passed parameter is Nil (null or undefined) and narrows its type accordingly
|
|
2309
|
+
* @param data the variable to check
|
|
2310
|
+
* @signature
|
|
2311
|
+
* P.isNil(data)
|
|
2312
|
+
* @returns true if the passed input is Nil (null or undefined), false otherwise
|
|
2313
|
+
* @example
|
|
2314
|
+
* P.isNil(undefined) //=> true
|
|
2315
|
+
* P.isNil(null) //=> true
|
|
2316
|
+
* P.isNil('somethingElse') //=> false
|
|
2317
|
+
* @category Guard
|
|
2318
|
+
*/
|
|
2319
|
+
declare function isNil<T>(data: T): data is Extract<T, null | undefined>;
|
|
2320
|
+
|
|
2321
|
+
/**
|
|
2322
|
+
* A function that checks if the passed parameter is not `null` and narrows its type accordingly.
|
|
2323
|
+
* Notice that `undefined` is not null!
|
|
2324
|
+
* @param data the variable to check
|
|
2325
|
+
* @signature
|
|
2326
|
+
* P.isNonNull(data)
|
|
2327
|
+
* @returns true if the passed input is defined, false otherwise
|
|
2328
|
+
* @example
|
|
2329
|
+
* P.isNonNull('string') //=> true
|
|
2330
|
+
* P.isNonNull(null) //=> false
|
|
2331
|
+
* P.isNonNull(undefined) //=> true
|
|
2332
|
+
* @category Guard
|
|
2333
|
+
*/
|
|
2334
|
+
declare function isNonNull<T>(data: T | null): data is T;
|
|
2335
|
+
|
|
2336
|
+
/**
|
|
2337
|
+
* A function that takes a guard function as predicate and returns a guard that negates it
|
|
2338
|
+
* @param predicate the guard function to negate
|
|
2339
|
+
* @signature
|
|
2340
|
+
* P.isNot(P.isTruthy)(data)
|
|
2341
|
+
* @returns function A guard function
|
|
2342
|
+
* @example
|
|
2343
|
+
* P.isNot(P.isTruthy)(false) //=> true
|
|
2344
|
+
* P.isNot(P.isTruthy)(true) //=> false
|
|
2345
|
+
* @dataLast
|
|
2346
|
+
* @category Guard
|
|
2347
|
+
*/
|
|
2348
|
+
declare function isNot<T, S extends T>(predicate: (data: T) => data is S): (data: T) => data is Exclude<T, S>;
|
|
2349
|
+
declare function isNot<T>(predicate: (data: T) => any): (data: T) => boolean;
|
|
2350
|
+
|
|
2351
|
+
type DefinitelyNumber<T> = Extract<T, number> extends never ? number : Extract<T, number> extends any ? number : Extract<T, number>;
|
|
2352
|
+
/**
|
|
2353
|
+
* A function that checks if the passed parameter is a number and narrows its type accordingly
|
|
2354
|
+
* @param data the variable to check
|
|
2355
|
+
* @signature
|
|
2356
|
+
* R.isNumber(data)
|
|
2357
|
+
* @returns true if the passed input is a number, false otherwise
|
|
2358
|
+
* @example
|
|
2359
|
+
* R.isNumber(1) //=> true
|
|
2360
|
+
* R.isNumber('notANumber') //=> false
|
|
2361
|
+
* @category Guard
|
|
2362
|
+
*/
|
|
2363
|
+
declare function isNumber<T>(data: T | number): data is DefinitelyNumber<T>;
|
|
2364
|
+
|
|
2365
|
+
type DefinitelyObject<T> = Exclude<Extract<T, object>, Array<any> | Function | ReadonlyArray<any>> extends never ? Record<string, unknown> : Exclude<Extract<T, object>, Array<any> | Function | ReadonlyArray<any>>;
|
|
2366
|
+
/**
|
|
2367
|
+
* A function that checks if the passed parameter is of type Object and narrows its type accordingly
|
|
2368
|
+
* @param data the variable to check
|
|
2369
|
+
* @signature
|
|
2370
|
+
* P.isObject(data)
|
|
2371
|
+
* @returns true if the passed input is an Object, Promise, Date or Error, false otherwise
|
|
2372
|
+
* @example
|
|
2373
|
+
* P.isObject({}) //=> true
|
|
2374
|
+
* P.isObject(Promise.resolve("something")) //=> true
|
|
2375
|
+
* P.isObject(new Date()) //=> true
|
|
2376
|
+
* P.isObject(new Error("error")) //=> true
|
|
2377
|
+
* P.isObject('somethingElse') //=> false
|
|
2378
|
+
* @category Guard
|
|
2379
|
+
*/
|
|
2380
|
+
declare function isObject<T>(data: T | object): data is DefinitelyObject<T>;
|
|
2381
|
+
|
|
2382
|
+
/**
|
|
2383
|
+
* A function that checks if the passed parameter is a Promise and narrows its type accordingly
|
|
2384
|
+
* @param data the variable to check
|
|
2385
|
+
* @signature
|
|
2386
|
+
* P.isPromise(data)
|
|
2387
|
+
* @returns true if the passed input is a Promise, false otherwise
|
|
2388
|
+
* @example
|
|
2389
|
+
* P.isPromise(Promise.resolve(5)) //=> true
|
|
2390
|
+
* P.isPromise(Promise.reject(5)) //=> true
|
|
2391
|
+
* P.isPromise('somethingElse') //=> false
|
|
2392
|
+
* @category Guard
|
|
2393
|
+
*/
|
|
2394
|
+
declare function isPromise<T, S>(data: Promise<T> | S): data is Promise<T>;
|
|
2395
|
+
|
|
2396
|
+
type DefinitelyString<T> = Extract<T, string> extends never ? string : Extract<T, string> extends any ? string : Extract<T, string>;
|
|
2397
|
+
/**
|
|
2398
|
+
* A function that checks if the passed parameter is a string and narrows its type accordingly
|
|
2399
|
+
* @param data the variable to check
|
|
2400
|
+
* @signature
|
|
2401
|
+
* P.isString(data)
|
|
2402
|
+
* @returns true if the passed input is a string, false otherwise
|
|
2403
|
+
* @example
|
|
2404
|
+
* P.isString('string') //=> true
|
|
2405
|
+
* P.isString(1) //=> false
|
|
2406
|
+
* @category Guard
|
|
2407
|
+
*/
|
|
2408
|
+
declare function isString<T>(data: T | string): data is DefinitelyString<T>;
|
|
2409
|
+
|
|
2410
|
+
/**
|
|
2411
|
+
* A function that checks if the passed parameter is truthy and narrows its type accordingly
|
|
2412
|
+
* @param data the variable to check
|
|
2413
|
+
* @signature
|
|
2414
|
+
* P.isTruthy(data)
|
|
2415
|
+
* @returns true if the passed input is truthy, false otherwise
|
|
2416
|
+
* @example
|
|
2417
|
+
* P.isTruthy('somethingElse') //=> true
|
|
2418
|
+
* P.isTruthy(null) //=> false
|
|
2419
|
+
* P.isTruthy(undefined) //=> false
|
|
2420
|
+
* P.isTruthy(false) //=> false
|
|
2421
|
+
* P.isTruthy(0) //=> false
|
|
2422
|
+
* P.isTruthy('') //=> false
|
|
2423
|
+
* @category Guard
|
|
2424
|
+
*/
|
|
2425
|
+
declare function isTruthy<T>(data: T): data is Exclude<T, null | undefined | false | '' | 0>;
|
|
2426
|
+
|
|
2427
|
+
/**
|
|
2428
|
+
* Clamp the given value within the inclusive min and max bounds.
|
|
2429
|
+
* @param value the number
|
|
2430
|
+
* @param limits the bounds limits
|
|
2431
|
+
* @param limits.min the minimal bounds limits
|
|
2432
|
+
* @param limits.max the maximal bounds limits
|
|
2433
|
+
* @signature
|
|
2434
|
+
* P.clamp(value, { min, max });
|
|
2435
|
+
* @example
|
|
2436
|
+
* clamp(10, { min: 20 }) // => 20
|
|
2437
|
+
* clamp(10, { max: 5 }) // => 5
|
|
2438
|
+
* clamp(10, { max: 20, min: 5 }) // => 10
|
|
2439
|
+
* @dataFirst
|
|
2440
|
+
* @category Number
|
|
2441
|
+
*/
|
|
2442
|
+
declare function clamp(value: number, limits: {
|
|
2443
|
+
min?: number;
|
|
2444
|
+
max?: number;
|
|
2445
|
+
}): number;
|
|
2446
|
+
/**
|
|
2447
|
+
* Clamp the given value within the inclusive min and max bounds.
|
|
2448
|
+
* @param limits the bounds limits
|
|
2449
|
+
* @param limits.min the minimal bounds limits
|
|
2450
|
+
* @param limits.max the maximal bounds limits
|
|
2451
|
+
* @signature
|
|
2452
|
+
* P.clamp({ min, max })(value);
|
|
2453
|
+
* @example
|
|
2454
|
+
* clamp({ min: 20 })(10) // => 20
|
|
2455
|
+
* clamp({ max: 5 })(10) // => 5
|
|
2456
|
+
* clamp({ max: 20, min: 5 })(10) // => 10
|
|
2457
|
+
* @dataLast
|
|
2458
|
+
* @category Number
|
|
2459
|
+
*/
|
|
2460
|
+
declare function clamp(limits: {
|
|
2461
|
+
min?: number;
|
|
2462
|
+
max?: number;
|
|
2463
|
+
}): (value: number) => number;
|
|
2464
|
+
|
|
2465
|
+
/**
|
|
2466
|
+
* Add a new property to an object.
|
|
2467
|
+
* @param obj the target object
|
|
2468
|
+
* @param prop the property name
|
|
2469
|
+
* @param value the property value
|
|
2470
|
+
* @signature
|
|
2471
|
+
* P.addProp(obj, prop, value)
|
|
2472
|
+
* @example
|
|
2473
|
+
* P.addProp({firstName: 'john'}, 'lastName', 'doe') // => {firstName: 'john', lastName: 'doe'}
|
|
2474
|
+
* @dataFirst
|
|
2475
|
+
* @category Object
|
|
2476
|
+
*/
|
|
2477
|
+
declare function addProp<T extends Record<PropertyKey, any>, K extends string, V>(obj: T, prop: K, value: V): T & {
|
|
2478
|
+
[x in K]: V;
|
|
2479
|
+
};
|
|
2480
|
+
/**
|
|
2481
|
+
* Add a new property to an object.
|
|
2482
|
+
* @param prop the property name
|
|
2483
|
+
* @param value the property value
|
|
2484
|
+
* @signature
|
|
2485
|
+
* P.addProp(prop, value)(obj)
|
|
2486
|
+
* @example
|
|
2487
|
+
* P.addProp('lastName', 'doe')({firstName: 'john'}) // => {firstName: 'john', lastName: 'doe'}
|
|
2488
|
+
* @dataLast
|
|
2489
|
+
* @category Object
|
|
2490
|
+
*/
|
|
2491
|
+
declare function addProp<T extends Record<PropertyKey, any>, K extends string, V>(prop: K, value: V): (obj: T) => T & {
|
|
2492
|
+
[x in K]: V;
|
|
2493
|
+
};
|
|
2494
|
+
|
|
2495
|
+
/**
|
|
2496
|
+
* Creates a deep copy of the value. Supported types: `Array`, `Object`, `Number`, `String`, `Boolean`, `Date`, `RegExp`. Functions are assigned by reference rather than copied.
|
|
2497
|
+
* @param value the object to clone
|
|
2498
|
+
* @category Object
|
|
2499
|
+
* @signature P.clone(value)
|
|
2500
|
+
* @example P.clone({foo: 'bar'}) // {foo: 'bar'}
|
|
2501
|
+
*/
|
|
2502
|
+
declare function clone<T>(value: T): T;
|
|
2503
|
+
|
|
2504
|
+
/**
|
|
2505
|
+
* Returns true if its arguments are equivalent, false otherwise.
|
|
2506
|
+
* NOTE: Doesn't handle cyclical data structures.
|
|
2507
|
+
* @param a the first object to compare
|
|
2508
|
+
* @param b the second object to compare
|
|
2509
|
+
* @signature
|
|
2510
|
+
* P.equals(a, b)
|
|
2511
|
+
* @example
|
|
2512
|
+
* P.equals(1, 1) //=> true
|
|
2513
|
+
* P.equals(1, '1') //=> false
|
|
2514
|
+
* P.equals([1, 2, 3], [1, 2, 3]) //=> true
|
|
2515
|
+
* @dataFirst
|
|
2516
|
+
* @category Object
|
|
2517
|
+
*/
|
|
2518
|
+
declare function equals(a: any, b: any): boolean;
|
|
2519
|
+
/**
|
|
2520
|
+
* Returns true if its arguments are equivalent, false otherwise.
|
|
2521
|
+
* NOTE: Doesn't handle cyclical data structures.
|
|
2522
|
+
* @param a the first object to compare
|
|
2523
|
+
* @signature
|
|
2524
|
+
* P.equals(b)(a)
|
|
2525
|
+
* @example
|
|
2526
|
+
* P.equals(1)(1) //=> true
|
|
2527
|
+
* P.equals('1')(1) //=> false
|
|
2528
|
+
* P.equals([1, 2, 3])([1, 2, 3]) //=> true
|
|
2529
|
+
* @dataLast
|
|
2530
|
+
* @category Object
|
|
2531
|
+
*/
|
|
2532
|
+
declare function equals(a: any): (b: any) => boolean;
|
|
2533
|
+
|
|
2534
|
+
type IndexedIteratee<T extends Record<PropertyKey, any>, K extends keyof T> = (value: T[K], key: K, obj: T) => void;
|
|
2535
|
+
type UnindexedIteratee<T extends Record<PropertyKey, any>> = (value: T[keyof T]) => void;
|
|
2536
|
+
/**
|
|
2537
|
+
* Iterate an object using a defined callback function. The original object is returned.
|
|
2538
|
+
* @param object The object.
|
|
2539
|
+
* @param fn The callback function.
|
|
2540
|
+
* @returns The original object
|
|
2541
|
+
* @signature
|
|
2542
|
+
* P.forEachObj(object, fn)
|
|
2543
|
+
* @example
|
|
2544
|
+
* P.forEachObj({a: 1}, (val) => {
|
|
2545
|
+
* console.log(`${val}`)
|
|
2546
|
+
* }) // "1"
|
|
2547
|
+
* P.forEachObj.indexed({a: 1}, (val, key, obj) => {
|
|
2548
|
+
* console.log(`${key}: ${val}`)
|
|
2549
|
+
* }) // "a: 1"
|
|
2550
|
+
* @dataFirst
|
|
2551
|
+
* @category Object
|
|
2552
|
+
*/
|
|
2553
|
+
declare function forEachObj<T extends Record<PropertyKey, any>>(object: T, fn: UnindexedIteratee<T>): T;
|
|
2554
|
+
/**
|
|
2555
|
+
* Iterate an object using a defined callback function. The original object is returned.
|
|
2556
|
+
* @param fn The callback function.
|
|
2557
|
+
* @signature
|
|
2558
|
+
* P.forEachObj(fn)(object)
|
|
2559
|
+
* @example
|
|
2560
|
+
* P.pipe(
|
|
2561
|
+
* {a: 1},
|
|
2562
|
+
* P.forEachObj((val) => console.log(`${val}`))
|
|
2563
|
+
* ) // "1"
|
|
2564
|
+
* P.pipe(
|
|
2565
|
+
* {a: 1},
|
|
2566
|
+
* P.forEachObj.indexed((val, key) => console.log(`${key}: ${val}`))
|
|
2567
|
+
* ) // "a: 1"
|
|
2568
|
+
* @dataLast
|
|
2569
|
+
* @category Object
|
|
2570
|
+
*/
|
|
2571
|
+
declare function forEachObj<T extends Record<PropertyKey, any>>(fn: UnindexedIteratee<T>): (object: T) => T;
|
|
2572
|
+
declare namespace forEachObj {
|
|
2573
|
+
function indexed<T extends Record<PropertyKey, any>>(object: T, fn: IndexedIteratee<T, keyof T>): T;
|
|
2574
|
+
function indexed<T extends Record<PropertyKey, any>>(fn: IndexedIteratee<T, keyof T>): (object: T) => T;
|
|
2575
|
+
}
|
|
2576
|
+
|
|
2577
|
+
type Entry<Key extends PropertyKey = PropertyKey, Value = unknown> = readonly [
|
|
2578
|
+
key: Key,
|
|
2579
|
+
value: Value
|
|
2580
|
+
];
|
|
2581
|
+
type Strict$1 = <Entries extends IterableContainer<Entry>>(entries: Entries) => StrictOut<Entries>;
|
|
2582
|
+
type StrictOut<Entries> = Entries extends readonly [infer First, ...infer Tail] ? FromPairsTuple<First, Tail> : Entries extends readonly [...infer Head, infer Last] ? FromPairsTuple<Last, Head> : Entries extends IterableContainer<Entry> ? FromPairsArray<Entries> : 'ERROR: Entries array-like could not be infered';
|
|
2583
|
+
type FromPairsTuple<E, Rest> = E extends Entry ? Record<E[0], E[1]> & StrictOut<Rest> : 'ERROR: Array-like contains a non-entry element';
|
|
2584
|
+
type FromPairsArray<Entries extends IterableContainer<Entry>> = string extends AllKeys$1<Entries> ? Record<string, Entries[number][1]> : number extends AllKeys$1<Entries> ? Record<number, Entries[number][1]> : symbol extends AllKeys$1<Entries> ? Record<symbol, Entries[number][1]> : FromPairsArrayWithLiteralKeys<Entries>;
|
|
2585
|
+
type FromPairsArrayWithLiteralKeys<Entries extends IterableContainer<Entry>> = {
|
|
2586
|
+
[K in AllKeys$1<Entries>]?: ValueForKey<Entries, K>;
|
|
2587
|
+
};
|
|
2588
|
+
type AllKeys$1<Entries extends IterableContainer<Entry>> = Extract<Entries[number], Entry>[0];
|
|
2589
|
+
type ValueForKey<Entries extends IterableContainer<Entry>, K extends PropertyKey> = (Extract<Entries[number], Entry<K>> extends never ? Entries[number] : Extract<Entries[number], Entry<K>>)[1];
|
|
2590
|
+
/**
|
|
2591
|
+
* Creates a new object from an array of tuples by pairing up first and second elements as {[key]: value}.
|
|
2592
|
+
* If a tuple is not supplied for any element in the array, the element will be ignored
|
|
2593
|
+
* If duplicate keys exist, the tuple with the greatest index in the input array will be preferred.
|
|
2594
|
+
*
|
|
2595
|
+
* The strict option supports more sophisticated use-cases like those that would
|
|
2596
|
+
* result when calling the strict `toPairs` function.
|
|
2597
|
+
* @param pairs the list of input tuples
|
|
2598
|
+
* @signature
|
|
2599
|
+
* P.fromPairs(tuples)
|
|
2600
|
+
* P.fromPairs.strict(tuples)
|
|
2601
|
+
* @example
|
|
2602
|
+
* P.fromPairs([['a', 'b'], ['c', 'd']]) // => {a: 'b', c: 'd'} (type: Record<string, string>)
|
|
2603
|
+
* P.fromPairs.strict(['a', 1] as const) // => {a: 1} (type: {a: 1})
|
|
2604
|
+
* @category Object
|
|
2605
|
+
* @strict
|
|
2606
|
+
*/
|
|
2607
|
+
declare function fromPairs<V>(pairs: ReadonlyArray<Entry<number, V>>): Record<number, V>;
|
|
2608
|
+
declare function fromPairs<V>(pairs: ReadonlyArray<Entry<string, V>>): Record<string, V>;
|
|
2609
|
+
declare namespace fromPairs {
|
|
2610
|
+
const strict: Strict$1;
|
|
2611
|
+
}
|
|
2612
|
+
|
|
2613
|
+
type Inverted<T extends object> = T[keyof T] extends PropertyKey ? Record<T[keyof T], keyof T> : never;
|
|
2614
|
+
/**
|
|
2615
|
+
* Returns an object whose keys are values are swapped. If the object contains duplicate values,
|
|
2616
|
+
* subsequent values will overwrite previous values.
|
|
2617
|
+
* @param object the object
|
|
2618
|
+
* @signature
|
|
2619
|
+
* P.invert(object)
|
|
2620
|
+
* @example
|
|
2621
|
+
* P.invert({ a: "d", b: "e", c: "f" }) // => { d: "a", e: "b", f: "c" }
|
|
2622
|
+
* @dataFirst
|
|
2623
|
+
* @category Object
|
|
2624
|
+
* @pipeable
|
|
2625
|
+
*/
|
|
2626
|
+
declare function invert<T extends object>(object: T): Inverted<T>;
|
|
2627
|
+
/**
|
|
2628
|
+
* Returns an object whose keys are values are swapped. If the object contains duplicate values,
|
|
2629
|
+
* subsequent values will overwrite previous values.
|
|
2630
|
+
* @signature
|
|
2631
|
+
* P.invert()(object)
|
|
2632
|
+
* @example
|
|
2633
|
+
* P.pipe({ a: "d", b: "e", c: "f" }, P.invert()); // => { d: "a", e: "b", f: "c" }
|
|
2634
|
+
* @dataLast
|
|
2635
|
+
* @category Object
|
|
2636
|
+
* @pipeable
|
|
2637
|
+
*/
|
|
2638
|
+
declare function invert<T extends object>(): (object: T) => Inverted<T>;
|
|
2639
|
+
|
|
2640
|
+
/**
|
|
2641
|
+
* Returns a new array containing the keys of the array or object.
|
|
2642
|
+
* @param source Either an array or an object
|
|
2643
|
+
* @signature
|
|
2644
|
+
* P.keys(source)
|
|
2645
|
+
* P.keys.strict(source)
|
|
2646
|
+
* @example
|
|
2647
|
+
* P.keys(['x', 'y', 'z']) // => ['0', '1', '2']
|
|
2648
|
+
* P.keys({ a: 'x', b: 'y', c: 'z' }) // => ['a', 'b', 'c']
|
|
2649
|
+
* P.pipe(
|
|
2650
|
+
* { a: 'x', b: 'y', c: 'z' },
|
|
2651
|
+
* P.keys,
|
|
2652
|
+
* P.first
|
|
2653
|
+
* ) // => 'a'
|
|
2654
|
+
* P.keys.strict({ a: 'x', b: 'y', 5: 'z' } as const ) // => ['a', 'b', '5'], typed Array<'a' | 'b' | '5'>
|
|
2655
|
+
* @pipeable
|
|
2656
|
+
* @strict
|
|
2657
|
+
* @category Object
|
|
2658
|
+
*/
|
|
2659
|
+
|
|
2660
|
+
type Strict = <T extends object>(source: T) => Keys<T>;
|
|
2661
|
+
type Keys<T> = T extends IterableContainer ? ArrayKeys<T> : ObjectKeys$1<T>;
|
|
2662
|
+
type ArrayKeys<T extends IterableContainer> = {
|
|
2663
|
+
-readonly [Index in keyof T]: Index extends string | number ? `${IsIndexAfterSpread<T, Index> extends true ? number : Index}` : never;
|
|
2664
|
+
};
|
|
2665
|
+
type IsIndexAfterSpread<T extends IterableContainer, Index extends string | number> = IndicesAfterSpread<T> extends never ? false : Index extends `${IndicesAfterSpread<T>}` ? true : false;
|
|
2666
|
+
type IndicesAfterSpread<T extends ReadonlyArray<unknown> | [], Iterations extends ReadonlyArray<unknown> = []> = T[number] extends never ? never : T extends readonly [unknown, ...infer Tail] ? IndicesAfterSpread<Tail, [unknown, ...Iterations]> : T extends readonly [...infer Head, unknown] ? IndicesAfterSpread<Head, [unknown, ...Iterations]> | Iterations['length'] : Iterations['length'];
|
|
2667
|
+
type ObjectKeys$1<T> = T extends Record<PropertyKey, never> ? [] : Array<`${Exclude<keyof T, symbol>}`>;
|
|
2668
|
+
declare function keys(source: Record<PropertyKey, unknown> | ArrayLike<unknown>): Array<string>;
|
|
2669
|
+
declare namespace keys {
|
|
2670
|
+
const strict: Strict;
|
|
2671
|
+
}
|
|
2672
|
+
|
|
2673
|
+
/**
|
|
2674
|
+
* Maps keys of `object` and keeps the same values.
|
|
2675
|
+
* @param object the object to map
|
|
2676
|
+
* @param fn the mapping function
|
|
2677
|
+
* @signature
|
|
2678
|
+
* P.mapKeys(object, fn)
|
|
2679
|
+
* @example
|
|
2680
|
+
* P.mapKeys({a: 1, b: 2}, (key, value) => key + value) // => { a1: 1, b2: 2 }
|
|
2681
|
+
* @dataFirst
|
|
2682
|
+
* @category Object
|
|
2683
|
+
*/
|
|
2684
|
+
declare function mapKeys<T, S extends keyof any>(object: T, fn: (key: keyof T, value: T[keyof T]) => S): Record<S, T[keyof T]>;
|
|
2685
|
+
/**
|
|
2686
|
+
* Maps keys of `object` and keeps the same values.
|
|
2687
|
+
* @param fn the mapping function
|
|
2688
|
+
* @signature
|
|
2689
|
+
* P.mapKeys(fn)(object)
|
|
2690
|
+
* @example
|
|
2691
|
+
* P.pipe({a: 1, b: 2}, P.mapKeys((key, value) => key + value)) // => { a1: 1, b2: 2 }
|
|
2692
|
+
* @dataLast
|
|
2693
|
+
* @category Object
|
|
2694
|
+
*/
|
|
2695
|
+
declare function mapKeys<T, S extends keyof any>(fn: (key: keyof T, value: T[keyof T]) => S): (object: T) => Record<S, T[keyof T]>;
|
|
2696
|
+
|
|
2697
|
+
/**
|
|
2698
|
+
* Maps values of `object` and keeps the same keys.
|
|
2699
|
+
* @param object the object to map
|
|
2700
|
+
* @param fn the mapping function
|
|
2701
|
+
* @signature
|
|
2702
|
+
* P.mapValues(object, fn)
|
|
2703
|
+
* @example
|
|
2704
|
+
* P.mapValues({a: 1, b: 2}, (value, key) => value + key) // => {a: '1a', b: '2b'}
|
|
2705
|
+
* @dataFirst
|
|
2706
|
+
* @category Object
|
|
2707
|
+
*/
|
|
2708
|
+
declare function mapValues<T extends Record<PropertyKey, any>, S>(object: T, fn: (value: T[keyof T], key: keyof T) => S): Record<keyof T, S>;
|
|
2709
|
+
/**
|
|
2710
|
+
* Maps values of `object` and keeps the same keys.
|
|
2711
|
+
* @param fn the mapping function
|
|
2712
|
+
* @signature
|
|
2713
|
+
* P.mapValues(fn)(object)
|
|
2714
|
+
* @example
|
|
2715
|
+
* P.pipe({a: 1, b: 2}, P.mapValues((value, key) => value + key)) // => {a: '1a', b: '2b'}
|
|
2716
|
+
* @dataLast
|
|
2717
|
+
* @category Object
|
|
2718
|
+
*/
|
|
2719
|
+
declare function mapValues<T extends Record<PropertyKey, any>, S>(fn: (value: T[keyof T], key: keyof T) => S): (object: T) => Record<keyof T, S>;
|
|
2720
|
+
|
|
2721
|
+
/**
|
|
2722
|
+
* Merges two objects. The same as `Object.assign`.
|
|
2723
|
+
* `b` object will override properties of `a`.
|
|
2724
|
+
* @param a the first object
|
|
2725
|
+
* @param b the second object
|
|
2726
|
+
* @signature
|
|
2727
|
+
* P.merge(a, b)
|
|
2728
|
+
* @example
|
|
2729
|
+
* P.merge({ x: 1, y: 2 }, { y: 10, z: 2 }) // => { x: 1, y: 10, z: 2 }
|
|
2730
|
+
* @dataFirst
|
|
2731
|
+
* @category Object
|
|
2732
|
+
*/
|
|
2733
|
+
declare function merge<A, B>(a: A, b: B): A & B;
|
|
2734
|
+
/**
|
|
2735
|
+
* Merges two objects. The same as `Object.assign`. `b` object will override properties of `a`.
|
|
2736
|
+
* @param b the second object
|
|
2737
|
+
* @signature
|
|
2738
|
+
* P.merge(b)(a)
|
|
2739
|
+
* @example
|
|
2740
|
+
* P.merge({ y: 10, z: 2 })({ x: 1, y: 2 }) // => { x: 1, y: 10, z: 2 }
|
|
2741
|
+
* @dataLast
|
|
2742
|
+
* @category Object
|
|
2743
|
+
*/
|
|
2744
|
+
declare function merge<A, B>(b: B): (a: A) => A & B;
|
|
2745
|
+
|
|
2746
|
+
/**
|
|
2747
|
+
* Returns a partial copy of an object omitting the keys specified.
|
|
2748
|
+
* @param data the object
|
|
2749
|
+
* @param propNames the property names
|
|
2750
|
+
* @signature
|
|
2751
|
+
* P.omit(obj, names);
|
|
2752
|
+
* @example
|
|
2753
|
+
* P.omit({ a: 1, b: 2, c: 3, d: 4 }, ['a', 'd']) // => { b: 2, c: 3 }
|
|
2754
|
+
* @dataFirst
|
|
2755
|
+
* @category Object
|
|
2756
|
+
*/
|
|
2757
|
+
declare function omit<T extends object, K extends keyof T>(data: T, propNames: ReadonlyArray<K>): Omit<T, K>;
|
|
2758
|
+
/**
|
|
2759
|
+
* Returns a partial copy of an object omitting the keys specified.
|
|
2760
|
+
* @param propNames the property names
|
|
2761
|
+
* @signature
|
|
2762
|
+
* P.omit(propNames)(obj);
|
|
2763
|
+
* @example
|
|
2764
|
+
* P.pipe({ a: 1, b: 2, c: 3, d: 4 }, P.omit(['a', 'd'])) // => { b: 2, c: 3 }
|
|
2765
|
+
* @dataLast
|
|
2766
|
+
* @category Object
|
|
2767
|
+
*/
|
|
2768
|
+
declare function omit<K extends PropertyKey>(propNames: ReadonlyArray<K>): <T extends object>(data: T) => Omit<T, K>;
|
|
2769
|
+
|
|
2770
|
+
/**
|
|
2771
|
+
* Returns a partial copy of an object omitting the keys matching predicate.
|
|
2772
|
+
* @param object the target object
|
|
2773
|
+
* @param fn the predicate
|
|
2774
|
+
* @signature P.omitBy(object, fn)
|
|
2775
|
+
* @example
|
|
2776
|
+
* P.omitBy({a: 1, b: 2, A: 3, B: 4}, (val, key) => key.toUpperCase() === key) // => {a: 1, b: 2}
|
|
2777
|
+
* @dataFirst
|
|
2778
|
+
* @category Object
|
|
2779
|
+
*/
|
|
2780
|
+
declare function omitBy<T>(object: T, fn: <K extends keyof T>(value: T[K], key: K) => boolean): T extends Record<keyof T, T[keyof T]> ? T : Partial<T>;
|
|
2781
|
+
/**
|
|
2782
|
+
* Returns a partial copy of an object omitting the keys matching predicate.
|
|
2783
|
+
* @param fn the predicate
|
|
2784
|
+
* @signature P.omitBy(fn)(object)
|
|
2785
|
+
* @example
|
|
2786
|
+
* P.omitBy((val, key) => key.toUpperCase() === key)({a: 1, b: 2, A: 3, B: 4}) // => {a: 1, b: 2}
|
|
2787
|
+
* @dataLast
|
|
2788
|
+
* @category Object
|
|
2789
|
+
*/
|
|
2790
|
+
declare function omitBy<T>(fn: <K extends keyof T>(value: T[K], key: K) => boolean): (object: T) => T extends Record<keyof T, T[keyof T]> ? T : Partial<T>;
|
|
2791
|
+
|
|
2792
|
+
/**
|
|
2793
|
+
* Given a union of indexable types `T`, we derive an indexable type
|
|
2794
|
+
* containing all of the keys of each variant of `T`. If a key is
|
|
2795
|
+
* present in multiple variants of `T`, then the corresponding type in
|
|
2796
|
+
* `Pathable<T>` will be the intersection of all types for that key.
|
|
2797
|
+
* @example
|
|
2798
|
+
* type T1 = Pathable<{a: number} | {a: string; b: boolean}>
|
|
2799
|
+
* // {a: number | string; b: boolean}
|
|
2800
|
+
*
|
|
2801
|
+
* type T2 = Pathable<{a?: {b: string}}
|
|
2802
|
+
* // {a: {b: string} | undefined}
|
|
2803
|
+
*
|
|
2804
|
+
* type T3 = Pathable<{a: string} | number>
|
|
2805
|
+
* // {a: string}
|
|
2806
|
+
*
|
|
2807
|
+
* type T4 = Pathable<{a: number} | {a: string} | {b: boolean}>
|
|
2808
|
+
* // {a: number | string; b: boolean}
|
|
2809
|
+
*
|
|
2810
|
+
* This type lets us answer the questions:
|
|
2811
|
+
* - Given some object of type `T`, what keys might this object have?
|
|
2812
|
+
* - If this object did happen to have a particular key, what values
|
|
2813
|
+
* might that key have?
|
|
2814
|
+
*/
|
|
2815
|
+
type Pathable<T> = {
|
|
2816
|
+
[K in AllKeys<T>]: TypesForKey<T, K>;
|
|
2817
|
+
};
|
|
2818
|
+
type AllKeys<T> = T extends infer I ? keyof I : never;
|
|
2819
|
+
type TypesForKey<T, K extends PropertyKey> = T extends infer I ? K extends keyof I ? I[K] : never : never;
|
|
2820
|
+
type StrictlyRequired<T> = {
|
|
2821
|
+
[K in keyof T]-?: NonNullable<T[K]>;
|
|
2822
|
+
};
|
|
2823
|
+
/**
|
|
2824
|
+
* Given some `A` which is a key of at least one variant of `T`, derive
|
|
2825
|
+
* `T[A]` for the cases where `A` is present in `T`, and `T[A]` is not
|
|
2826
|
+
* null or undefined.
|
|
2827
|
+
*/
|
|
2828
|
+
type PathValue1<T, A extends keyof Pathable<T>> = StrictlyRequired<Pathable<T>>[A];
|
|
2829
|
+
/** All possible options after successfully reaching `T[A]` */
|
|
2830
|
+
type Pathable1<T, A extends keyof Pathable<T>> = Pathable<PathValue1<T, A>>;
|
|
2831
|
+
/** As `PathValue1`, but for `T[A][B]` */
|
|
2832
|
+
type PathValue2<T, A extends keyof Pathable<T>, B extends keyof Pathable1<T, A>> = StrictlyRequired<Pathable1<T, A>>[B];
|
|
2833
|
+
/** As `Pathable1`, but for `T[A][B]` */
|
|
2834
|
+
type Pathable2<T, A extends keyof Pathable<T>, B extends keyof Pathable1<T, A>> = Pathable<PathValue2<T, A, B>>;
|
|
2835
|
+
/** As `PathValue1`, but for `T[A][B][C]` */
|
|
2836
|
+
type PathValue3<T, A extends keyof Pathable<T>, B extends keyof Pathable1<T, A>, C extends keyof Pathable2<T, A, B>> = StrictlyRequired<Pathable2<T, A, B>>[C];
|
|
2837
|
+
/**
|
|
2838
|
+
* Gets the value at `path` of `object`. If the resolved value is `undefined`, the `defaultValue` is returned in its place.
|
|
2839
|
+
* @param object the target object
|
|
2840
|
+
* @param path the path of the property to get
|
|
2841
|
+
* @param defaultValue the default value
|
|
2842
|
+
* @signature P.pathOr(object, array, defaultValue)
|
|
2843
|
+
* @example
|
|
2844
|
+
* P.pathOr({x: 10}, ['y'], 2) // 2
|
|
2845
|
+
* P.pathOr({y: 10}, ['y'], 2) // 10
|
|
2846
|
+
* @dataFirst
|
|
2847
|
+
* @category Object
|
|
2848
|
+
*/
|
|
2849
|
+
declare function pathOr<T, A extends keyof Pathable<T>>(object: T, path: readonly [A], defaultValue: PathValue1<T, A>): PathValue1<T, A>;
|
|
2850
|
+
declare function pathOr<T, A extends keyof Pathable<T>, B extends keyof Pathable1<T, A>>(object: T, path: readonly [A, B], defaultValue: PathValue2<T, A, B>): PathValue2<T, A, B>;
|
|
2851
|
+
declare function pathOr<T, A extends keyof Pathable<T>, B extends keyof Pathable1<T, A>, C extends keyof Pathable2<T, A, B>>(object: T, path: readonly [A, B, C], defaultValue: PathValue3<T, A, B, C>): PathValue3<T, A, B, C>;
|
|
2852
|
+
/**
|
|
2853
|
+
* Gets the value at `path` of `object`. If the resolved value is `undefined`, the `defaultValue` is returned in its place.
|
|
2854
|
+
* @param path the path of the property to get
|
|
2855
|
+
* @param defaultValue the default value
|
|
2856
|
+
* @signature P.pathOr(array, defaultValue)(object)
|
|
2857
|
+
* @example
|
|
2858
|
+
* P.pipe({x: 10}, P.pathOr(['y'], 2)) // 2
|
|
2859
|
+
* P.pipe({y: 10}, P.pathOr(['y'], 2)) // 10
|
|
2860
|
+
* @dataLast
|
|
2861
|
+
* @category Object
|
|
2862
|
+
*/
|
|
2863
|
+
declare function pathOr<T, A extends keyof Pathable<T>>(path: readonly [A], defaultValue: PathValue1<T, A>): (object: T) => PathValue1<T, A>;
|
|
2864
|
+
declare function pathOr<T, A extends keyof Pathable<T>, B extends keyof Pathable1<T, A>>(path: readonly [A, B], defaultValue: PathValue2<T, A, B>): (object: T) => PathValue2<T, A, B>;
|
|
2865
|
+
declare function pathOr<T, A extends keyof Pathable<T>, B extends keyof Pathable1<T, A>, C extends keyof Pathable2<T, A, B>>(path: readonly [A, B, C], defaultValue: PathValue3<T, A, B, C>): (object: T) => PathValue3<T, A, B, C>;
|
|
2866
|
+
|
|
2867
|
+
/**
|
|
2868
|
+
* Creates an object composed of the picked `object` properties.
|
|
2869
|
+
* @param object the target object
|
|
2870
|
+
* @param names the properties names
|
|
2871
|
+
* @signature P.pick(object, [prop1, prop2])
|
|
2872
|
+
* @example
|
|
2873
|
+
* P.pick({ a: 1, b: 2, c: 3, d: 4 }, ['a', 'd']) // => { a: 1, d: 4 }
|
|
2874
|
+
* @dataFirst
|
|
2875
|
+
* @category Object
|
|
2876
|
+
*/
|
|
2877
|
+
declare function pick<T extends object, K extends keyof T>(object: T, names: ReadonlyArray<K>): Pick<T, K>;
|
|
2878
|
+
/**
|
|
2879
|
+
* Creates an object composed of the picked `object` properties.
|
|
2880
|
+
* @param names the properties names
|
|
2881
|
+
* @signature P.pick([prop1, prop2])(object)
|
|
2882
|
+
* @example
|
|
2883
|
+
* P.pipe({ a: 1, b: 2, c: 3, d: 4 }, P.pick(['a', 'd'])) // => { a: 1, d: 4 }
|
|
2884
|
+
* @dataLast
|
|
2885
|
+
* @category Object
|
|
2886
|
+
*/
|
|
2887
|
+
declare function pick<K extends PropertyKey>(names: ReadonlyArray<K>): <T extends Record<PropertyKey, any>>(object: T) => Pick<T, K>;
|
|
2888
|
+
|
|
2889
|
+
/**
|
|
2890
|
+
* Creates an object composed of the picked `object` properties.
|
|
2891
|
+
* @param object the target object
|
|
2892
|
+
* @param fn the predicate
|
|
2893
|
+
* @signature P.pickBy(object, fn)
|
|
2894
|
+
* @example
|
|
2895
|
+
* P.pickBy({a: 1, b: 2, A: 3, B: 4}, (val, key) => key.toUpperCase() === key) // => {A: 3, B: 4}
|
|
2896
|
+
* @dataFirst
|
|
2897
|
+
* @category Object
|
|
2898
|
+
*/
|
|
2899
|
+
declare function pickBy<T>(object: T, fn: <K extends keyof T>(value: T[K], key: K) => boolean): T extends Record<keyof T, T[keyof T]> ? T : Partial<T>;
|
|
2900
|
+
/**
|
|
2901
|
+
* Creates an object composed of the picked `object` properties.
|
|
2902
|
+
* @param fn the predicate
|
|
2903
|
+
* @signature P.pickBy(fn)(object)
|
|
2904
|
+
* @example
|
|
2905
|
+
* P.pickBy((val, key) => key.toUpperCase() === key)({a: 1, b: 2, A: 3, B: 4}) // => {A: 3, B: 4}
|
|
2906
|
+
* @dataLast
|
|
2907
|
+
* @category Object
|
|
2908
|
+
*/
|
|
2909
|
+
declare function pickBy<T>(fn: <K extends keyof T>(value: T[K], key: K) => boolean): (object: T) => T extends Record<keyof T, T[keyof T]> ? T : Partial<T>;
|
|
2910
|
+
|
|
2911
|
+
/**
|
|
2912
|
+
* Gets the value of the given property.
|
|
2913
|
+
* @param propName the property name
|
|
2914
|
+
* @signature P.prop(prop)(object)
|
|
2915
|
+
* @example
|
|
2916
|
+
* P.pipe({foo: 'bar'}, P.prop('foo')) // => 'bar'
|
|
2917
|
+
* @dataLast
|
|
2918
|
+
* @category Object
|
|
2919
|
+
*/
|
|
2920
|
+
declare function prop<T, K extends keyof T>(propName: K): ({ [propName]: value }: T) => T[K];
|
|
2921
|
+
|
|
2922
|
+
/**
|
|
2923
|
+
* Sets the `value` at `prop` of `object`.
|
|
2924
|
+
* @param obj the target method
|
|
2925
|
+
* @param prop the property name
|
|
2926
|
+
* @param value the value to set
|
|
2927
|
+
* @signature
|
|
2928
|
+
* P.set(obj, prop, value)
|
|
2929
|
+
* @example
|
|
2930
|
+
* P.set({ a: 1 }, 'a', 2) // => { a: 2 }
|
|
2931
|
+
* @dataFirst
|
|
2932
|
+
* @category Object
|
|
2933
|
+
*/
|
|
2934
|
+
declare function set<T, K extends keyof T>(obj: T, prop: K, value: T[K]): T;
|
|
2935
|
+
/**
|
|
2936
|
+
* Sets the `value` at `prop` of `object`.
|
|
2937
|
+
* @param prop the property name
|
|
2938
|
+
* @param value the value to set
|
|
2939
|
+
* @signature
|
|
2940
|
+
* P.set(prop, value)(obj)
|
|
2941
|
+
* @example
|
|
2942
|
+
* P.pipe({ a: 1 }, P.set('a', 2)) // => { a: 2 }
|
|
2943
|
+
* @dataLast
|
|
2944
|
+
* @category Object
|
|
2945
|
+
*/
|
|
2946
|
+
declare function set<T, K extends keyof T>(prop: K, value: T[K]): (obj: T) => T;
|
|
2947
|
+
|
|
2948
|
+
type Path<Obj, Prefix extends Array<PropertyKey> = []> = Obj extends Primitive ? Prefix : Obj extends Array<infer Item> ? Prefix | Path<Item, [...Prefix, number]> : Prefix | PathsOfObject<Obj, Prefix>;
|
|
2949
|
+
type PathsOfObject<Obj, Prefix extends Array<PropertyKey>> = {
|
|
2950
|
+
[K in keyof Obj]: Path<Obj[K], [...Prefix, K]>;
|
|
2951
|
+
}[keyof Obj];
|
|
2952
|
+
type ValueAtPath<Obj, ObjPath extends Array<PropertyKey> = []> = ObjPath extends [] ? Obj : ObjPath extends [infer Head, ...infer Tail] ? Tail extends Array<PropertyKey> ? Head extends keyof Obj ? ValueAtPath<Obj[Head], Tail> : never : never : never;
|
|
2953
|
+
type SupportsValueAtPath<Obj, Path extends Array<PropertyKey>, Value> = Value extends ValueAtPath<Obj, Path> ? Obj : never;
|
|
2954
|
+
type Primitive = string | number | boolean | null | undefined | symbol;
|
|
2955
|
+
|
|
2956
|
+
/**
|
|
2957
|
+
* Copied from ts-toolbelt
|
|
2958
|
+
* https://github.com/millsp/ts-toolbelt/blob/master/sources/Function/Narrow.ts
|
|
2959
|
+
*/
|
|
2960
|
+
/**
|
|
2961
|
+
* Similar to [[Cast]] but with a custom fallback `Catch`. If it fails,
|
|
2962
|
+
* it will enforce `Catch` instead of `A2`.
|
|
2963
|
+
* @param A1 to check against
|
|
2964
|
+
* @param A2 to try/test with
|
|
2965
|
+
* @param Catch to fallback to if the test failed
|
|
2966
|
+
* @returns `A1 | Catch`
|
|
2967
|
+
* @example
|
|
2968
|
+
* ```ts
|
|
2969
|
+
* import {A} from 'ts-toolbelt'
|
|
2970
|
+
*
|
|
2971
|
+
* type test0 = A.Try<'42', string> // '42'
|
|
2972
|
+
* type test1 = A.Try<'42', number> // never
|
|
2973
|
+
* type test1 = A.Try<'42', number, 'tried'> // 'tried'
|
|
2974
|
+
* ```
|
|
2975
|
+
*/
|
|
2976
|
+
type Try<A1, A2, Catch = never> = A1 extends A2 ? A1 : Catch;
|
|
2977
|
+
/**
|
|
2978
|
+
* Describes types that can be narrowed
|
|
2979
|
+
*/
|
|
2980
|
+
type Narrowable = string | number | bigint | boolean;
|
|
2981
|
+
/**
|
|
2982
|
+
* @hidden
|
|
2983
|
+
*/
|
|
2984
|
+
type NarrowRaw<A> = (A extends [] ? [] : never) | (A extends Narrowable ? A : never) | {
|
|
2985
|
+
[K in keyof A]: A[K] extends (...args: Array<any>) => any ? A[K] : NarrowRaw<A[K]>;
|
|
2986
|
+
};
|
|
2987
|
+
/**
|
|
2988
|
+
* Prevent type widening on generic function parameters
|
|
2989
|
+
* @param A to narrow
|
|
2990
|
+
* @returns `A`
|
|
2991
|
+
* @example
|
|
2992
|
+
* ```ts
|
|
2993
|
+
* import {F} from 'ts-toolbelt'
|
|
2994
|
+
*
|
|
2995
|
+
* declare function foo<A extends any[]>(x: F.Narrow<A>): A;
|
|
2996
|
+
* declare function bar<A extends object>(x: F.Narrow<A>): A;
|
|
2997
|
+
*
|
|
2998
|
+
* const test0 = foo(['e', 2, true, {f: ['g', ['h']]}])
|
|
2999
|
+
* // `A` inferred : ['e', 2, true, {f: ['g']}]
|
|
3000
|
+
*
|
|
3001
|
+
* const test1 = bar({a: 1, b: 'c', d: ['e', 2, true, {f: ['g']}]})
|
|
3002
|
+
* // `A` inferred : {a: 1, b: 'c', d: ['e', 2, true, {f: ['g']}]}
|
|
3003
|
+
* ```
|
|
3004
|
+
*/
|
|
3005
|
+
type Narrow<A> = Try<A, [], NarrowRaw<A>>;
|
|
3006
|
+
|
|
3007
|
+
/**
|
|
3008
|
+
* Sets the value at `path` of `object`. `path` can be an array or a path string.
|
|
3009
|
+
* @param object the target method
|
|
3010
|
+
* @param path the property name
|
|
3011
|
+
* @param value the value to set
|
|
3012
|
+
* @signature
|
|
3013
|
+
* P.setPath(obj, path, value)
|
|
3014
|
+
* @example
|
|
3015
|
+
* P.setPath({ a: { b: 1 } }, ['a', 'b'], 2) // => { a: { b: 2 } }
|
|
3016
|
+
* @dataFirst
|
|
3017
|
+
* @category Object
|
|
3018
|
+
*/
|
|
3019
|
+
declare function setPath<T, TPath extends Array<PropertyKey> & Path<T>>(object: T, path: Narrow<TPath>, value: ValueAtPath<T, TPath>): T;
|
|
3020
|
+
/**
|
|
3021
|
+
* Sets the value at `path` of `object`. `path` can be an array or a path string.
|
|
3022
|
+
* @param path the property name
|
|
3023
|
+
* @param value the value to set
|
|
3024
|
+
* @signature
|
|
3025
|
+
* P.setPath(path, value)
|
|
3026
|
+
* @example
|
|
3027
|
+
* P.pipe({ a: { b: 1 } }, P.setPath(['a', 'b'], 2)) // { a: { b: 2 } }
|
|
3028
|
+
* @dataFirst
|
|
3029
|
+
* @category Object
|
|
3030
|
+
*/
|
|
3031
|
+
declare function setPath<TPath extends Array<PropertyKey>, Value>(path: Narrow<TPath>, value: Value): <Obj>(object: SupportsValueAtPath<Obj, TPath, Value>) => Obj;
|
|
3032
|
+
declare function _setPath(object: any, path: Array<any>, defaultValue: any): any;
|
|
3033
|
+
|
|
3034
|
+
type SwappedProps<T, K1 extends keyof T, K2 extends keyof T> = {
|
|
3035
|
+
[K in keyof T]: T[K1 extends K ? K2 : K2 extends K ? K1 : K];
|
|
3036
|
+
};
|
|
3037
|
+
/**
|
|
3038
|
+
* Swaps the positions of two properties in an object based on the provided keys.
|
|
3039
|
+
*
|
|
3040
|
+
* @param data the object to be manipulated
|
|
3041
|
+
* @param key1 the first property key
|
|
3042
|
+
* @param key2 the second property key
|
|
3043
|
+
*
|
|
3044
|
+
* @signature
|
|
3045
|
+
* swap(data, key1, key2)
|
|
3046
|
+
*
|
|
3047
|
+
* @returns Returns the manipulated object.
|
|
3048
|
+
*
|
|
3049
|
+
* @example
|
|
3050
|
+
* swap({a: 1, b: 2, c: 3}, 'a', 'b') // => {a: 2, b: 1, c: 3}
|
|
3051
|
+
*
|
|
3052
|
+
* @category Object
|
|
3053
|
+
*
|
|
3054
|
+
* @dataFirst
|
|
3055
|
+
*/
|
|
3056
|
+
declare function swapProps<T extends object, K1 extends keyof T, K2 extends keyof T>(data: T, key1: K1, key2: K2): SwappedProps<T, K1, K2>;
|
|
3057
|
+
/**
|
|
3058
|
+
* Swaps the positions of two properties in an object based on the provided keys.
|
|
3059
|
+
*
|
|
3060
|
+
* @param key1 the first property key
|
|
3061
|
+
* @param key2 the second property key
|
|
3062
|
+
*
|
|
3063
|
+
* @signature
|
|
3064
|
+
* swap(key1, key2)(data)
|
|
3065
|
+
*
|
|
3066
|
+
* @example
|
|
3067
|
+
* swap('a', 'b')({a: 1, b: 2, c: 3}) // => {a: 2, b: 1, c: 3}
|
|
3068
|
+
*
|
|
3069
|
+
* @returns Returns the manipulated object.
|
|
3070
|
+
*
|
|
3071
|
+
* @category Object
|
|
3072
|
+
*
|
|
3073
|
+
* @dataLast
|
|
3074
|
+
*/
|
|
3075
|
+
declare function swapProps<T extends object, K1 extends keyof T, K2 extends keyof T>(key1: K1, key2: K2): (data: T) => SwappedProps<T, K1, K2>;
|
|
3076
|
+
|
|
3077
|
+
type ObjectKeys<T extends object> = `${Exclude<keyof T, symbol>}`;
|
|
3078
|
+
type ObjectValues<T extends Record<PropertyKey, unknown>> = Required<T>[ObjectKeys<T>];
|
|
3079
|
+
type ObjectEntry<T extends Record<PropertyKey, unknown>> = [
|
|
3080
|
+
ObjectKeys<T>,
|
|
3081
|
+
ObjectValues<T>
|
|
3082
|
+
];
|
|
3083
|
+
type ObjectEntries<T extends Record<PropertyKey, unknown>> = Array<ObjectEntry<T>>;
|
|
3084
|
+
/**
|
|
3085
|
+
* Returns an array of key/values of the enumerable properties of an object.
|
|
3086
|
+
* @param object
|
|
3087
|
+
* @signature
|
|
3088
|
+
* P.toPairs(object)
|
|
3089
|
+
* P.toPairs.strict(object)
|
|
3090
|
+
* @example
|
|
3091
|
+
* P.toPairs({ a: 1, b: 2, c: 3 }) // => [['a', 1], ['b', 2], ['c', 3]]
|
|
3092
|
+
* P.toPairs.strict({ a: 1 } as const) // => [['a', 1]] typed Array<['a', 1]>
|
|
3093
|
+
* @strict
|
|
3094
|
+
* @category Object
|
|
3095
|
+
*/
|
|
3096
|
+
declare function toPairs<T>(object: Record<string, T>): Array<[string, T]>;
|
|
3097
|
+
declare namespace toPairs {
|
|
3098
|
+
function strict<T extends Record<PropertyKey, unknown>>(object: T): ObjectEntries<T>;
|
|
3099
|
+
}
|
|
3100
|
+
|
|
3101
|
+
/**
|
|
3102
|
+
* Returns a new array containing the values of the array or object.
|
|
3103
|
+
* @param source Either an array or an object
|
|
3104
|
+
* @signature
|
|
3105
|
+
* P.values(source)
|
|
3106
|
+
* @example
|
|
3107
|
+
* P.values(['x', 'y', 'z']) // => ['x', 'y', 'z']
|
|
3108
|
+
* P.values({ a: 'x', b: 'y', c: 'z' }) // => ['x', 'y', 'z']
|
|
3109
|
+
* P.pipe(
|
|
3110
|
+
* { a: 'x', b: 'y', c: 'z' },
|
|
3111
|
+
* P.values,
|
|
3112
|
+
* P.first
|
|
3113
|
+
* ) // => 'x'
|
|
3114
|
+
* @pipeable
|
|
3115
|
+
* @category Object
|
|
3116
|
+
*/
|
|
3117
|
+
type Values<T extends object> = T extends ReadonlyArray<unknown> | [] ? Array<T[number]> : Array<T[keyof T]>;
|
|
3118
|
+
declare function values<T extends object>(source: T): Values<T>;
|
|
3119
|
+
|
|
3120
|
+
type Splitter = '-' | '_' | '/' | '.';
|
|
3121
|
+
type LastOfArray<T extends any[]> = T extends [...any, infer R] ? R : never;
|
|
3122
|
+
type RemoveLastOfArray<T extends any[]> = T extends [...infer F, any] ? F : never;
|
|
3123
|
+
type IsUpper<S extends string> = S extends Uppercase<S> ? true : false;
|
|
3124
|
+
type IsLower<S extends string> = S extends Lowercase<S> ? true : false;
|
|
3125
|
+
type SameLetterCase<X extends string, Y extends string> = IsUpper<X> extends IsUpper<Y> ? true : IsLower<X> extends IsLower<Y> ? true : false;
|
|
3126
|
+
type FirstOfString<S extends string> = S extends `${infer F}${string}` ? F : never;
|
|
3127
|
+
type RemoveFirstOfString<S extends string> = S extends `${string}${infer R}` ? R : never;
|
|
3128
|
+
type SplitByCase<T, Separator extends string = Splitter, Accumulator extends unknown[] = []> = string extends Separator ? string[] : T extends `${infer F}${infer R}` ? [LastOfArray<Accumulator>] extends [never] ? SplitByCase<R, Separator, [F]> : LastOfArray<Accumulator> extends string ? R extends '' ? SplitByCase<R, Separator, [
|
|
3129
|
+
...RemoveLastOfArray<Accumulator>,
|
|
3130
|
+
`${LastOfArray<Accumulator>}${F}`
|
|
3131
|
+
]> : SameLetterCase<F, FirstOfString<R>> extends true ? F extends Separator ? FirstOfString<R> extends Separator ? SplitByCase<R, Separator, [...Accumulator, '']> : IsUpper<FirstOfString<R>> extends true ? SplitByCase<RemoveFirstOfString<R>, Separator, [
|
|
3132
|
+
...Accumulator,
|
|
3133
|
+
FirstOfString<R>
|
|
3134
|
+
]> : SplitByCase<R, Separator, [...Accumulator, '']> : SplitByCase<R, Separator, [
|
|
3135
|
+
...RemoveLastOfArray<Accumulator>,
|
|
3136
|
+
`${LastOfArray<Accumulator>}${F}`
|
|
3137
|
+
]> : IsLower<F> extends true ? SplitByCase<RemoveFirstOfString<R>, Separator, [
|
|
3138
|
+
...RemoveLastOfArray<Accumulator>,
|
|
3139
|
+
`${LastOfArray<Accumulator>}${F}`,
|
|
3140
|
+
FirstOfString<R>
|
|
3141
|
+
]> : SplitByCase<R, Separator, [...Accumulator, F]> : never : Accumulator extends [] ? T extends '' ? [] : string[] : Accumulator;
|
|
3142
|
+
type CapitalizedWords<T extends readonly string[], Accumulator extends string = ''> = T extends readonly [infer F extends string, ...infer R extends string[]] ? CapitalizedWords<R, `${Accumulator}${Capitalize<F>}`> : Accumulator;
|
|
3143
|
+
type JoinLowercaseWords<T extends readonly string[], Joiner extends string, Accumulator extends string = ''> = T extends readonly [infer F extends string, ...infer R extends string[]] ? Accumulator extends '' ? JoinLowercaseWords<R, Joiner, `${Accumulator}${Lowercase<F>}`> : JoinLowercaseWords<R, Joiner, `${Accumulator}${Joiner}${Lowercase<F>}`> : Accumulator;
|
|
3144
|
+
type PascalCase<T> = string extends T ? string : string[] extends T ? string : T extends string ? SplitByCase<T> extends readonly string[] ? CapitalizedWords<SplitByCase<T>> : never : T extends readonly string[] ? CapitalizedWords<T> : never;
|
|
3145
|
+
type CamelCase<T> = string extends T ? string : string[] extends T ? string : Uncapitalize<PascalCase<T>>;
|
|
3146
|
+
type JoinByCase<T, Joiner extends string> = string extends T ? string : string[] extends T ? string : T extends string ? SplitByCase<T> extends readonly string[] ? JoinLowercaseWords<SplitByCase<T>, Joiner> : never : T extends readonly string[] ? JoinLowercaseWords<T, Joiner> : never;
|
|
3147
|
+
|
|
3148
|
+
declare function isUppercase(char?: string): boolean | undefined;
|
|
3149
|
+
declare function splitByCase<T extends string>(string_: T): SplitByCase<T>;
|
|
3150
|
+
declare function splitByCase<T extends string, Separator extends readonly string[]>(string_: T, separators: Separator): SplitByCase<T, Separator[number]>;
|
|
3151
|
+
declare function toUpperFirst<S extends string>(string_: S): Capitalize<S>;
|
|
3152
|
+
declare function toLowerFirst<S extends string>(string_: S): Uncapitalize<S>;
|
|
3153
|
+
declare function toPascalCase(): '';
|
|
3154
|
+
declare function toPascalCase<T extends string | readonly string[]>(string_?: T): PascalCase<T>;
|
|
3155
|
+
declare function toCamelCase(): '';
|
|
3156
|
+
declare function toCamelCase<T extends string | readonly string[]>(string_?: T): CamelCase<T>;
|
|
3157
|
+
declare function toKebabCase(): '';
|
|
3158
|
+
declare function toKebabCase<T extends string | readonly string[]>(string_?: T): JoinByCase<T, '-'>;
|
|
3159
|
+
declare function toKebabCase<T extends string | readonly string[], Joiner extends string>(string_: T, joiner: Joiner): JoinByCase<T, Joiner>;
|
|
3160
|
+
declare function toSnakeCase(): '';
|
|
3161
|
+
declare function toSnakeCase<T extends string | readonly string[]>(string_?: T): JoinByCase<T, '_'>;
|
|
3162
|
+
|
|
3163
|
+
/**
|
|
3164
|
+
* Returns human readable file size.
|
|
3165
|
+
* @param bytes the file size in bytes
|
|
3166
|
+
* @param base the base (1000 or 1024)
|
|
3167
|
+
* @signature
|
|
3168
|
+
* P.humanReadableFileSize(bytes, base)
|
|
3169
|
+
* @example
|
|
3170
|
+
* P.humanReadableFileSize(1000) // => '1.0 kB'
|
|
3171
|
+
* P.humanReadableFileSize(2097152, 1024) // => '2.0 Mib'
|
|
3172
|
+
* @category String
|
|
3173
|
+
*/
|
|
3174
|
+
declare function humanReadableFileSize(bytes: number, base?: 1000 | 1024): string;
|
|
3175
|
+
|
|
3176
|
+
/**
|
|
3177
|
+
* Random a non-cryptographic random string from characters a-zA-Z0-9.
|
|
3178
|
+
* @param length the length of the random string
|
|
3179
|
+
* @signature randomString(length)
|
|
3180
|
+
* @example
|
|
3181
|
+
* randomString(5) // => aB92J
|
|
3182
|
+
* @category String
|
|
3183
|
+
*/
|
|
3184
|
+
declare function randomString(length: number): string;
|
|
3185
|
+
|
|
3186
|
+
/**
|
|
3187
|
+
* Turn any string into a URL/DOM safe string.
|
|
3188
|
+
* @param str the string to slugify
|
|
3189
|
+
* @signature
|
|
3190
|
+
* P.slugify(str)
|
|
3191
|
+
* @example
|
|
3192
|
+
* P.slugify('FooBar') // => 'foobar'
|
|
3193
|
+
* P.slugify('This!-is*&%#@^up!') // => 'this-is-up'
|
|
3194
|
+
* @category String
|
|
3195
|
+
*/
|
|
3196
|
+
declare function slugify(str: string): string;
|
|
3197
|
+
|
|
3198
|
+
/**
|
|
3199
|
+
* Converts a path string to an array of keys.
|
|
3200
|
+
* @param path a string path
|
|
3201
|
+
* @signature P.stringToPathArray(path)
|
|
3202
|
+
* @example P.stringToPathArray('a.b[0].c') // => ['a', 'b', 0, 'c']
|
|
3203
|
+
* @dataFirst
|
|
3204
|
+
* @category String
|
|
3205
|
+
*/
|
|
3206
|
+
declare function stringToPath<Path extends string>(path: Path): StringToPath<Path>;
|
|
3207
|
+
type StringToPath<T extends string> = T extends '' ? [] : T extends `[${infer Head}].${infer Tail}` ? [Head, ...StringToPath<Tail>] : T extends `.${infer Head}${infer Tail}` ? [Head, ...StringToPath<Tail>] : T extends `${infer Head}${infer Tail}` ? [Head, ...StringToPath<Tail>] : [T];
|
|
3208
|
+
|
|
3209
|
+
/**
|
|
3210
|
+
* Gives a single-word string description of the (native) type of a value, returning such answers as 'Object', 'Number', 'Array', or 'Null'. Does not attempt to distinguish user Object types any further, reporting them all as 'Object'.
|
|
3211
|
+
* @param val
|
|
3212
|
+
* @signature
|
|
3213
|
+
* P.type(obj)
|
|
3214
|
+
* @example
|
|
3215
|
+
* P.type({}); //=> "Object"
|
|
3216
|
+
* P.type(1); //=> "Number"
|
|
3217
|
+
* P.type(false); //=> "Boolean"
|
|
3218
|
+
* P.type('s'); //=> "String"
|
|
3219
|
+
* P.type(null); //=> "Null"
|
|
3220
|
+
* P.type([]); //=> "Array"
|
|
3221
|
+
* P.type(/[A-z]/); //=> "RegExp"
|
|
3222
|
+
* P.type(() => {}); //=> "Function"
|
|
3223
|
+
* P.type(undefined); //=> "Undefined"
|
|
3224
|
+
* @category Type
|
|
3225
|
+
*/
|
|
3226
|
+
declare function type(val: any): string;
|
|
3227
|
+
|
|
3228
|
+
declare const isBrowser: boolean;
|
|
3229
|
+
|
|
3230
|
+
export { Joined, KEY_CODES, StringToPath, _setPath, addProp, allPass, anyPass, chunk, clamp, clone, compact, concat, countBy, createPipe, difference, differenceWith, drop, dropLast, equals, filter, find, findIndex, findLast, findLastIndex, first, flatMap, flatMapToObj, flatten, flattenDeep, forEach, forEachObj, fromPairs, groupBy, humanReadableFileSize, identity, indexBy, intersection, intersectionWith, invert, isArray, isBoolean, isBrowser, isDate, isDefined, isEmpty, isError, isFunction, isNil, isNonNull, isNot, isNumber, isObject, isPromise, isString, isTruthy, isUppercase, join, keys, last, length, map, mapKeys, mapToObj, mapValues, maxBy, meanBy, merge, mergeAll, minBy, noop, omit, omitBy, once, partition, pathOr, pick, pickBy, pipe, prop, purry, randomString, range, reduce, reject, reverse, sample, set, setPath, shuffle, sleep, slugify, sort, sortBy, splitAt, splitByCase, splitWhen, stringToPath, sumBy, swapIndices, swapProps, take, takeWhile, toCamelCase, toKebabCase, toLowerFirst, toPairs, toPascalCase, toSnakeCase, toUpperFirst, type, uniq, uniqBy, uniqWith, values, zip, zipObj, zipWith };
|