@vinicunca/perkakas 0.2.1 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -0
- package/dist/commonjs/aria/index.js +17 -0
- package/dist/commonjs/aria/key-codes.js +25 -0
- package/dist/commonjs/array/all-pass.js +11 -0
- package/dist/commonjs/array/any-pass.js +11 -0
- package/dist/commonjs/array/chunk.js +17 -0
- package/dist/commonjs/array/compact.js +8 -0
- package/dist/commonjs/array/concat.js +11 -0
- package/dist/commonjs/array/count-by.js +22 -0
- package/dist/commonjs/array/difference-with.js +31 -0
- package/dist/commonjs/array/difference.js +32 -0
- package/dist/commonjs/array/drop-first-by.js +26 -0
- package/dist/commonjs/array/drop-last-while.js +16 -0
- package/dist/commonjs/array/drop-last.js +15 -0
- package/dist/commonjs/array/drop-while.js +16 -0
- package/dist/commonjs/array/drop.js +32 -0
- package/dist/commonjs/array/filter.js +41 -0
- package/dist/commonjs/array/find-index.js +46 -0
- package/dist/commonjs/array/find-last-index.js +24 -0
- package/dist/commonjs/array/find-last.js +24 -0
- package/dist/commonjs/array/find.js +38 -0
- package/dist/commonjs/array/first-by.js +22 -0
- package/dist/commonjs/array/first.js +26 -0
- package/dist/commonjs/array/flat-map-to-obj.js +25 -0
- package/dist/commonjs/array/flat-map.js +33 -0
- package/dist/commonjs/array/flatten-deep.js +48 -0
- package/dist/commonjs/array/flatten.js +32 -0
- package/dist/commonjs/array/for-each.js +40 -0
- package/dist/commonjs/array/group-by.js +33 -0
- package/dist/commonjs/array/has-at-least.js +11 -0
- package/dist/commonjs/array/index-by.js +24 -0
- package/dist/commonjs/array/index.js +81 -0
- package/dist/commonjs/array/intersection-with.js +31 -0
- package/dist/commonjs/array/intersection.js +32 -0
- package/dist/commonjs/array/join.js +11 -0
- package/dist/commonjs/array/last.js +11 -0
- package/dist/commonjs/array/length.js +11 -0
- package/dist/commonjs/array/map-to-obj.js +23 -0
- package/dist/commonjs/array/map.js +35 -0
- package/dist/commonjs/array/max-by.js +28 -0
- package/dist/commonjs/array/mean-by.js +26 -0
- package/dist/commonjs/array/merge-all.js +7 -0
- package/dist/commonjs/array/min-by.js +28 -0
- package/dist/commonjs/array/nth-by.js +12 -0
- package/dist/commonjs/array/only.js +14 -0
- package/dist/commonjs/array/partition.js +24 -0
- package/dist/commonjs/array/range.js +15 -0
- package/dist/commonjs/array/rank-by.js +17 -0
- package/dist/commonjs/array/reduce.js +19 -0
- package/dist/commonjs/array/reject.js +41 -0
- package/dist/commonjs/array/reverse.js +11 -0
- package/dist/commonjs/array/sample.js +34 -0
- package/dist/commonjs/array/shuffle.js +18 -0
- package/dist/commonjs/array/sort-by.js +52 -0
- package/dist/commonjs/array/sort.js +16 -0
- package/dist/commonjs/array/splice.js +13 -0
- package/dist/commonjs/array/split-at.js +13 -0
- package/dist/commonjs/array/split-when.js +17 -0
- package/dist/commonjs/array/sum-by.js +24 -0
- package/dist/commonjs/array/swap-indices.js +34 -0
- package/dist/commonjs/array/take-first-by.js +24 -0
- package/dist/commonjs/array/take-while.js +18 -0
- package/dist/commonjs/array/take.js +38 -0
- package/dist/commonjs/array/uniq-by.js +30 -0
- package/dist/commonjs/array/uniq-with.js +33 -0
- package/dist/commonjs/array/uniq.js +32 -0
- package/dist/commonjs/array/zip-obj.js +16 -0
- package/dist/commonjs/array/zip-with.js +23 -0
- package/dist/commonjs/array/zip.js +19 -0
- package/dist/commonjs/function/conditional.js +34 -0
- package/dist/commonjs/function/create-pipe.js +8 -0
- package/dist/commonjs/function/debounce.js +88 -0
- package/dist/commonjs/function/identity.js +7 -0
- package/dist/commonjs/function/index.js +25 -0
- package/dist/commonjs/function/noop.js +7 -0
- package/dist/commonjs/function/once.js +15 -0
- package/dist/commonjs/function/pipe.js +106 -0
- package/dist/commonjs/function/purry.js +20 -0
- package/dist/commonjs/function/sleep.js +9 -0
- package/dist/commonjs/guard/index.js +32 -0
- package/dist/commonjs/guard/is-array.js +7 -0
- package/dist/commonjs/guard/is-boolean.js +7 -0
- package/dist/commonjs/guard/is-date.js +7 -0
- package/dist/commonjs/guard/is-defined.js +13 -0
- package/dist/commonjs/guard/is-empty.js +19 -0
- package/dist/commonjs/guard/is-error.js +7 -0
- package/dist/commonjs/guard/is-function.js +7 -0
- package/dist/commonjs/guard/is-nil.js +7 -0
- package/dist/commonjs/guard/is-non-null.js +7 -0
- package/dist/commonjs/guard/is-not.js +9 -0
- package/dist/commonjs/guard/is-number.js +7 -0
- package/dist/commonjs/guard/is-object.js +11 -0
- package/dist/commonjs/guard/is-promise.js +7 -0
- package/dist/commonjs/guard/is-string.js +7 -0
- package/dist/commonjs/guard/is-symbol.js +7 -0
- package/dist/commonjs/guard/is-truthy.js +7 -0
- package/dist/commonjs/index.js +26 -0
- package/dist/commonjs/number/add.js +11 -0
- package/dist/commonjs/number/ceil.js +9 -0
- package/dist/commonjs/number/clamp.js +17 -0
- package/dist/commonjs/number/divide.js +11 -0
- package/dist/commonjs/number/floor.js +9 -0
- package/dist/commonjs/number/index.js +24 -0
- package/dist/commonjs/number/multiply.js +11 -0
- package/dist/commonjs/number/round.js +9 -0
- package/dist/commonjs/number/subtract.js +11 -0
- package/dist/commonjs/object/add-prop.js +14 -0
- package/dist/commonjs/object/clone.js +49 -0
- package/dist/commonjs/object/equals.js +71 -0
- package/dist/commonjs/object/for-each-obj.js +30 -0
- package/dist/commonjs/object/from-pairs.js +14 -0
- package/dist/commonjs/object/index.js +39 -0
- package/dist/commonjs/object/invert.js +15 -0
- package/dist/commonjs/object/keys.js +10 -0
- package/dist/commonjs/object/map-keys.js +16 -0
- package/dist/commonjs/object/map-values.js +16 -0
- package/dist/commonjs/object/merge-deep.js +31 -0
- package/dist/commonjs/object/merge.js +11 -0
- package/dist/commonjs/object/omit-by.js +20 -0
- package/dist/commonjs/object/omit.js +25 -0
- package/dist/commonjs/object/path-or.js +18 -0
- package/dist/commonjs/object/pick-by.js +20 -0
- package/dist/commonjs/object/pick.js +19 -0
- package/dist/commonjs/object/prop.js +7 -0
- package/dist/commonjs/object/set-path.js +26 -0
- package/dist/commonjs/object/set.js +14 -0
- package/dist/commonjs/object/swap-props.js +16 -0
- package/dist/commonjs/object/to-pairs.js +11 -0
- package/dist/commonjs/object/values.js +7 -0
- package/dist/commonjs/string/cases-types.js +2 -0
- package/dist/commonjs/string/cases.js +107 -0
- package/dist/commonjs/string/human-readable-file-size.js +16 -0
- package/dist/commonjs/string/index.js +21 -0
- package/dist/commonjs/string/random-string.js +10 -0
- package/dist/commonjs/string/slugify.js +13 -0
- package/dist/commonjs/string/string-to-path.js +18 -0
- package/dist/commonjs/type/index.js +17 -0
- package/dist/commonjs/type/type.js +13 -0
- package/dist/commonjs/utils/heap.js +43 -0
- package/dist/commonjs/utils/narrow.js +2 -0
- package/dist/commonjs/utils/paths.js +2 -0
- package/dist/commonjs/utils/purry-on.js +10 -0
- package/dist/commonjs/utils/purry-order-rules.js +66 -0
- package/dist/commonjs/utils/quick-select.js +31 -0
- package/dist/commonjs/utils/reduce-lazy.js +18 -0
- package/dist/commonjs/utils/swap-in-place.js +7 -0
- package/dist/commonjs/utils/to-lazy-indexed.js +7 -0
- package/dist/commonjs/utils/to-single.js +8 -0
- package/dist/commonjs/utils/types.js +2 -0
- package/dist/commonjs/utils/with-precision.js +23 -0
- package/dist/es/aria/index.js +1 -0
- package/dist/es/aria/key-codes.js +22 -0
- package/dist/es/array/all-pass.js +7 -0
- package/dist/es/array/any-pass.js +7 -0
- package/dist/es/array/chunk.js +13 -0
- package/dist/es/array/compact.js +4 -0
- package/dist/es/array/concat.js +7 -0
- package/dist/es/array/count-by.js +18 -0
- package/dist/es/array/difference-with.js +27 -0
- package/dist/es/array/difference.js +28 -0
- package/dist/es/array/drop-first-by.js +22 -0
- package/dist/es/array/drop-last-while.js +12 -0
- package/dist/es/array/drop-last.js +11 -0
- package/dist/es/array/drop-while.js +12 -0
- package/dist/es/array/drop.js +28 -0
- package/dist/es/array/filter.js +37 -0
- package/dist/es/array/find-index.js +42 -0
- package/dist/es/array/find-last-index.js +20 -0
- package/dist/es/array/find-last.js +20 -0
- package/dist/es/array/find.js +34 -0
- package/dist/es/array/first-by.js +18 -0
- package/dist/es/array/first.js +22 -0
- package/dist/es/array/flat-map-to-obj.js +21 -0
- package/dist/es/array/flat-map.js +29 -0
- package/dist/es/array/flatten-deep.js +44 -0
- package/dist/es/array/flatten.js +28 -0
- package/dist/es/array/for-each.js +36 -0
- package/dist/es/array/group-by.js +29 -0
- package/dist/es/array/has-at-least.js +7 -0
- package/dist/es/array/index-by.js +20 -0
- package/dist/es/array/index.js +65 -0
- package/dist/es/array/intersection-with.js +27 -0
- package/dist/es/array/intersection.js +28 -0
- package/dist/es/array/join.js +7 -0
- package/dist/es/array/last.js +7 -0
- package/dist/es/array/length.js +7 -0
- package/dist/es/array/map-to-obj.js +19 -0
- package/dist/es/array/map.js +31 -0
- package/dist/es/array/max-by.js +24 -0
- package/dist/es/array/mean-by.js +22 -0
- package/dist/es/array/merge-all.js +3 -0
- package/dist/es/array/min-by.js +24 -0
- package/dist/es/array/nth-by.js +8 -0
- package/dist/es/array/only.js +10 -0
- package/dist/es/array/partition.js +20 -0
- package/dist/es/array/range.js +11 -0
- package/dist/es/array/rank-by.js +13 -0
- package/dist/es/array/reduce.js +15 -0
- package/dist/es/array/reject.js +37 -0
- package/dist/es/array/reverse.js +7 -0
- package/dist/es/array/sample.js +30 -0
- package/dist/es/array/shuffle.js +14 -0
- package/dist/es/array/sort-by.js +48 -0
- package/dist/es/array/sort.js +12 -0
- package/dist/es/array/splice.js +9 -0
- package/dist/es/array/split-at.js +9 -0
- package/dist/es/array/split-when.js +13 -0
- package/dist/es/array/sum-by.js +20 -0
- package/dist/es/array/swap-indices.js +30 -0
- package/dist/es/array/take-first-by.js +20 -0
- package/dist/es/array/take-while.js +14 -0
- package/dist/es/array/take.js +34 -0
- package/dist/es/array/uniq-by.js +26 -0
- package/dist/es/array/uniq-with.js +29 -0
- package/dist/es/array/uniq.js +28 -0
- package/dist/es/array/zip-obj.js +12 -0
- package/dist/es/array/zip-with.js +19 -0
- package/dist/es/array/zip.js +15 -0
- package/dist/es/function/conditional.js +30 -0
- package/dist/es/function/create-pipe.js +4 -0
- package/dist/es/function/debounce.js +84 -0
- package/dist/es/function/identity.js +3 -0
- package/dist/es/function/index.js +9 -0
- package/dist/es/function/noop.js +3 -0
- package/dist/es/function/once.js +11 -0
- package/dist/es/function/pipe.js +102 -0
- package/dist/es/function/purry.js +16 -0
- package/dist/es/function/sleep.js +5 -0
- package/dist/es/guard/index.js +16 -0
- package/dist/es/guard/is-array.js +3 -0
- package/dist/es/guard/is-boolean.js +3 -0
- package/dist/es/guard/is-date.js +3 -0
- package/dist/es/guard/is-defined.js +9 -0
- package/dist/es/guard/is-empty.js +15 -0
- package/dist/es/guard/is-error.js +3 -0
- package/dist/es/guard/is-function.js +3 -0
- package/dist/es/guard/is-nil.js +3 -0
- package/dist/es/guard/is-non-null.js +3 -0
- package/dist/es/guard/is-not.js +5 -0
- package/dist/es/guard/is-number.js +3 -0
- package/dist/es/guard/is-object.js +7 -0
- package/dist/es/guard/is-promise.js +3 -0
- package/dist/es/guard/is-string.js +3 -0
- package/dist/es/guard/is-symbol.js +3 -0
- package/dist/es/guard/is-truthy.js +3 -0
- package/dist/es/index.js +9 -0
- package/dist/es/number/add.js +7 -0
- package/dist/es/number/ceil.js +5 -0
- package/dist/es/number/clamp.js +13 -0
- package/dist/es/number/divide.js +7 -0
- package/dist/es/number/floor.js +5 -0
- package/dist/es/number/index.js +8 -0
- package/dist/es/number/multiply.js +7 -0
- package/dist/es/number/round.js +5 -0
- package/dist/es/number/subtract.js +7 -0
- package/dist/es/object/add-prop.js +10 -0
- package/dist/es/object/clone.js +45 -0
- package/dist/es/object/equals.js +67 -0
- package/dist/es/object/for-each-obj.js +26 -0
- package/dist/es/object/from-pairs.js +10 -0
- package/dist/es/object/index.js +23 -0
- package/dist/es/object/invert.js +11 -0
- package/dist/es/object/keys.js +6 -0
- package/dist/es/object/map-keys.js +12 -0
- package/dist/es/object/map-values.js +12 -0
- package/dist/es/object/merge-deep.js +27 -0
- package/dist/es/object/merge.js +7 -0
- package/dist/es/object/omit-by.js +16 -0
- package/dist/es/object/omit.js +21 -0
- package/dist/es/object/path-or.js +14 -0
- package/dist/es/object/pick-by.js +16 -0
- package/dist/es/object/pick.js +15 -0
- package/dist/es/object/prop.js +3 -0
- package/dist/es/object/set-path.js +21 -0
- package/dist/es/object/set.js +10 -0
- package/dist/es/object/swap-props.js +12 -0
- package/dist/es/object/to-pairs.js +7 -0
- package/dist/es/object/values.js +3 -0
- package/dist/es/string/cases-types.js +1 -0
- package/dist/es/string/cases.js +93 -0
- package/dist/es/string/human-readable-file-size.js +12 -0
- package/dist/es/string/index.js +5 -0
- package/dist/es/string/random-string.js +6 -0
- package/dist/es/string/slugify.js +9 -0
- package/dist/es/string/string-to-path.js +14 -0
- package/dist/es/type/index.js +1 -0
- package/dist/es/type/type.js +9 -0
- package/dist/es/utils/heap.js +38 -0
- package/dist/es/utils/narrow.js +1 -0
- package/dist/es/utils/paths.js +1 -0
- package/dist/es/utils/purry-on.js +6 -0
- package/dist/es/utils/purry-order-rules.js +61 -0
- package/dist/es/utils/quick-select.js +27 -0
- package/dist/es/utils/reduce-lazy.js +14 -0
- package/dist/es/utils/swap-in-place.js +3 -0
- package/dist/es/utils/to-lazy-indexed.js +3 -0
- package/dist/es/utils/to-single.js +4 -0
- package/dist/es/utils/types.js +1 -0
- package/dist/es/utils/with-precision.js +19 -0
- package/dist/metadata.json +48311 -0
- package/dist/types/aria/index.d.ts +2 -0
- package/dist/types/aria/index.d.ts.map +1 -0
- package/dist/types/aria/key-codes.d.ts +26 -0
- package/dist/types/aria/key-codes.d.ts.map +1 -0
- package/dist/types/array/all-pass.d.ts +32 -0
- package/dist/types/array/all-pass.d.ts.map +1 -0
- package/dist/types/array/any-pass.d.ts +32 -0
- package/dist/types/array/any-pass.d.ts.map +1 -0
- package/dist/types/array/chunk.d.ts +29 -0
- package/dist/types/array/chunk.d.ts.map +1 -0
- package/dist/types/array/compact.d.ts +12 -0
- package/dist/types/array/compact.d.ts.map +1 -0
- package/dist/types/array/concat.d.ts +24 -0
- package/dist/types/array/concat.d.ts.map +1 -0
- package/dist/types/array/count-by.d.ts +20 -0
- package/dist/types/array/count-by.d.ts.map +1 -0
- package/dist/types/array/difference-with.d.ts +48 -0
- package/dist/types/array/difference-with.d.ts.map +1 -0
- package/dist/types/array/difference.d.ts +35 -0
- package/dist/types/array/difference.d.ts.map +1 -0
- package/dist/types/array/drop-first-by.d.ts +39 -0
- package/dist/types/array/drop-first-by.d.ts.map +1 -0
- package/dist/types/array/drop-last-while.d.ts +30 -0
- package/dist/types/array/drop-last-while.d.ts.map +1 -0
- package/dist/types/array/drop-last.d.ts +25 -0
- package/dist/types/array/drop-last.d.ts.map +1 -0
- package/dist/types/array/drop-while.d.ts +33 -0
- package/dist/types/array/drop-while.d.ts.map +1 -0
- package/dist/types/array/drop.d.ts +31 -0
- package/dist/types/array/drop.d.ts.map +1 -0
- package/dist/types/array/filter.d.ts +49 -0
- package/dist/types/array/filter.d.ts.map +1 -0
- package/dist/types/array/find-index.d.ts +67 -0
- package/dist/types/array/find-index.d.ts.map +1 -0
- package/dist/types/array/find-last-index.d.ts +43 -0
- package/dist/types/array/find-last-index.d.ts.map +1 -0
- package/dist/types/array/find-last.d.ts +45 -0
- package/dist/types/array/find-last.d.ts.map +1 -0
- package/dist/types/array/find.d.ts +59 -0
- package/dist/types/array/find.d.ts.map +1 -0
- package/dist/types/array/first-by.d.ts +57 -0
- package/dist/types/array/first-by.d.ts.map +1 -0
- package/dist/types/array/first.d.ts +35 -0
- package/dist/types/array/first.d.ts.map +1 -0
- package/dist/types/array/flat-map-to-obj.d.ts +50 -0
- package/dist/types/array/flat-map-to-obj.d.ts.map +1 -0
- package/dist/types/array/flat-map.d.ts +39 -0
- package/dist/types/array/flat-map.d.ts.map +1 -0
- package/dist/types/array/flatten-deep.d.ts +26 -0
- package/dist/types/array/flatten-deep.d.ts.map +1 -0
- package/dist/types/array/flatten.d.ts +23 -0
- package/dist/types/array/flatten.d.ts.map +1 -0
- package/dist/types/array/for-each.d.ts +57 -0
- package/dist/types/array/for-each.d.ts.map +1 -0
- package/dist/types/array/group-by.d.ts +36 -0
- package/dist/types/array/group-by.d.ts.map +1 -0
- package/dist/types/array/has-at-least.d.ts +47 -0
- package/dist/types/array/has-at-least.d.ts.map +1 -0
- package/dist/types/array/index-by.d.ts +34 -0
- package/dist/types/array/index-by.d.ts.map +1 -0
- package/dist/types/array/index.d.ts +66 -0
- package/dist/types/array/index.d.ts.map +1 -0
- package/dist/types/array/intersection-with.d.ts +54 -0
- package/dist/types/array/intersection-with.d.ts.map +1 -0
- package/dist/types/array/intersection.d.ts +30 -0
- package/dist/types/array/intersection.d.ts.map +1 -0
- package/dist/types/array/join.d.ts +45 -0
- package/dist/types/array/join.d.ts.map +1 -0
- package/dist/types/array/last.d.ts +24 -0
- package/dist/types/array/last.d.ts.map +1 -0
- package/dist/types/array/length.d.ts +14 -0
- package/dist/types/array/length.d.ts.map +1 -0
- package/dist/types/array/map-to-obj.d.ts +42 -0
- package/dist/types/array/map-to-obj.d.ts.map +1 -0
- package/dist/types/array/map.d.ts +62 -0
- package/dist/types/array/map.d.ts.map +1 -0
- package/dist/types/array/max-by.d.ts +39 -0
- package/dist/types/array/max-by.d.ts.map +1 -0
- package/dist/types/array/mean-by.d.ts +39 -0
- package/dist/types/array/mean-by.d.ts.map +1 -0
- package/dist/types/array/merge-all.d.ts +16 -0
- package/dist/types/array/merge-all.d.ts.map +1 -0
- package/dist/types/array/min-by.d.ts +39 -0
- package/dist/types/array/min-by.d.ts.map +1 -0
- package/dist/types/array/nth-by.d.ts +45 -0
- package/dist/types/array/nth-by.d.ts.map +1 -0
- package/dist/types/array/only.d.ts +36 -0
- package/dist/types/array/only.d.ts.map +1 -0
- package/dist/types/array/partition.d.ts +60 -0
- package/dist/types/array/partition.d.ts.map +1 -0
- package/dist/types/array/range.d.ts +22 -0
- package/dist/types/array/range.d.ts.map +1 -0
- package/dist/types/array/rank-by.d.ts +41 -0
- package/dist/types/array/rank-by.d.ts.map +1 -0
- package/dist/types/array/reduce.d.ts +35 -0
- package/dist/types/array/reduce.d.ts.map +1 -0
- package/dist/types/array/reject.d.ts +42 -0
- package/dist/types/array/reject.d.ts.map +1 -0
- package/dist/types/array/reverse.d.ts +25 -0
- package/dist/types/array/reverse.d.ts.map +1 -0
- package/dist/types/array/sample.d.ts +54 -0
- package/dist/types/array/sample.d.ts.map +1 -0
- package/dist/types/array/shuffle.d.ts +22 -0
- package/dist/types/array/shuffle.d.ts.map +1 -0
- package/dist/types/array/sort-by.d.ts +99 -0
- package/dist/types/array/sort-by.d.ts.map +1 -0
- package/dist/types/array/sort.d.ts +52 -0
- package/dist/types/array/sort.d.ts.map +1 -0
- package/dist/types/array/splice.d.ts +31 -0
- package/dist/types/array/splice.d.ts.map +1 -0
- package/dist/types/array/split-at.d.ts +26 -0
- package/dist/types/array/split-at.d.ts.map +1 -0
- package/dist/types/array/split-when.d.ts +24 -0
- package/dist/types/array/split-when.d.ts.map +1 -0
- package/dist/types/array/sum-by.d.ts +39 -0
- package/dist/types/array/sum-by.d.ts.map +1 -0
- package/dist/types/array/swap-indices.d.ts +68 -0
- package/dist/types/array/swap-indices.d.ts.map +1 -0
- package/dist/types/array/take-first-by.d.ts +43 -0
- package/dist/types/array/take-first-by.d.ts.map +1 -0
- package/dist/types/array/take-while.d.ts +24 -0
- package/dist/types/array/take-while.d.ts.map +1 -0
- package/dist/types/array/take.d.ts +30 -0
- package/dist/types/array/take.d.ts.map +1 -0
- package/dist/types/array/uniq-by.d.ts +22 -0
- package/dist/types/array/uniq-by.d.ts.map +1 -0
- package/dist/types/array/uniq-with.d.ts +44 -0
- package/dist/types/array/uniq-with.d.ts.map +1 -0
- package/dist/types/array/uniq.d.ts +24 -0
- package/dist/types/array/uniq.d.ts.map +1 -0
- package/dist/types/array/zip-obj.d.ts +26 -0
- package/dist/types/array/zip-obj.d.ts.map +1 -0
- package/dist/types/array/zip-with.d.ts +42 -0
- package/dist/types/array/zip-with.d.ts.map +1 -0
- package/dist/types/array/zip.d.ts +52 -0
- package/dist/types/array/zip.d.ts.map +1 -0
- package/dist/types/function/conditional.d.ts +108 -0
- package/dist/types/function/conditional.d.ts.map +1 -0
- package/dist/types/function/create-pipe.d.ts +19 -0
- package/dist/types/function/create-pipe.d.ts.map +1 -0
- package/dist/types/function/debounce.d.ts +92 -0
- package/dist/types/function/debounce.d.ts.map +1 -0
- package/dist/types/function/identity.d.ts +10 -0
- package/dist/types/function/identity.d.ts.map +1 -0
- package/dist/types/function/index.d.ts +10 -0
- package/dist/types/function/index.d.ts.map +1 -0
- package/dist/types/function/noop.d.ts +10 -0
- package/dist/types/function/noop.d.ts.map +1 -0
- package/dist/types/function/once.d.ts +13 -0
- package/dist/types/function/once.d.ts.map +1 -0
- package/dist/types/function/pipe.d.ts +32 -0
- package/dist/types/function/pipe.d.ts.map +1 -0
- package/dist/types/function/purry.d.ts +32 -0
- package/dist/types/function/purry.d.ts.map +1 -0
- package/dist/types/function/sleep.d.ts +12 -0
- package/dist/types/function/sleep.d.ts.map +1 -0
- package/dist/types/guard/index.d.ts +17 -0
- package/dist/types/guard/index.d.ts.map +1 -0
- package/dist/types/guard/is-array.d.ts +15 -0
- package/dist/types/guard/is-array.d.ts.map +1 -0
- package/dist/types/guard/is-boolean.d.ts +15 -0
- package/dist/types/guard/is-boolean.d.ts.map +1 -0
- package/dist/types/guard/is-date.d.ts +13 -0
- package/dist/types/guard/is-date.d.ts.map +1 -0
- package/dist/types/guard/is-defined.d.ts +22 -0
- package/dist/types/guard/is-defined.d.ts.map +1 -0
- package/dist/types/guard/is-empty.d.ts +19 -0
- package/dist/types/guard/is-empty.d.ts.map +1 -0
- package/dist/types/guard/is-error.d.ts +15 -0
- package/dist/types/guard/is-error.d.ts.map +1 -0
- package/dist/types/guard/is-function.d.ts +15 -0
- package/dist/types/guard/is-function.d.ts.map +1 -0
- package/dist/types/guard/is-nil.d.ts +14 -0
- package/dist/types/guard/is-nil.d.ts.map +1 -0
- package/dist/types/guard/is-non-null.d.ts +15 -0
- package/dist/types/guard/is-non-null.d.ts.map +1 -0
- package/dist/types/guard/is-not.d.ts +15 -0
- package/dist/types/guard/is-not.d.ts.map +1 -0
- package/dist/types/guard/is-number.d.ts +14 -0
- package/dist/types/guard/is-number.d.ts.map +1 -0
- package/dist/types/guard/is-object.d.ts +28 -0
- package/dist/types/guard/is-object.d.ts.map +1 -0
- package/dist/types/guard/is-promise.d.ts +14 -0
- package/dist/types/guard/is-promise.d.ts.map +1 -0
- package/dist/types/guard/is-string.d.ts +14 -0
- package/dist/types/guard/is-string.d.ts.map +1 -0
- package/dist/types/guard/is-symbol.d.ts +14 -0
- package/dist/types/guard/is-symbol.d.ts.map +1 -0
- package/dist/types/guard/is-truthy.d.ts +17 -0
- package/dist/types/guard/is-truthy.d.ts.map +1 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/number/add.d.ts +29 -0
- package/dist/types/number/add.d.ts.map +1 -0
- package/dist/types/number/ceil.d.ts +35 -0
- package/dist/types/number/ceil.d.ts.map +1 -0
- package/dist/types/number/clamp.d.ts +38 -0
- package/dist/types/number/clamp.d.ts.map +1 -0
- package/dist/types/number/divide.d.ts +27 -0
- package/dist/types/number/divide.d.ts.map +1 -0
- package/dist/types/number/floor.d.ts +35 -0
- package/dist/types/number/floor.d.ts.map +1 -0
- package/dist/types/number/index.d.ts +9 -0
- package/dist/types/number/index.d.ts.map +1 -0
- package/dist/types/number/multiply.d.ts +27 -0
- package/dist/types/number/multiply.d.ts.map +1 -0
- package/dist/types/number/round.d.ts +35 -0
- package/dist/types/number/round.d.ts.map +1 -0
- package/dist/types/number/subtract.d.ts +29 -0
- package/dist/types/number/subtract.d.ts.map +1 -0
- package/dist/types/object/add-prop.d.ts +30 -0
- package/dist/types/object/add-prop.d.ts.map +1 -0
- package/dist/types/object/clone.d.ts +10 -0
- package/dist/types/object/clone.d.ts.map +1 -0
- package/dist/types/object/equals.d.ts +30 -0
- package/dist/types/object/equals.d.ts.map +1 -0
- package/dist/types/object/for-each-obj.d.ts +44 -0
- package/dist/types/object/for-each-obj.d.ts.map +1 -0
- package/dist/types/object/from-pairs.d.ts +38 -0
- package/dist/types/object/from-pairs.d.ts.map +1 -0
- package/dist/types/object/index.d.ts +24 -0
- package/dist/types/object/index.d.ts.map +1 -0
- package/dist/types/object/invert.d.ts +28 -0
- package/dist/types/object/invert.d.ts.map +1 -0
- package/dist/types/object/keys.d.ts +34 -0
- package/dist/types/object/keys.d.ts.map +1 -0
- package/dist/types/object/map-keys.d.ts +24 -0
- package/dist/types/object/map-keys.d.ts.map +1 -0
- package/dist/types/object/map-values.d.ts +25 -0
- package/dist/types/object/map-values.d.ts.map +1 -0
- package/dist/types/object/merge-deep.d.ts +32 -0
- package/dist/types/object/merge-deep.d.ts.map +1 -0
- package/dist/types/object/merge.d.ts +25 -0
- package/dist/types/object/merge.d.ts.map +1 -0
- package/dist/types/object/omit-by.d.ts +22 -0
- package/dist/types/object/omit-by.d.ts.map +1 -0
- package/dist/types/object/omit.d.ts +24 -0
- package/dist/types/object/omit.d.ts.map +1 -0
- package/dist/types/object/path-or.d.ts +76 -0
- package/dist/types/object/path-or.d.ts.map +1 -0
- package/dist/types/object/pick-by.d.ts +22 -0
- package/dist/types/object/pick-by.d.ts.map +1 -0
- package/dist/types/object/pick.d.ts +22 -0
- package/dist/types/object/pick.d.ts.map +1 -0
- package/dist/types/object/prop.d.ts +11 -0
- package/dist/types/object/prop.d.ts.map +1 -0
- package/dist/types/object/set-path.d.ts +29 -0
- package/dist/types/object/set-path.d.ts.map +1 -0
- package/dist/types/object/set.d.ts +26 -0
- package/dist/types/object/set.d.ts.map +1 -0
- package/dist/types/object/swap-props.d.ts +44 -0
- package/dist/types/object/swap-props.d.ts.map +1 -0
- package/dist/types/object/to-pairs.d.ts +33 -0
- package/dist/types/object/to-pairs.d.ts.map +1 -0
- package/dist/types/object/values.d.ts +20 -0
- package/dist/types/object/values.d.ts.map +1 -0
- package/dist/types/string/cases-types.d.ts +36 -0
- package/dist/types/string/cases-types.d.ts.map +1 -0
- package/dist/types/string/cases.d.ts +22 -0
- package/dist/types/string/cases.d.ts.map +1 -0
- package/dist/types/string/human-readable-file-size.d.ts +13 -0
- package/dist/types/string/human-readable-file-size.d.ts.map +1 -0
- package/dist/types/string/index.d.ts +6 -0
- package/dist/types/string/index.d.ts.map +1 -0
- package/dist/types/string/random-string.d.ts +10 -0
- package/dist/types/string/random-string.d.ts.map +1 -0
- package/dist/types/string/slugify.d.ts +12 -0
- package/dist/types/string/slugify.d.ts.map +1 -0
- package/dist/types/string/string-to-path.d.ts +11 -0
- package/dist/types/string/string-to-path.d.ts.map +1 -0
- package/dist/types/type/index.d.ts +2 -0
- package/dist/types/type/index.d.ts.map +1 -0
- package/dist/types/type/type.d.ts +19 -0
- package/dist/types/type/type.d.ts.map +1 -0
- package/dist/types/utils/heap.d.ts +24 -0
- package/dist/types/utils/heap.d.ts.map +1 -0
- package/dist/types/utils/narrow.d.ts +52 -0
- package/dist/types/utils/narrow.d.ts.map +1 -0
- package/dist/types/utils/paths.d.ts +9 -0
- package/dist/types/utils/paths.d.ts.map +1 -0
- package/dist/types/utils/purry-on.d.ts +7 -0
- package/dist/types/utils/purry-on.d.ts.map +1 -0
- package/dist/types/utils/purry-order-rules.d.ts +52 -0
- package/dist/types/utils/purry-order-rules.d.ts.map +1 -0
- package/dist/types/utils/quick-select.d.ts +18 -0
- package/dist/types/utils/quick-select.d.ts.map +1 -0
- package/dist/types/utils/reduce-lazy.d.ts +22 -0
- package/dist/types/utils/reduce-lazy.d.ts.map +1 -0
- package/dist/types/utils/swap-in-place.d.ts +5 -0
- package/dist/types/utils/swap-in-place.d.ts.map +1 -0
- package/dist/types/utils/to-lazy-indexed.d.ts +4 -0
- package/dist/types/utils/to-lazy-indexed.d.ts.map +1 -0
- package/dist/types/utils/to-single.d.ts +4 -0
- package/dist/types/utils/to-single.d.ts.map +1 -0
- package/dist/types/utils/types.d.ts +32 -0
- package/dist/types/utils/types.d.ts.map +1 -0
- package/dist/types/utils/with-precision.d.ts +2 -0
- package/dist/types/utils/with-precision.d.ts.map +1 -0
- package/package.json +34 -23
- package/dist/index.cjs +0 -2843
- package/dist/index.d.cts +0 -4175
- package/dist/index.d.ts +0 -4175
- package/dist/index.js +0 -2678
- package/dist/index.min.js +0 -2
- package/dist/index.min.js.map +0 -7
package/dist/index.d.cts
DELETED
|
@@ -1,4175 +0,0 @@
|
|
|
1
|
-
import { IsAny, ReadonlyTuple, MergeDeep } from 'type-fest';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Using event.code is not predictable since each machine may have different output
|
|
5
|
-
*/
|
|
6
|
-
declare const KEY_CODES: {
|
|
7
|
-
readonly ALT: "Alt";
|
|
8
|
-
readonly ARROW_DOWN: "ArrowDown";
|
|
9
|
-
readonly ARROW_LEFT: "ArrowLeft";
|
|
10
|
-
readonly ARROW_RIGHT: "ArrowRight";
|
|
11
|
-
readonly ARROW_UP: "ArrowUp";
|
|
12
|
-
readonly AT: "@";
|
|
13
|
-
readonly BACKSPACE: "Backspace";
|
|
14
|
-
readonly CTRL: "Control";
|
|
15
|
-
readonly DELETE: "Delete";
|
|
16
|
-
readonly END: "End";
|
|
17
|
-
readonly ENTER: "Enter";
|
|
18
|
-
readonly ESC: "Escape";
|
|
19
|
-
readonly HOME: "Home";
|
|
20
|
-
readonly KEY_F: "KEY_F";
|
|
21
|
-
readonly META: "Meta";
|
|
22
|
-
readonly PAGE_DOWN: "PageDown";
|
|
23
|
-
readonly PAGE_UP: "PageUp";
|
|
24
|
-
readonly SHIFT: "Shift";
|
|
25
|
-
readonly SPACE: "Space";
|
|
26
|
-
readonly TAB: "Tab";
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Determines whether all predicates returns true for the input data.
|
|
31
|
-
* @param data The input data for predicates.
|
|
32
|
-
* @param fns The list of predicates.
|
|
33
|
-
* @signature
|
|
34
|
-
* P.allPass(data, fns)
|
|
35
|
-
* @example
|
|
36
|
-
* const isDivisibleBy3 = (x: number) => x % 3 === 0
|
|
37
|
-
* const isDivisibleBy4 = (x: number) => x % 4 === 0
|
|
38
|
-
* const fns = [isDivisibleBy3, isDivisibleBy4]
|
|
39
|
-
* P.allPass(12, fns) // => true
|
|
40
|
-
* P.allPass(8, fns) // => false
|
|
41
|
-
* @dataFirst
|
|
42
|
-
* @category Array
|
|
43
|
-
*/
|
|
44
|
-
declare function allPass<T>(data: T, fns: ReadonlyArray<(data: T) => boolean>): boolean;
|
|
45
|
-
/**
|
|
46
|
-
* Determines whether all predicates returns true for the input data.
|
|
47
|
-
* @param fns The list of predicates.
|
|
48
|
-
* @signature
|
|
49
|
-
* P.allPass(fns)(data)
|
|
50
|
-
* @example
|
|
51
|
-
* const isDivisibleBy3 = (x: number) => x % 3 === 0
|
|
52
|
-
* const isDivisibleBy4 = (x: number) => x % 4 === 0
|
|
53
|
-
* const fns = [isDivisibleBy3, isDivisibleBy4]
|
|
54
|
-
* P.allPass(fns)(12) // => true
|
|
55
|
-
* P.allPass(fns)(8) // => false
|
|
56
|
-
* @dataLast
|
|
57
|
-
* @category Array
|
|
58
|
-
*/
|
|
59
|
-
declare function allPass<T>(fns: ReadonlyArray<(data: T) => boolean>): (data: T) => boolean;
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Determines whether any predicate returns true for the input data.
|
|
63
|
-
* @param data The input data for predicates.
|
|
64
|
-
* @param fns The list of predicates.
|
|
65
|
-
* @signature
|
|
66
|
-
* P.anyPass(data, fns)
|
|
67
|
-
* @example
|
|
68
|
-
* const isDivisibleBy3 = (x: number) => x % 3 === 0
|
|
69
|
-
* const isDivisibleBy4 = (x: number) => x % 4 === 0
|
|
70
|
-
* const fns = [isDivisibleBy3, isDivisibleBy4]
|
|
71
|
-
* P.anyPass(8, fns) // => true
|
|
72
|
-
* P.anyPass(11, fns) // => false
|
|
73
|
-
* @dataFirst
|
|
74
|
-
* @category Array
|
|
75
|
-
*/
|
|
76
|
-
declare function anyPass<T>(data: T, fns: ReadonlyArray<(data: T) => boolean>): boolean;
|
|
77
|
-
/**
|
|
78
|
-
* Determines whether any predicate returns true for the input data.
|
|
79
|
-
* @param fns The list of predicates.
|
|
80
|
-
* @signature
|
|
81
|
-
* P.anyPass(fns)(data)
|
|
82
|
-
* @example
|
|
83
|
-
* const isDivisibleBy3 = (x: number) => x % 3 === 0
|
|
84
|
-
* const isDivisibleBy4 = (x: number) => x % 4 === 0
|
|
85
|
-
* const fns = [isDivisibleBy3, isDivisibleBy4]
|
|
86
|
-
* P.anyPass(fns)(8) // => true
|
|
87
|
-
* P.anyPass(fns)(11) // => false
|
|
88
|
-
* @dataLast
|
|
89
|
-
* @category Array
|
|
90
|
-
*/
|
|
91
|
-
declare function anyPass<T>(fns: ReadonlyArray<(data: T) => boolean>): (data: T) => boolean;
|
|
92
|
-
|
|
93
|
-
type Pred<T, K> = (input: T) => K;
|
|
94
|
-
type PredIndexed<T, K> = (input: T, index: number, array: Array<T>) => K;
|
|
95
|
-
type PredIndexedOptional<T, K> = (input: T, index?: number, array?: ReadonlyArray<T>) => K;
|
|
96
|
-
type NonEmptyArray<T> = [T, ...Array<T>];
|
|
97
|
-
/**
|
|
98
|
-
* This should only be used for defining generics which extend any kind of JS
|
|
99
|
-
* array under the hood, this includes arrays *AND* tuples (of the form [x, y],
|
|
100
|
-
* and of the form [x, ...y[]], etc...), and their readonly equivalent. This
|
|
101
|
-
* allows us to be more inclusive to what functions can process.
|
|
102
|
-
*
|
|
103
|
-
* @example map<T extends ArrayLike>(items: T) { ... }
|
|
104
|
-
*
|
|
105
|
-
* We would've named this `ArrayLike`, but that's already used by typescript...
|
|
106
|
-
*
|
|
107
|
-
* @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)
|
|
108
|
-
*/
|
|
109
|
-
type IterableContainer<T = unknown> = [] | ReadonlyArray<T>;
|
|
110
|
-
type ObjectKeys$1<T extends object> = `${Exclude<keyof T, symbol>}`;
|
|
111
|
-
/**
|
|
112
|
-
* An extension of Extract for type predicates which falls back to the base
|
|
113
|
-
* in order to narrow the `unknown` case.
|
|
114
|
-
* @example
|
|
115
|
-
* function isMyType<T>(data: T | MyType): data is NarrowedTo<T, MyType> { ... }
|
|
116
|
-
*/
|
|
117
|
-
type NarrowedTo<T, Base> = Extract<T, Base> extends never ? Base : IsAny<T> extends true ? Base : Extract<T, Base>;
|
|
118
|
-
|
|
119
|
-
type Chunked<T extends IterableContainer> = T[number] extends never ? [] : T extends readonly [...Array<unknown>, unknown] | readonly [unknown, ...Array<unknown>] ? NonEmptyArray<NonEmptyArray<T[number]>> : Array<NonEmptyArray<T[number]>>;
|
|
120
|
-
/**
|
|
121
|
-
* Split an array into groups the length of `size`. If `array` can't be split evenly, the final chunk will be the remaining elements.
|
|
122
|
-
* @param array the array
|
|
123
|
-
* @param size the length of the chunk
|
|
124
|
-
* @signature
|
|
125
|
-
* P.chunk(array, size)
|
|
126
|
-
* @example
|
|
127
|
-
* P.chunk(['a', 'b', 'c', 'd'], 2) // => [['a', 'b'], ['c', 'd']]
|
|
128
|
-
* P.chunk(['a', 'b', 'c', 'd'], 3) // => [['a', 'b', 'c'], ['d']]
|
|
129
|
-
* @dataFirst
|
|
130
|
-
* @category Array
|
|
131
|
-
*/
|
|
132
|
-
declare function chunk<T extends IterableContainer>(array: T, size: number): Chunked<T>;
|
|
133
|
-
/**
|
|
134
|
-
* Split an array into groups the length of `size`. If `array` can't be split evenly, the final chunk will be the remaining elements.
|
|
135
|
-
* @param size the length of the chunk
|
|
136
|
-
* @signature
|
|
137
|
-
* P.chunk(size)(array)
|
|
138
|
-
* @example
|
|
139
|
-
* P.chunk(2)(['a', 'b', 'c', 'd']) // => [['a', 'b'], ['c', 'd']]
|
|
140
|
-
* P.chunk(3)(['a', 'b', 'c', 'd']) // => [['a', 'b', 'c'], ['d']]
|
|
141
|
-
* @dataLast
|
|
142
|
-
* @category Array
|
|
143
|
-
*/
|
|
144
|
-
declare function chunk<T extends IterableContainer>(size: number): (array: T) => Chunked<T>;
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Filter out all falsey values. The values `false`, `null`, `0`, `""`, `undefined`, and `NaN` are falsey.
|
|
148
|
-
* @param items the array to compact
|
|
149
|
-
* @signature
|
|
150
|
-
* P.compact(array)
|
|
151
|
-
* @example
|
|
152
|
-
* P.compact([0, 1, false, 2, '', 3]) // => [1, 2, 3]
|
|
153
|
-
* @category Array
|
|
154
|
-
* @pipeable
|
|
155
|
-
*/
|
|
156
|
-
declare function compact<T>(items: ReadonlyArray<'' | 0 | T | false | null | undefined>): Array<T>;
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Combines two arrays.
|
|
160
|
-
* @param arr1 the first array
|
|
161
|
-
* @param arr2 the second array
|
|
162
|
-
* @signature
|
|
163
|
-
* P.concat(arr1, arr2);
|
|
164
|
-
* @example
|
|
165
|
-
* P.concat([1, 2, 3], ['a']) // [1, 2, 3, 'a']
|
|
166
|
-
* @dataFirst
|
|
167
|
-
* @category Array
|
|
168
|
-
*/
|
|
169
|
-
declare function concat<T, K>(arr1: ReadonlyArray<T>, arr2: ReadonlyArray<K>): Array<K | T>;
|
|
170
|
-
/**
|
|
171
|
-
* Combines two arrays.
|
|
172
|
-
* @param arr2 the second array
|
|
173
|
-
* @signature
|
|
174
|
-
* P.concat(arr2)(arr1);
|
|
175
|
-
* @example
|
|
176
|
-
* P.concat(['a'])([1, 2, 3]) // [1, 2, 3, 'a']
|
|
177
|
-
* @dataLast
|
|
178
|
-
* @category Array
|
|
179
|
-
*/
|
|
180
|
-
declare function concat<T, K>(arr2: ReadonlyArray<K>): (arr1: ReadonlyArray<T>) => Array<K | T>;
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Counts how many values of the collection pass the specified predicate.
|
|
184
|
-
* @param items The input data.
|
|
185
|
-
* @param fn The predicate.
|
|
186
|
-
* @signature
|
|
187
|
-
* P.countBy(array, fn)
|
|
188
|
-
* @example
|
|
189
|
-
* P.countBy([1, 2, 3, 4, 5], x => x % 2 === 0) // => 2
|
|
190
|
-
* @dataFirst
|
|
191
|
-
* @indexed
|
|
192
|
-
* @category Array
|
|
193
|
-
*/
|
|
194
|
-
declare function countBy<T>(items: ReadonlyArray<T>, fn: Pred<T, boolean>): number;
|
|
195
|
-
declare function countBy<T>(fn: Pred<T, boolean>): (array: ReadonlyArray<T>) => number;
|
|
196
|
-
declare namespace countBy {
|
|
197
|
-
function indexed<T>(array: ReadonlyArray<T>, fn: PredIndexed<T, boolean>): number;
|
|
198
|
-
function indexed<T>(fn: PredIndexed<T, boolean>): (array: ReadonlyArray<T>) => number;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
type LazyResult<T> = LazyEmpty | LazyMany<T> | LazyNext<T>;
|
|
202
|
-
interface LazyEmpty {
|
|
203
|
-
done: boolean;
|
|
204
|
-
hasMany?: false | undefined;
|
|
205
|
-
hasNext: false;
|
|
206
|
-
next?: undefined;
|
|
207
|
-
}
|
|
208
|
-
interface LazyNext<T> {
|
|
209
|
-
done: boolean;
|
|
210
|
-
hasMany?: false | undefined;
|
|
211
|
-
hasNext: true;
|
|
212
|
-
next: T;
|
|
213
|
-
}
|
|
214
|
-
interface LazyMany<T> {
|
|
215
|
-
done: boolean;
|
|
216
|
-
hasMany: true;
|
|
217
|
-
hasNext: true;
|
|
218
|
-
next: Array<T>;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
type IsEquals$1<TFirst, TSecond> = (a: TFirst, b: TSecond) => boolean;
|
|
222
|
-
/**
|
|
223
|
-
* Excludes the values from `other` array.
|
|
224
|
-
* Elements are compared by custom comparator isEquals.
|
|
225
|
-
* @param array the source array
|
|
226
|
-
* @param other the values to exclude
|
|
227
|
-
* @param isEquals the comparator
|
|
228
|
-
* @signature
|
|
229
|
-
* P.differenceWith(array, other, isEquals)
|
|
230
|
-
* @example
|
|
231
|
-
* P.differenceWith(
|
|
232
|
-
* [{a: 1}, {a: 2}, {a: 3}, {a: 4}],
|
|
233
|
-
* [{a: 2}, {a: 5}, {a: 3}],
|
|
234
|
-
* P.equals,
|
|
235
|
-
* ) // => [{a: 1}, {a: 4}]
|
|
236
|
-
* @dataFirst
|
|
237
|
-
* @category Array
|
|
238
|
-
* @pipeable
|
|
239
|
-
*/
|
|
240
|
-
declare function differenceWith<TFirst, TSecond>(array: ReadonlyArray<TFirst>, other: ReadonlyArray<TSecond>, isEquals: IsEquals$1<TFirst, TSecond>): Array<TFirst>;
|
|
241
|
-
/**
|
|
242
|
-
* Excludes the values from `other` array.
|
|
243
|
-
* Elements are compared by custom comparator isEquals.
|
|
244
|
-
* @param other the values to exclude
|
|
245
|
-
* @param isEquals the comparator
|
|
246
|
-
* @signature
|
|
247
|
-
* P.differenceWith(other, isEquals)(array)
|
|
248
|
-
* @example
|
|
249
|
-
* P.differenceWith(
|
|
250
|
-
* [{a: 2}, {a: 5}, {a: 3}],
|
|
251
|
-
* P.equals,
|
|
252
|
-
* )([{a: 1}, {a: 2}, {a: 3}, {a: 4}]) // => [{a: 1}, {a: 4}]
|
|
253
|
-
* P.pipe(
|
|
254
|
-
* [{a: 1}, {a: 2}, {a: 3}, {a: 4}, {a: 5}, {a: 6}], // only 4 iterations
|
|
255
|
-
* P.differenceWith([{a: 2}, {a: 3}], P.equals),
|
|
256
|
-
* P.take(2),
|
|
257
|
-
* ) // => [{a: 1}, {a: 4}]
|
|
258
|
-
* @dataLast
|
|
259
|
-
* @category Array
|
|
260
|
-
* @pipeable
|
|
261
|
-
*/
|
|
262
|
-
declare function differenceWith<TFirst, TSecond>(other: ReadonlyArray<TSecond>, isEquals: IsEquals$1<TFirst, TSecond>): (array: ReadonlyArray<TFirst>) => Array<TFirst>;
|
|
263
|
-
declare namespace differenceWith {
|
|
264
|
-
function lazy<TFirst, TSecond>(other: Array<TSecond>, isEquals: IsEquals$1<TFirst, TSecond>): (value: TFirst) => LazyResult<TFirst>;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
/**
|
|
268
|
-
* Excludes the values from `other` array.
|
|
269
|
-
* @param array the source array
|
|
270
|
-
* @param other the values to exclude
|
|
271
|
-
* @signature
|
|
272
|
-
* P.difference(array, other)
|
|
273
|
-
* @example
|
|
274
|
-
* P.difference([1, 2, 3, 4], [2, 5, 3]) // => [1, 4]
|
|
275
|
-
* @dataFirst
|
|
276
|
-
* @category Array
|
|
277
|
-
* @pipeable
|
|
278
|
-
*/
|
|
279
|
-
declare function difference<T>(array: ReadonlyArray<T>, other: ReadonlyArray<T>): Array<T>;
|
|
280
|
-
/**
|
|
281
|
-
* Excludes the values from `other` array.
|
|
282
|
-
* @param other the values to exclude
|
|
283
|
-
* @signature
|
|
284
|
-
* P.difference(other)(array)
|
|
285
|
-
* @example
|
|
286
|
-
* P.difference([2, 5, 3])([1, 2, 3, 4]) // => [1, 4]
|
|
287
|
-
* P.pipe(
|
|
288
|
-
* [1, 2, 3, 4, 5, 6], // only 4 iterations
|
|
289
|
-
* P.difference([2, 3]),
|
|
290
|
-
* P.take(2)
|
|
291
|
-
* ) // => [1, 4]
|
|
292
|
-
* @dataLast
|
|
293
|
-
* @category Array
|
|
294
|
-
* @pipeable
|
|
295
|
-
*/
|
|
296
|
-
declare function difference<T, K>(other: ReadonlyArray<T>): (array: ReadonlyArray<K>) => Array<T>;
|
|
297
|
-
declare namespace difference {
|
|
298
|
-
function lazy<T>(other: Array<T>): (value: T) => LazyResult<T>;
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
/**
|
|
302
|
-
* Removes last `n` elements from the `array`.
|
|
303
|
-
* @param array the target array
|
|
304
|
-
* @param n the number of elements to skip
|
|
305
|
-
* @signature
|
|
306
|
-
* P.dropLast(array, n)
|
|
307
|
-
* @example
|
|
308
|
-
* P.dropLast([1, 2, 3, 4, 5], 2) // => [1, 2, 3]
|
|
309
|
-
* @dataFirst
|
|
310
|
-
* @category Array
|
|
311
|
-
*/
|
|
312
|
-
declare function dropLast<T>(array: ReadonlyArray<T>, n: number): Array<T>;
|
|
313
|
-
/**
|
|
314
|
-
* Removes last `n` elements from the `array`.
|
|
315
|
-
* @param array the target array
|
|
316
|
-
* @param n the number of elements to skip
|
|
317
|
-
* @signature
|
|
318
|
-
* P.dropLast(n)(array)
|
|
319
|
-
* @example
|
|
320
|
-
* P.dropLast(2)([1, 2, 3, 4, 5]) // => [1, 2, 3]
|
|
321
|
-
* @dataLast
|
|
322
|
-
* @category Array
|
|
323
|
-
*/
|
|
324
|
-
declare function dropLast<T>(n: number): (array: ReadonlyArray<T>) => Array<T>;
|
|
325
|
-
|
|
326
|
-
/**
|
|
327
|
-
* Removes first `n` elements from the `array`.
|
|
328
|
-
* @param array the target array
|
|
329
|
-
* @param n the number of elements to skip
|
|
330
|
-
* @signature
|
|
331
|
-
* P.drop(array, n)
|
|
332
|
-
* @example
|
|
333
|
-
* P.drop([1, 2, 3, 4, 5], 2) // => [3, 4, 5]
|
|
334
|
-
* @dataFirst
|
|
335
|
-
* @pipeable
|
|
336
|
-
* @category Array
|
|
337
|
-
*/
|
|
338
|
-
declare function drop<T>(array: ReadonlyArray<T>, n: number): Array<T>;
|
|
339
|
-
/**
|
|
340
|
-
* Removes first `n` elements from the `array`.
|
|
341
|
-
* @param array the target array
|
|
342
|
-
* @param n the number of elements to skip
|
|
343
|
-
* @signature
|
|
344
|
-
* P.drop(n)(array)
|
|
345
|
-
* @example
|
|
346
|
-
* P.drop(2)([1, 2, 3, 4, 5]) // => [3, 4, 5]
|
|
347
|
-
* @dataLast
|
|
348
|
-
* @pipeable
|
|
349
|
-
* @category Array
|
|
350
|
-
*/
|
|
351
|
-
declare function drop<T>(n: number): (array: ReadonlyArray<T>) => Array<T>;
|
|
352
|
-
declare namespace drop {
|
|
353
|
-
function lazy<T>(n: number): (value: T) => LazyResult<T>;
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
declare const COMPARATORS: {
|
|
357
|
-
readonly asc: <T>(x: T, y: T) => boolean;
|
|
358
|
-
readonly desc: <T_1>(x: T_1, y: T_1) => boolean;
|
|
359
|
-
};
|
|
360
|
-
/**
|
|
361
|
-
* An order rule defines a projection/extractor that returns a comparable from
|
|
362
|
-
* the data being compared. It would be run on each item being compared, and a
|
|
363
|
-
* comparator would then be used on the results to determine the order.
|
|
364
|
-
*
|
|
365
|
-
* There are 2 forms of the order rule, a simple one which only provides the
|
|
366
|
-
* projection function and assumes ordering is ascending, and a 2-tuple where
|
|
367
|
-
* the first element is the projection function and the second is the direction;
|
|
368
|
-
* this allows changing the direction without defining a more complex projection
|
|
369
|
-
* to simply negate the value (e.g. `(x) => -x`).
|
|
370
|
-
*
|
|
371
|
-
* We rely on the javascript implementation of `<` and `>` for comparison, which
|
|
372
|
-
* will attempt to transform both operands into a primitive comparable value via
|
|
373
|
-
* the built in `valueOf` function (and then `toString`). It's up to the caller
|
|
374
|
-
* to make sure that the projection is returning a value that makes sense for
|
|
375
|
-
* this logic.
|
|
376
|
-
*
|
|
377
|
-
* It's important to note that there is no built-in caching/memoization of
|
|
378
|
-
* projection function and therefore no guarantee that it would only be called
|
|
379
|
-
* once.
|
|
380
|
-
*/
|
|
381
|
-
type OrderRule<T> = Projection<T> | readonly [projection: Projection<T>, direction: keyof typeof COMPARATORS];
|
|
382
|
-
type Projection<T> = (x: T) => Comparable$1;
|
|
383
|
-
type Comparable$1 = {
|
|
384
|
-
[Symbol.toPrimitive](hint: string): ComparablePrimitive$1;
|
|
385
|
-
} | {
|
|
386
|
-
toString(): string;
|
|
387
|
-
} | {
|
|
388
|
-
valueOf(): ComparablePrimitive$1;
|
|
389
|
-
} | ComparablePrimitive$1;
|
|
390
|
-
type ComparablePrimitive$1 = boolean | number | string;
|
|
391
|
-
|
|
392
|
-
/**
|
|
393
|
-
* Drop the first `n` items from `data` based on the provided ordering criteria.
|
|
394
|
-
* This allows you to avoid sorting the array before dropping the items.
|
|
395
|
-
* The complexity of this function is *O(Nlogn)* where `N` is the length of the array.
|
|
396
|
-
*
|
|
397
|
-
* For the opposite operation (to keep `n` elements) see `takeFirstBy`.
|
|
398
|
-
*
|
|
399
|
-
* @params data - the input array
|
|
400
|
-
* @params n - the number of items to drop. If `n` is non-positive no items would be dropped and a *clone* of the input would be returned, if `n` is bigger then data.length no items would be returned.
|
|
401
|
-
* @param rules - A variadic array of order rules defining the sorting criteria. Each order rule is a projection function that extracts a comparable value from the data. Sorting is based on these extracted values using the native `<` and `>` operators. Earlier rules take precedence over later ones. Use the syntax `[projection, "desc"]` for descending order.
|
|
402
|
-
* @returns a subset of the input array.
|
|
403
|
-
* @signature
|
|
404
|
-
* P.dropFirstBy(data, n, ...rules);
|
|
405
|
-
* @example
|
|
406
|
-
* P.dropFirstBy(['aa', 'aaaa', 'a', 'aaa'], 2, x => x.length); // => ['aaa', 'aaaa']
|
|
407
|
-
* @dataFirst
|
|
408
|
-
* @category Array
|
|
409
|
-
*/
|
|
410
|
-
declare function dropFirstBy<T>(data: ReadonlyArray<T>, n: number, ...rules: Readonly<NonEmptyArray<OrderRule<T>>>): Array<T>;
|
|
411
|
-
/**
|
|
412
|
-
* Drop the first `n` items from `data` based on the provided ordering criteria. This allows you to avoid sorting the array before dropping the items. The complexity of this function is *O(Nlogn)* where `N` is the length of the array.
|
|
413
|
-
*
|
|
414
|
-
* For the opposite operation (to keep `n` elements) see `takeFirstBy`.
|
|
415
|
-
*
|
|
416
|
-
* @params data - the input array
|
|
417
|
-
* @params n - the number of items to drop. If `n` is non-positive no items would be dropped and a *clone* of the input would be returned, if `n` is bigger then data.length no items would be returned.
|
|
418
|
-
* @param rules - A variadic array of order rules defining the sorting criteria. Each order rule is a projection function that extracts a comparable value from the data. Sorting is based on these extracted values using the native `<` and `>` operators. Earlier rules take precedence over later ones. Use the syntax `[projection, "desc"]` for descending order.
|
|
419
|
-
* @returns a subset of the input array.
|
|
420
|
-
* @signature
|
|
421
|
-
* P.dropFirstBy(n, ...rules)(data);
|
|
422
|
-
* @example
|
|
423
|
-
* P.pipe(['aa', 'aaaa', 'a', 'aaa'], P.dropFirstBy(2, x => x.length)); // => ['aaa', 'aaaa']
|
|
424
|
-
* @dataLast
|
|
425
|
-
* @category Array
|
|
426
|
-
*/
|
|
427
|
-
declare function dropFirstBy<T>(n: number, ...rules: Readonly<NonEmptyArray<OrderRule<T>>>): (data: ReadonlyArray<T>) => Array<T>;
|
|
428
|
-
|
|
429
|
-
/**
|
|
430
|
-
* Removes elements from the end of the array until the predicate returns false.
|
|
431
|
-
*
|
|
432
|
-
* The predicate is applied to each element in the array starting from the end and moving towards the beginning, until the predicate returns false. The returned array includes elements from the beginning of the array, up to and including the element that produced false for the predicate.
|
|
433
|
-
*
|
|
434
|
-
* @param data the array
|
|
435
|
-
* @param predicate the predicate
|
|
436
|
-
* @signature
|
|
437
|
-
* P.dropLastWhile(data, predicate)
|
|
438
|
-
* @example
|
|
439
|
-
* P.dropLastWhile([1, 2, 10, 3, 4], x => x < 10) // => [1, 2, 10]
|
|
440
|
-
* @dataFirst
|
|
441
|
-
* @category Array
|
|
442
|
-
*/
|
|
443
|
-
declare function dropLastWhile<T>(data: ReadonlyArray<T>, predicate: (item: T) => boolean): Array<T>;
|
|
444
|
-
/**
|
|
445
|
-
* Removes elements from the end of the array until the predicate returns false.
|
|
446
|
-
*
|
|
447
|
-
* The predicate is applied to each element in the array starting from the end and moving towards the beginning, until the predicate returns false. The returned array includes elements from the beginning of the array, up to and including the element that produced false for the predicate.
|
|
448
|
-
*
|
|
449
|
-
* @param predicate the predicate
|
|
450
|
-
* @signature
|
|
451
|
-
* P.dropLastWhile(predicate)(data)
|
|
452
|
-
* @example
|
|
453
|
-
* P.pipe([1, 2, 10, 3, 4], P.dropLastWhile(x => x < 10)) // => [1, 2, 10]
|
|
454
|
-
* @dataLast
|
|
455
|
-
* @category Array
|
|
456
|
-
*/
|
|
457
|
-
declare function dropLastWhile<T>(predicate: (item: T) => boolean): (data: ReadonlyArray<T>) => Array<T>;
|
|
458
|
-
|
|
459
|
-
/**
|
|
460
|
-
* Removes elements from the beginning of the array until the predicate returns false.
|
|
461
|
-
*
|
|
462
|
-
* The predicate is applied to each element in the array,
|
|
463
|
-
* until the predicate returns false.
|
|
464
|
-
* The returned array includes the rest of the elements,
|
|
465
|
-
* starting with the element that produced false for the predicate.
|
|
466
|
-
*
|
|
467
|
-
* @param data the array
|
|
468
|
-
* @param predicate the predicate
|
|
469
|
-
* @signature
|
|
470
|
-
* P.dropWhile(data, predicate)
|
|
471
|
-
* @example
|
|
472
|
-
* P.dropWhile([1, 2, 10, 3, 4], x => x < 10) // => [10, 3, 4]
|
|
473
|
-
* @dataFirst
|
|
474
|
-
* @category Array
|
|
475
|
-
*/
|
|
476
|
-
declare function dropWhile<T>(data: ReadonlyArray<T>, predicate: (item: T) => boolean): Array<T>;
|
|
477
|
-
/**
|
|
478
|
-
* Removes elements from the beginning of the array until the predicate returns false.
|
|
479
|
-
*
|
|
480
|
-
* The predicate is applied to each element in the array, until the predicate returns false. The returned array includes the rest of the elements, starting with the element that produced false for the predicate.
|
|
481
|
-
*
|
|
482
|
-
* @param predicate the predicate
|
|
483
|
-
* @signature
|
|
484
|
-
* P.dropWhile(predicate)(data)
|
|
485
|
-
* @example
|
|
486
|
-
* P.pipe([1, 2, 10, 3, 4], P.dropWhile(x => x < 10)) // => [10, 3, 4]
|
|
487
|
-
* @dataLast
|
|
488
|
-
* @category Array
|
|
489
|
-
*/
|
|
490
|
-
declare function dropWhile<T>(predicate: (item: T) => boolean): (data: ReadonlyArray<T>) => Array<T>;
|
|
491
|
-
|
|
492
|
-
/**
|
|
493
|
-
* Filter the elements of an array that meet the condition specified in a callback function.
|
|
494
|
-
* @param array The array to filter.
|
|
495
|
-
* @param fn the callback function.
|
|
496
|
-
* @signature
|
|
497
|
-
* P.filter(array, fn)
|
|
498
|
-
* P.filter.indexed(array, fn)
|
|
499
|
-
* @example
|
|
500
|
-
* P.filter([1, 2, 3], x => x % 2 === 1) // => [1, 3]
|
|
501
|
-
* P.filter.indexed([1, 2, 3], (x, i, array) => x % 2 === 1) // => [1, 3]
|
|
502
|
-
* @dataFirst
|
|
503
|
-
* @indexed
|
|
504
|
-
* @pipeable
|
|
505
|
-
* @category Array
|
|
506
|
-
*/
|
|
507
|
-
declare function filter<T, S extends T>(array: ReadonlyArray<T>, fn: (value: T) => value is S): Array<S>;
|
|
508
|
-
declare function filter<T>(array: ReadonlyArray<T>, fn: Pred<T, boolean>): Array<T>;
|
|
509
|
-
/**
|
|
510
|
-
* Filter the elements of an array that meet the condition specified in a callback function.
|
|
511
|
-
* @param fn the callback function.
|
|
512
|
-
* @signature
|
|
513
|
-
* P.filter(fn)(array)
|
|
514
|
-
* P.filter.indexed(fn)(array)
|
|
515
|
-
* @example
|
|
516
|
-
* P.pipe([1, 2, 3], P.filter(x => x % 2 === 1)) // => [1, 3]
|
|
517
|
-
* P.pipe([1, 2, 3], P.filter.indexed((x, i) => x % 2 === 1)) // => [1, 3]
|
|
518
|
-
* @dataLast
|
|
519
|
-
* @indexed
|
|
520
|
-
* @pipeable
|
|
521
|
-
* @category Array
|
|
522
|
-
*/
|
|
523
|
-
declare function filter<T, S extends T>(fn: (input: T) => input is S): (array: ReadonlyArray<T>) => Array<S>;
|
|
524
|
-
declare function filter<T>(fn: Pred<T, boolean>): (array: ReadonlyArray<T>) => Array<T>;
|
|
525
|
-
declare namespace filter {
|
|
526
|
-
function indexed<T, S extends T>(array: ReadonlyArray<T>, fn: (input: T, index: number, array: Array<T>) => input is S): Array<S>;
|
|
527
|
-
function indexed<T>(array: ReadonlyArray<T>, fn: PredIndexed<T, boolean>): Array<T>;
|
|
528
|
-
/**
|
|
529
|
-
* @dataLast
|
|
530
|
-
*/
|
|
531
|
-
function indexed<T, S extends T>(fn: (input: T, index: number, array: Array<T>) => input is S): (array: ReadonlyArray<T>) => Array<S>;
|
|
532
|
-
function indexed<T>(fn: PredIndexed<T, boolean>): (array: ReadonlyArray<T>) => Array<T>;
|
|
533
|
-
const lazy: <T>(fn: PredIndexedOptional<T, boolean>) => (value: T, index?: number | undefined, array?: readonly T[] | undefined) => LazyResult<T>;
|
|
534
|
-
const lazyIndexed: (<T>(fn: PredIndexedOptional<T, boolean>) => (value: T, index?: number | undefined, array?: readonly T[] | undefined) => LazyResult<T>) & {
|
|
535
|
-
readonly indexed: true;
|
|
536
|
-
};
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
/**
|
|
540
|
-
* Returns the index of the first element in the array where predicate is true, and -1 otherwise.
|
|
541
|
-
* @param items the array
|
|
542
|
-
* @param fn the predicate
|
|
543
|
-
* @signature
|
|
544
|
-
* P.findIndex(items, fn)
|
|
545
|
-
* P.findIndex.indexed(items, fn)
|
|
546
|
-
* @example
|
|
547
|
-
* P.findIndex([1, 3, 4, 6], n => n % 2 === 0) // => 2
|
|
548
|
-
* P.findIndex.indexed([1, 3, 4, 6], (n, i) => n % 2 === 0) // => 2
|
|
549
|
-
* @dataFirst
|
|
550
|
-
* @indexed
|
|
551
|
-
* @pipeable
|
|
552
|
-
* @category Array
|
|
553
|
-
*/
|
|
554
|
-
declare function findIndex<T>(items: ReadonlyArray<T>, fn: Pred<T, boolean>): number;
|
|
555
|
-
/**
|
|
556
|
-
* Returns the index of the first element in the array where predicate is true, and -1 otherwise.
|
|
557
|
-
* @param fn the predicate
|
|
558
|
-
* @signature
|
|
559
|
-
* P.findIndex(fn)(items)
|
|
560
|
-
* P.findIndex.indexed(fn)(items)
|
|
561
|
-
* @example
|
|
562
|
-
* P.pipe(
|
|
563
|
-
* [1, 3, 4, 6],
|
|
564
|
-
* P.findIndex(n => n % 2 === 0)
|
|
565
|
-
* ) // => 2
|
|
566
|
-
* P.pipe(
|
|
567
|
-
* [1, 3, 4, 6],
|
|
568
|
-
* P.findIndex.indexed((n, i) => n % 2 === 0)
|
|
569
|
-
* ) // => 2
|
|
570
|
-
* @dataLast
|
|
571
|
-
* @indexed
|
|
572
|
-
* @pipeable
|
|
573
|
-
* @category Array
|
|
574
|
-
*/
|
|
575
|
-
declare function findIndex<T>(fn: Pred<T, boolean>): (items: ReadonlyArray<T>) => number;
|
|
576
|
-
declare namespace findIndex {
|
|
577
|
-
function indexed<T>(array: ReadonlyArray<T>, fn: PredIndexed<T, boolean>): number;
|
|
578
|
-
function indexed<T>(fn: PredIndexed<T, boolean>): (array: ReadonlyArray<T>) => number;
|
|
579
|
-
const lazy: (<T>(fn: PredIndexedOptional<T, boolean>) => (value: T, index?: number | undefined, array?: T[] | undefined) => {
|
|
580
|
-
done: boolean;
|
|
581
|
-
hasNext: boolean;
|
|
582
|
-
next: number;
|
|
583
|
-
} | {
|
|
584
|
-
done: boolean;
|
|
585
|
-
hasNext: boolean;
|
|
586
|
-
next?: never;
|
|
587
|
-
}) & {
|
|
588
|
-
single: true;
|
|
589
|
-
};
|
|
590
|
-
const lazyIndexed: ((fn: PredIndexedOptional<unknown, boolean>) => (value: unknown, index?: number | undefined, array?: unknown[] | undefined) => {
|
|
591
|
-
done: boolean;
|
|
592
|
-
hasNext: boolean;
|
|
593
|
-
next: number;
|
|
594
|
-
} | {
|
|
595
|
-
done: boolean;
|
|
596
|
-
hasNext: boolean;
|
|
597
|
-
next?: never;
|
|
598
|
-
}) & {
|
|
599
|
-
readonly indexed: true;
|
|
600
|
-
} & {
|
|
601
|
-
single: true;
|
|
602
|
-
};
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
/**
|
|
606
|
-
* Returns the index of the last element in the array where predicate is true, and -1 otherwise.
|
|
607
|
-
* @param array the array
|
|
608
|
-
* @param fn the predicate
|
|
609
|
-
* @signature
|
|
610
|
-
* P.findLastIndex(items, fn)
|
|
611
|
-
* P.findLastIndex.indexed(items, fn)
|
|
612
|
-
* @example
|
|
613
|
-
* P.findLastIndex([1, 3, 4, 6], n => n % 2 === 1) // => 1
|
|
614
|
-
* P.findLastIndex.indexed([1, 3, 4, 6], (n, i) => n % 2 === 1) // => 1
|
|
615
|
-
* @dataFirst
|
|
616
|
-
* @indexed
|
|
617
|
-
* @pipeable
|
|
618
|
-
* @category Array
|
|
619
|
-
*/
|
|
620
|
-
declare function findLastIndex<T>(array: ReadonlyArray<T>, fn: Pred<T, boolean>): number;
|
|
621
|
-
/**
|
|
622
|
-
* Returns the index of the last element in the array where predicate is true, and -1 otherwise.
|
|
623
|
-
* @param fn the predicate
|
|
624
|
-
* @signature
|
|
625
|
-
* P.findLastIndex(fn)(items)
|
|
626
|
-
* P.findLastIndex.indexed(fn)(items)
|
|
627
|
-
* @example
|
|
628
|
-
* P.pipe(
|
|
629
|
-
* [1, 3, 4, 6],
|
|
630
|
-
* P.findLastIndex(n => n % 2 === 1)
|
|
631
|
-
* ) // => 1
|
|
632
|
-
* P.pipe(
|
|
633
|
-
* [1, 3, 4, 6],
|
|
634
|
-
* P.findLastIndex.indexed((n, i) => n % 2 === 1)
|
|
635
|
-
* ) // => 1
|
|
636
|
-
* @dataLast
|
|
637
|
-
* @indexed
|
|
638
|
-
* @pipeable
|
|
639
|
-
* @category Array
|
|
640
|
-
*/
|
|
641
|
-
declare function findLastIndex<T>(fn: Pred<T, boolean>): (array: ReadonlyArray<T>) => number;
|
|
642
|
-
declare namespace findLastIndex {
|
|
643
|
-
function indexed<T>(array: ReadonlyArray<T>, fn: PredIndexed<T, boolean>): number;
|
|
644
|
-
function indexed<T>(fn: PredIndexed<T, boolean>): (array: ReadonlyArray<T>) => number;
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
/**
|
|
648
|
-
* Returns the value of the last element in the array where predicate is true, and undefined
|
|
649
|
-
* otherwise.
|
|
650
|
-
* @param array the array
|
|
651
|
-
* @param fn the predicate
|
|
652
|
-
* @signature
|
|
653
|
-
* P.findLast(items, fn)
|
|
654
|
-
* P.findLast.indexed(items, fn)
|
|
655
|
-
* @example
|
|
656
|
-
* P.findLast([1, 3, 4, 6], n => n % 2 === 1) // => 3
|
|
657
|
-
* P.findLast.indexed([1, 3, 4, 6], (n, i) => n % 2 === 1) // => 3
|
|
658
|
-
* @dataFirst
|
|
659
|
-
* @indexed
|
|
660
|
-
* @pipeable
|
|
661
|
-
* @category Array
|
|
662
|
-
*/
|
|
663
|
-
declare function findLast<T>(array: ReadonlyArray<T>, fn: Pred<T, boolean>): T | undefined;
|
|
664
|
-
/**
|
|
665
|
-
* Returns the value of the last element in the array where predicate is true, and undefined
|
|
666
|
-
* otherwise.
|
|
667
|
-
* @param fn the predicate
|
|
668
|
-
* @signature
|
|
669
|
-
* P.findLast(fn)(items)
|
|
670
|
-
* P.findLast.indexed(fn)(items)
|
|
671
|
-
* @example
|
|
672
|
-
* P.pipe(
|
|
673
|
-
* [1, 3, 4, 6],
|
|
674
|
-
* P.findLast(n => n % 2 === 1)
|
|
675
|
-
* ) // => 3
|
|
676
|
-
* P.pipe(
|
|
677
|
-
* [1, 3, 4, 6],
|
|
678
|
-
* P.findLast.indexed((n, i) => n % 2 === 1)
|
|
679
|
-
* ) // => 3
|
|
680
|
-
* @dataLast
|
|
681
|
-
* @indexed
|
|
682
|
-
* @pipeable
|
|
683
|
-
* @category Array
|
|
684
|
-
*/
|
|
685
|
-
declare function findLast<T = never>(fn: Pred<T, boolean>): (array: ReadonlyArray<T>) => T | undefined;
|
|
686
|
-
declare namespace findLast {
|
|
687
|
-
function indexed<T>(array: ReadonlyArray<T>, fn: PredIndexed<T, boolean>): T | undefined;
|
|
688
|
-
function indexed<T>(fn: PredIndexed<T, boolean>): (array: ReadonlyArray<T>) => T | undefined;
|
|
689
|
-
}
|
|
690
|
-
|
|
691
|
-
/**
|
|
692
|
-
* Returns the value of the first element in the array where predicate is true, and undefined otherwise.
|
|
693
|
-
* @param items the array
|
|
694
|
-
* @param fn the predicate
|
|
695
|
-
* @signature
|
|
696
|
-
* P.find(items, fn)
|
|
697
|
-
* P.find.indexed(items, fn)
|
|
698
|
-
* @example
|
|
699
|
-
* P.find([1, 3, 4, 6], n => n % 2 === 0) // => 4
|
|
700
|
-
* P.find.indexed([1, 3, 4, 6], (n, i) => n % 2 === 0) // => 4
|
|
701
|
-
* @dataFirst
|
|
702
|
-
* @indexed
|
|
703
|
-
* @pipeable
|
|
704
|
-
* @category Array
|
|
705
|
-
*/
|
|
706
|
-
declare function find<T>(items: ReadonlyArray<T>, fn: Pred<T, boolean>): T | undefined;
|
|
707
|
-
/**
|
|
708
|
-
* Returns the value of the first element in the array where predicate is true, and undefined otherwise.
|
|
709
|
-
* @param fn the predicate
|
|
710
|
-
* @signature
|
|
711
|
-
* P.find(fn)(items)
|
|
712
|
-
* P.find.indexed(fn)(items)
|
|
713
|
-
* @example
|
|
714
|
-
* P.pipe(
|
|
715
|
-
* [1, 3, 4, 6],
|
|
716
|
-
* P.find(n => n % 2 === 0)
|
|
717
|
-
* ) // => 4
|
|
718
|
-
* P.pipe(
|
|
719
|
-
* [1, 3, 4, 6],
|
|
720
|
-
* P.find.indexed((n, i) => n % 2 === 0)
|
|
721
|
-
* ) // => 4
|
|
722
|
-
* @dataLast
|
|
723
|
-
* @indexed
|
|
724
|
-
* @pipeable
|
|
725
|
-
* @category Array
|
|
726
|
-
*/
|
|
727
|
-
declare function find<T = never>(fn: Pred<T, boolean>): (array: ReadonlyArray<T>) => T | undefined;
|
|
728
|
-
declare namespace find {
|
|
729
|
-
function indexed<T>(array: ReadonlyArray<T>, fn: PredIndexed<T, boolean>): T | undefined;
|
|
730
|
-
function indexed<T>(fn: PredIndexed<T, boolean>): (array: ReadonlyArray<T>) => T | undefined;
|
|
731
|
-
const lazy: (<T>(fn: PredIndexedOptional<T, boolean>) => (value: T, index?: number | undefined, array?: T[] | undefined) => {
|
|
732
|
-
done: boolean;
|
|
733
|
-
hasNext: boolean;
|
|
734
|
-
next: T;
|
|
735
|
-
}) & {
|
|
736
|
-
single: true;
|
|
737
|
-
};
|
|
738
|
-
const lazyIndexed: ((fn: PredIndexedOptional<unknown, boolean>) => (value: unknown, index?: number | undefined, array?: unknown[] | undefined) => {
|
|
739
|
-
done: boolean;
|
|
740
|
-
hasNext: boolean;
|
|
741
|
-
next: unknown;
|
|
742
|
-
}) & {
|
|
743
|
-
readonly indexed: true;
|
|
744
|
-
} & {
|
|
745
|
-
single: true;
|
|
746
|
-
};
|
|
747
|
-
}
|
|
748
|
-
|
|
749
|
-
type FirstOut<T extends IterableContainer> = T extends [] ? undefined : T extends readonly [unknown, ...Array<unknown>] ? T[0] : T extends readonly [...infer Pre, infer Last] ? Last | Pre[0] : T[0] | undefined;
|
|
750
|
-
/**
|
|
751
|
-
* Gets the first element of `array`.
|
|
752
|
-
* Note: In `pipe`, use `first()` form instead of `first`. Otherwise, the inferred type is lost.
|
|
753
|
-
* @param array the array
|
|
754
|
-
* @signature
|
|
755
|
-
* P.first(array)
|
|
756
|
-
* @example
|
|
757
|
-
* P.first([1, 2, 3]) // => 1
|
|
758
|
-
* P.first([]) // => undefined
|
|
759
|
-
* P.pipe(
|
|
760
|
-
* [1, 2, 4, 8, 16],
|
|
761
|
-
* P.filter(x => x > 3),
|
|
762
|
-
* P.first(),
|
|
763
|
-
* x => x + 1
|
|
764
|
-
* ); // => 5
|
|
765
|
-
*
|
|
766
|
-
* @category Array
|
|
767
|
-
* @pipeable
|
|
768
|
-
*/
|
|
769
|
-
declare function first<T extends IterableContainer>(array: Readonly<T>): FirstOut<T>;
|
|
770
|
-
declare function first<T extends IterableContainer>(): (array: Readonly<T>) => FirstOut<T>;
|
|
771
|
-
declare namespace first {
|
|
772
|
-
function lazy<T>(): (value: T) => {
|
|
773
|
-
done: boolean;
|
|
774
|
-
hasNext: boolean;
|
|
775
|
-
next: T;
|
|
776
|
-
};
|
|
777
|
-
namespace lazy {
|
|
778
|
-
const single = true;
|
|
779
|
-
}
|
|
780
|
-
}
|
|
781
|
-
|
|
782
|
-
type FirstBy<T extends IterableContainer> = (T extends readonly [unknown, ...ReadonlyArray<unknown>] ? never : T extends readonly [...ReadonlyArray<unknown>, unknown] ? never : undefined) | T[number];
|
|
783
|
-
/**
|
|
784
|
-
* Find the first element in the array that adheres to the order rules provided. This is a superset of what a typical `maxBy` or `minBy` function would do as it allows defining "tie-breaker" rules when values are equal, and allows comparing items using any logic. This function is equivalent to calling `P.first(P.sortBy(...))` but runs at *O(n)* instead of *O(nlogn)*.
|
|
785
|
-
*
|
|
786
|
-
* Use `nthBy` if you need an element other that the first, or `takeFirstBy` if you more than just the first element.
|
|
787
|
-
*
|
|
788
|
-
* @param data an array of items
|
|
789
|
-
* @param rules - A variadic array of order rules defining the sorting criteria. Each order rule is a projection function that extracts a comparable value from the data. Sorting is based on these extracted values using the native `<` and `>` operators. Earlier rules take precedence over later ones. Use the syntax `[projection, "desc"]` for descending ordeP.
|
|
790
|
-
* @returns the first element by the order criteria, or `undefined` if the array
|
|
791
|
-
* is empty. (The function provides strong typing if the input type assures the
|
|
792
|
-
* array isn't empty).
|
|
793
|
-
* @signature
|
|
794
|
-
* P.firstBy(...rules)(data);
|
|
795
|
-
* @example
|
|
796
|
-
* const max = P.pipe([1,2,3], P.firstBy([P.identity, "desc"])); // => 3;
|
|
797
|
-
* const min = P.pipe([1,2,3], P.firstBy([1,2,3])); // => 1;
|
|
798
|
-
*
|
|
799
|
-
* const data = [{ a: "a" }, { a: "aa" }, { a: "aaa" }] as const;
|
|
800
|
-
* const maxBy = P.pipe(data, P.firstBy([(item) => item.a.length, "desc"])); // => { a: "aaa" };
|
|
801
|
-
* const minBy = P.pipe(data, P.firstBy((item) => item.a.length)); // => { a: "a" };
|
|
802
|
-
*
|
|
803
|
-
* const data = [{type: "cat", size: 1}, {type: "cat", size: 2}, {type: "dog", size: 3}] as const;
|
|
804
|
-
* const multi = P.pipe(data, P.firstBy(P.prop('type'), [P.prop('size'), 'desc'])); // => {type: "cat", size: 2}
|
|
805
|
-
* @dataLast
|
|
806
|
-
* @category Array
|
|
807
|
-
*/
|
|
808
|
-
declare function firstBy<T extends IterableContainer>(...rules: Readonly<NonEmptyArray<OrderRule<T[number]>>>): (data: T) => FirstBy<T>;
|
|
809
|
-
/**
|
|
810
|
-
* Find the first element in the array that adheres to the order rules provided. This is a superset of what a typical `maxBy` or `minBy` function would do as it allows defining "tie-breaker" rules when values are equal, and allows comparing items using any logic. This function is equivalent to calling `P.first(P.sortBy(...))` but runs at *O(n)* instead of *O(nlogn)*.
|
|
811
|
-
*
|
|
812
|
-
* Use `nthBy` if you need an element other that the first, or `takeFirstBy` if you more than just the first element.
|
|
813
|
-
*
|
|
814
|
-
* @param data an array of items
|
|
815
|
-
* @param rules - A variadic array of order rules defining the sorting criteria. Each order rule is a projection function that extracts a comparable value from the data. Sorting is based on these extracted values using the native `<` and `>` operators. Earlier rules take precedence over later ones. Use the syntax `[projection, "desc"]` for descending ordeP.
|
|
816
|
-
* @returns the first element by the order criteria, or `undefined` if the array
|
|
817
|
-
* is empty. (The function provides strong typing if the input type assures the
|
|
818
|
-
* array isn't empty).
|
|
819
|
-
* @signature
|
|
820
|
-
* P.firstBy(data, ...rules);
|
|
821
|
-
* @example
|
|
822
|
-
* const max = P.firstBy([1,2,3], [P.identity, "desc"]); // => 3;
|
|
823
|
-
* const min = P.firstBy([1,2,3], P.identity); // => 1;
|
|
824
|
-
*
|
|
825
|
-
* const data = [{ a: "a" }, { a: "aa" }, { a: "aaa" }] as const;
|
|
826
|
-
* const maxBy = P.firstBy(data, [(item) => item.a.length, "desc"]); // => { a: "aaa" };
|
|
827
|
-
* const minBy = P.firstBy(data, (item) => item.a.length); // => { a: "a" };
|
|
828
|
-
*
|
|
829
|
-
* const data = [{type: "cat", size: 1}, {type: "cat", size: 2}, {type: "dog", size: 3}] as const;
|
|
830
|
-
* const multi = P.firstBy(data, P.prop('type'), [P.prop('size'), 'desc']); // => {type: "cat", size: 2}
|
|
831
|
-
* @dataFirst
|
|
832
|
-
* @category Array
|
|
833
|
-
*/
|
|
834
|
-
declare function firstBy<T extends IterableContainer>(data: T, ...rules: Readonly<NonEmptyArray<OrderRule<T[number]>>>): FirstBy<T>;
|
|
835
|
-
|
|
836
|
-
/**
|
|
837
|
-
* Map each element of an array into an object using a defined callback function and flatten the result.
|
|
838
|
-
* @param array The array to map.
|
|
839
|
-
* @param fn The mapping function, which should return an Array of key-value pairs, similar to Object.fromEntries
|
|
840
|
-
* @returns The new mapped object.
|
|
841
|
-
* @signature
|
|
842
|
-
* P.flatMapToObj(array, fn)
|
|
843
|
-
* P.flatMapToObj.indexed(array, fn)
|
|
844
|
-
* @example
|
|
845
|
-
* P.flatMapToObj([1, 2, 3], (x) =>
|
|
846
|
-
* x % 2 === 1 ? [[String(x), x]] : []
|
|
847
|
-
* ) // => {1: 1, 3: 3}
|
|
848
|
-
* P.flatMapToObj.indexed(['a', 'b'], (x, i) => [
|
|
849
|
-
* [x, i],
|
|
850
|
-
* [x + x, i + i],
|
|
851
|
-
* ]) // => {a: 0, aa: 0, b: 1, bb: 2}
|
|
852
|
-
* @dataFirst
|
|
853
|
-
* @indexed
|
|
854
|
-
* @category Array
|
|
855
|
-
*/
|
|
856
|
-
declare function flatMapToObj<T, K extends keyof any, V>(array: ReadonlyArray<T>, fn: (element: T) => Array<[K, V]>): Record<K, V>;
|
|
857
|
-
/**
|
|
858
|
-
* Map each element of an array into an object using a defined callback function and flatten the result.
|
|
859
|
-
* @param fn The mapping function, which should return an Array of key-value pairs, similar to Object.fromEntries
|
|
860
|
-
* @returns The new mapped object.
|
|
861
|
-
* @signature
|
|
862
|
-
* P.flatMapToObj(fn)(array)
|
|
863
|
-
* P.flatMapToObj(fn)(array)
|
|
864
|
-
* @example
|
|
865
|
-
* P.pipe(
|
|
866
|
-
* [1, 2, 3],
|
|
867
|
-
* P.flatMapToObj(x => (x % 2 === 1 ? [[String(x), x]] : []))
|
|
868
|
-
* ) // => {1: 1, 3: 3}
|
|
869
|
-
* P.pipe(
|
|
870
|
-
* ['a', 'b'],
|
|
871
|
-
* P.flatMapToObj.indexed((x, i) => [
|
|
872
|
-
* [x, i],
|
|
873
|
-
* [x + x, i + i],
|
|
874
|
-
* ])
|
|
875
|
-
* ) // => {a: 0, aa: 0, b: 1, bb: 2}
|
|
876
|
-
* @dataLast
|
|
877
|
-
* @indexed
|
|
878
|
-
* @category Array
|
|
879
|
-
*/
|
|
880
|
-
declare function flatMapToObj<T, K extends keyof any, V>(fn: (element: T) => Array<[K, V]>): (array: ReadonlyArray<T>) => Record<K, V>;
|
|
881
|
-
declare namespace flatMapToObj {
|
|
882
|
-
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>;
|
|
883
|
-
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>;
|
|
884
|
-
}
|
|
885
|
-
|
|
886
|
-
/**
|
|
887
|
-
* Map each element of an array using a defined callback function and flatten the mapped result.
|
|
888
|
-
* @param array The array to map.
|
|
889
|
-
* @param fn The function mapper.
|
|
890
|
-
* @signature
|
|
891
|
-
* P.flatMap(array, fn)
|
|
892
|
-
* @example
|
|
893
|
-
* P.flatMap([1, 2, 3], x => [x, x * 10]) // => [1, 10, 2, 20, 3, 30]
|
|
894
|
-
* @dataFirst
|
|
895
|
-
* @pipeable
|
|
896
|
-
* @category Array
|
|
897
|
-
*/
|
|
898
|
-
declare function flatMap<T, K>(array: ReadonlyArray<T>, fn: (input: T) => K | ReadonlyArray<K>): Array<K>;
|
|
899
|
-
/**
|
|
900
|
-
* Map each element of an array using a defined callback function and flatten the mapped result.
|
|
901
|
-
* @param fn The function mapper.
|
|
902
|
-
* @signature
|
|
903
|
-
* P.flatMap(fn)(array)
|
|
904
|
-
* @example
|
|
905
|
-
* P.pipe([1, 2, 3], P.flatMap(x => [x, x * 10])) // => [1, 10, 2, 20, 3, 30]
|
|
906
|
-
* @dataLast
|
|
907
|
-
* @pipeable
|
|
908
|
-
* @category Array
|
|
909
|
-
*/
|
|
910
|
-
declare function flatMap<T, K>(fn: (input: T) => K | ReadonlyArray<K>): (array: ReadonlyArray<T>) => Array<K>;
|
|
911
|
-
declare namespace flatMap {
|
|
912
|
-
function lazy<T, K>(fn: (input: T) => K | ReadonlyArray<K>): (value: T) => {
|
|
913
|
-
done: boolean;
|
|
914
|
-
hasMany: boolean;
|
|
915
|
-
hasNext: boolean;
|
|
916
|
-
next: K & any[];
|
|
917
|
-
} | {
|
|
918
|
-
done: boolean;
|
|
919
|
-
hasNext: boolean;
|
|
920
|
-
next: K | readonly K[];
|
|
921
|
-
hasMany?: never;
|
|
922
|
-
};
|
|
923
|
-
}
|
|
924
|
-
|
|
925
|
-
type FlattenDeep<T> = T extends ReadonlyArray<infer K> ? FlattenDeep2<K> : T;
|
|
926
|
-
type FlattenDeep2<T> = T extends ReadonlyArray<infer K> ? FlattenDeep3<K> : T;
|
|
927
|
-
type FlattenDeep3<T> = T extends ReadonlyArray<infer K> ? FlattenDeep4<K> : T;
|
|
928
|
-
type FlattenDeep4<T> = T extends ReadonlyArray<infer K> ? K : T;
|
|
929
|
-
/**
|
|
930
|
-
* Recursively flattens `array`.
|
|
931
|
-
* Note: In `pipe`, use `flattenDeep()` form instead of `flattenDeep`. Otherwise, the inferred type is lost.
|
|
932
|
-
* @param items the target array
|
|
933
|
-
* @signature P.flattenDeep(array)
|
|
934
|
-
* @example
|
|
935
|
-
* P.flattenDeep([[1, 2], [[3], [4, 5]]]) // => [1, 2, 3, 4, 5]
|
|
936
|
-
* P.pipe(
|
|
937
|
-
* [[1, 2], [[3], [4, 5]]],
|
|
938
|
-
* P.flattenDeep(),
|
|
939
|
-
* ); // => [1, 2, 3, 4, 5]
|
|
940
|
-
* @category Array
|
|
941
|
-
* @pipeable
|
|
942
|
-
*/
|
|
943
|
-
declare function flattenDeep<T>(items: ReadonlyArray<T>): Array<FlattenDeep<T>>;
|
|
944
|
-
declare function flattenDeep<T>(): (items: ReadonlyArray<T>) => Array<FlattenDeep<T>>;
|
|
945
|
-
declare namespace flattenDeep {
|
|
946
|
-
function lazy(): (value: any) => LazyResult<any>;
|
|
947
|
-
}
|
|
948
|
-
|
|
949
|
-
type Flatten<T> = T extends ReadonlyArray<infer K> ? K : T;
|
|
950
|
-
/**
|
|
951
|
-
* Flattens `array` a single level deep.
|
|
952
|
-
* Note: In `pipe`, use `flatten()` form instead of `flatten`. Otherwise, the inferred type is lost.
|
|
953
|
-
* @param items the target array
|
|
954
|
-
* @signature P.flatten(array)
|
|
955
|
-
* @example
|
|
956
|
-
* P.flatten([[1, 2], [3], [4, 5]]) // => [1, 2, 3, 4, 5]
|
|
957
|
-
* P.pipe(
|
|
958
|
-
* [[1, 2], [3], [4, 5]],
|
|
959
|
-
* P.flatten(),
|
|
960
|
-
* ); // => [1, 2, 3, 4, 5]
|
|
961
|
-
* @category Array
|
|
962
|
-
* @pipeable
|
|
963
|
-
*/
|
|
964
|
-
declare function flatten<T>(items: ReadonlyArray<T>): Array<Flatten<T>>;
|
|
965
|
-
declare function flatten<T>(): (items: ReadonlyArray<T>) => Array<Flatten<T>>;
|
|
966
|
-
declare namespace flatten {
|
|
967
|
-
function lazy<T>(): (next: T) => LazyResult<any>;
|
|
968
|
-
}
|
|
969
|
-
|
|
970
|
-
/**
|
|
971
|
-
* Iterate an array using a defined callback function. The original array is returned instead of `void`.
|
|
972
|
-
* @param array The array.
|
|
973
|
-
* @param fn The callback function.
|
|
974
|
-
* @returns The original array
|
|
975
|
-
* @signature
|
|
976
|
-
* P.forEach(array, fn)
|
|
977
|
-
* P.forEach.indexed(array, fn)
|
|
978
|
-
* @example
|
|
979
|
-
* P.forEach([1, 2, 3], x => {
|
|
980
|
-
* console.log(x)
|
|
981
|
-
* }) // => [1, 2, 3]
|
|
982
|
-
* P.forEach.indexed([1, 2, 3], (x, i) => {
|
|
983
|
-
* console.log(x, i)
|
|
984
|
-
* }) // => [1, 2, 3]
|
|
985
|
-
* @dataFirst
|
|
986
|
-
* @indexed
|
|
987
|
-
* @pipeable
|
|
988
|
-
* @category Array
|
|
989
|
-
*/
|
|
990
|
-
declare function forEach<T>(array: ReadonlyArray<T>, fn: Pred<T, void>): Array<T>;
|
|
991
|
-
/**
|
|
992
|
-
* Iterate an array using a defined callback function. The original array is returned instead of `void`.
|
|
993
|
-
* @param fn the function mapper
|
|
994
|
-
* @signature
|
|
995
|
-
* P.forEach(fn)(array)
|
|
996
|
-
* P.forEach.indexed(fn)(array)
|
|
997
|
-
* @example
|
|
998
|
-
* P.pipe(
|
|
999
|
-
* [1, 2, 3],
|
|
1000
|
-
* P.forEach(x => {
|
|
1001
|
-
* console.log(x)
|
|
1002
|
-
* })
|
|
1003
|
-
* ) // => [1, 2, 3]
|
|
1004
|
-
* P.pipe(
|
|
1005
|
-
* [1, 2, 3],
|
|
1006
|
-
* P.forEach.indexed((x, i) => {
|
|
1007
|
-
* console.log(x, i)
|
|
1008
|
-
* })
|
|
1009
|
-
* ) // => [1, 2, 3]
|
|
1010
|
-
* @dataLast
|
|
1011
|
-
* @indexed
|
|
1012
|
-
* @pipeable
|
|
1013
|
-
* @category Array
|
|
1014
|
-
*/
|
|
1015
|
-
declare function forEach<T>(fn: Pred<T, void>): (array: ReadonlyArray<T>) => Array<T>;
|
|
1016
|
-
declare namespace forEach {
|
|
1017
|
-
function indexed<T>(array: ReadonlyArray<T>, fn: PredIndexed<T, void>): Array<T>;
|
|
1018
|
-
function indexed<T>(fn: PredIndexed<T, void>): (array: ReadonlyArray<T>) => Array<T>;
|
|
1019
|
-
const lazy: <T>(fn: PredIndexedOptional<T, void>) => (value: T, index?: number | undefined, array?: readonly T[] | undefined) => LazyResult<T>;
|
|
1020
|
-
const lazyIndexed: (<T>(fn: PredIndexedOptional<T, void>) => (value: T, index?: number | undefined, array?: readonly T[] | undefined) => LazyResult<T>) & {
|
|
1021
|
-
readonly indexed: true;
|
|
1022
|
-
};
|
|
1023
|
-
}
|
|
1024
|
-
|
|
1025
|
-
interface Strict$7 {
|
|
1026
|
-
<Value, Key extends PropertyKey = PropertyKey>(items: ReadonlyArray<Value>, fn: (item: Value) => Key | undefined): StrictOut$2<Value, Key>;
|
|
1027
|
-
<Value, Key extends PropertyKey = PropertyKey>(fn: (item: Value) => Key | undefined): (items: ReadonlyArray<Value>) => StrictOut$2<Value, Key>;
|
|
1028
|
-
readonly indexed: {
|
|
1029
|
-
<Value, Key extends PropertyKey = PropertyKey>(fn: PredIndexed<Value, Key | undefined>): (items: ReadonlyArray<Value>) => StrictOut$2<Value, Key>;
|
|
1030
|
-
<Value, Key extends PropertyKey = PropertyKey>(items: ReadonlyArray<Value>, fn: PredIndexed<Value, Key | undefined>): StrictOut$2<Value, Key>;
|
|
1031
|
-
};
|
|
1032
|
-
}
|
|
1033
|
-
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>>>;
|
|
1034
|
-
/**
|
|
1035
|
-
* Splits a collection into sets, grouped by the result of running each value through `fn`.
|
|
1036
|
-
* @param items the items to group
|
|
1037
|
-
* @param fn the grouping function. When `undefined` is returned the item would
|
|
1038
|
-
* be skipped and not grouped under any key.
|
|
1039
|
-
* @signature
|
|
1040
|
-
* P.groupBy(array, fn)
|
|
1041
|
-
* P.groupBy.strict(array, fn)
|
|
1042
|
-
* @example
|
|
1043
|
-
* P.groupBy(['one', 'two', 'three'], x => x.length) // => {3: ['one', 'two'], 5: ['three']}
|
|
1044
|
-
* 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'}>>>
|
|
1045
|
-
* P.groupBy([0, 1], x => x % 2 === 0 ? 'even' : undefined) // => {even: [0]}
|
|
1046
|
-
* @dataFirst
|
|
1047
|
-
* @indexed
|
|
1048
|
-
* @strict
|
|
1049
|
-
* @category Array
|
|
1050
|
-
*/
|
|
1051
|
-
declare function groupBy<T>(items: ReadonlyArray<T>, fn: (item: T) => PropertyKey | undefined): Record<PropertyKey, NonEmptyArray<T>>;
|
|
1052
|
-
declare function groupBy<T>(fn: (item: T) => PropertyKey | undefined): (array: ReadonlyArray<T>) => Record<PropertyKey, NonEmptyArray<T>>;
|
|
1053
|
-
declare namespace groupBy {
|
|
1054
|
-
function indexed<T>(array: ReadonlyArray<T>, fn: PredIndexed<T, PropertyKey | undefined>): Record<string, NonEmptyArray<T>>;
|
|
1055
|
-
function indexed<T>(fn: PredIndexed<T, PropertyKey | undefined>): (array: ReadonlyArray<T>) => Record<string, NonEmptyArray<T>>;
|
|
1056
|
-
const strict: Strict$7;
|
|
1057
|
-
}
|
|
1058
|
-
|
|
1059
|
-
type ArrayMinN<T, N extends number> = number extends N ? Array<T> : N extends 0 ? Array<T> : [...ReadonlyTuple<T, N>, ...Array<T>];
|
|
1060
|
-
/**
|
|
1061
|
-
* Checks if the given array has at least the defined number of elements, and
|
|
1062
|
-
* refines the output type accordingly so that those indices are defined when
|
|
1063
|
-
* accessing the array even when using typescript's 'noUncheckedIndexAccess'.
|
|
1064
|
-
*
|
|
1065
|
-
* @param data the input array
|
|
1066
|
-
* @param minimum the minimum number of elements the array must have
|
|
1067
|
-
* @return true if the array's length is *at least* `minimum`.
|
|
1068
|
-
* @signature
|
|
1069
|
-
* P.hasAtLeast(data, minimum)
|
|
1070
|
-
* @example
|
|
1071
|
-
* P.hasAtLeast([], 4); // => false
|
|
1072
|
-
*
|
|
1073
|
-
* const data: number[] = [1,2,3,4];
|
|
1074
|
-
* P.hasAtLeast(data, 1); // => true
|
|
1075
|
-
* data[0]; // 1, with type `number`
|
|
1076
|
-
* @dataFirst
|
|
1077
|
-
* @category Array
|
|
1078
|
-
*/
|
|
1079
|
-
declare function hasAtLeast<T, N extends number>(data: ReadonlyArray<T>, minimum: N): data is ArrayMinN<T, N>;
|
|
1080
|
-
/**
|
|
1081
|
-
* Checks if the given array has at least the defined number of elements, and
|
|
1082
|
-
* refines the output type accordingly so that those indices are defined when
|
|
1083
|
-
* accessing the array even when using typescript's 'noUncheckedIndexAccess'.
|
|
1084
|
-
*
|
|
1085
|
-
* @param data the input array
|
|
1086
|
-
* @param minimum the minimum number of elements the array must have
|
|
1087
|
-
* @return true if the array's length is *at least* `minimum`.
|
|
1088
|
-
* @signature
|
|
1089
|
-
* P.hasAtLeast(minimum)(data)
|
|
1090
|
-
* @example
|
|
1091
|
-
* P.pipe([], P.hasAtLeast(4)); // => false
|
|
1092
|
-
*
|
|
1093
|
-
* const data = [[1,2], [3], [4,5]];
|
|
1094
|
-
* P.pipe(
|
|
1095
|
-
* data,
|
|
1096
|
-
* P.filter(P.hasAtLeast(2)),
|
|
1097
|
-
* P.map(([, second]) => second),
|
|
1098
|
-
* ); // => [2,5], with type `number[]`
|
|
1099
|
-
* @dataLast
|
|
1100
|
-
* @category Array
|
|
1101
|
-
*/
|
|
1102
|
-
declare function hasAtLeast<N extends number>(minimum: N): <T>(data: ReadonlyArray<T>) => data is ArrayMinN<T, N>;
|
|
1103
|
-
|
|
1104
|
-
/**
|
|
1105
|
-
* Converts a list of objects into an object indexing the objects by the given key.
|
|
1106
|
-
* @param array the array
|
|
1107
|
-
* @param fn the indexing function
|
|
1108
|
-
* @signature
|
|
1109
|
-
* P.indexBy(array, fn)
|
|
1110
|
-
* @example
|
|
1111
|
-
* P.indexBy(['one', 'two', 'three'], x => x.length) // => {3: 'two', 5: 'three'}
|
|
1112
|
-
* @dataFirst
|
|
1113
|
-
* @indexed
|
|
1114
|
-
* @category Array
|
|
1115
|
-
*/
|
|
1116
|
-
declare function indexBy<T>(array: ReadonlyArray<T>, fn: (item: T) => any): Record<string, T>;
|
|
1117
|
-
/**
|
|
1118
|
-
* Converts a list of objects into an object indexing the objects by the given key.
|
|
1119
|
-
* @param fn the indexing function
|
|
1120
|
-
* @signature
|
|
1121
|
-
* P.indexBy(fn)(array)
|
|
1122
|
-
* @example
|
|
1123
|
-
* P.pipe(
|
|
1124
|
-
* ['one', 'two', 'three'],
|
|
1125
|
-
* P.indexBy(x => x.length)
|
|
1126
|
-
* ) // => {3: 'two', 5: 'three'}
|
|
1127
|
-
* @dataLast
|
|
1128
|
-
* @indexed
|
|
1129
|
-
* @category Array
|
|
1130
|
-
*/
|
|
1131
|
-
declare function indexBy<T>(fn: (item: T) => any): (array: ReadonlyArray<T>) => Record<string, T>;
|
|
1132
|
-
declare namespace indexBy {
|
|
1133
|
-
function indexed<T>(array: ReadonlyArray<T>, fn: PredIndexed<T, any>): Record<string, T>;
|
|
1134
|
-
function indexed<T>(fn: PredIndexed<T, any>): (array: ReadonlyArray<T>) => Record<string, T>;
|
|
1135
|
-
}
|
|
1136
|
-
|
|
1137
|
-
/**
|
|
1138
|
-
* Returns a list of elements that exist in both array.
|
|
1139
|
-
* @param array the source array
|
|
1140
|
-
* @param other the second array
|
|
1141
|
-
* @signature
|
|
1142
|
-
* P.intersection(array, other)
|
|
1143
|
-
* @example
|
|
1144
|
-
* P.intersection([1, 2, 3], [2, 3, 5]) // => [2, 3]
|
|
1145
|
-
* @dataFirst
|
|
1146
|
-
* @category Array
|
|
1147
|
-
* @pipeable
|
|
1148
|
-
*/
|
|
1149
|
-
declare function intersection<T>(array: ReadonlyArray<T>, other: ReadonlyArray<T>): Array<T>;
|
|
1150
|
-
/**
|
|
1151
|
-
* Returns a list of elements that exist in both array.
|
|
1152
|
-
* @param other the second array
|
|
1153
|
-
* @signature
|
|
1154
|
-
* P.intersection(other)(array)
|
|
1155
|
-
* @example
|
|
1156
|
-
* P.intersection([2, 3, 5])([1, 2, 3]) // => [2, 3]
|
|
1157
|
-
* @dataLast
|
|
1158
|
-
* @category Array
|
|
1159
|
-
* @pipeable
|
|
1160
|
-
*/
|
|
1161
|
-
declare function intersection<T, K>(other: ReadonlyArray<T>): (source: ReadonlyArray<K>) => Array<T>;
|
|
1162
|
-
declare namespace intersection {
|
|
1163
|
-
function lazy<T>(other: Array<T>): (value: T) => LazyResult<T>;
|
|
1164
|
-
}
|
|
1165
|
-
|
|
1166
|
-
type Comparator<TFirst, TSecond> = (a: TFirst, b: TSecond) => boolean;
|
|
1167
|
-
/**
|
|
1168
|
-
* Returns a list of intersecting values based on a custom
|
|
1169
|
-
* comparator function that compares elements of both arrays.
|
|
1170
|
-
* @param array the source array
|
|
1171
|
-
* @param other the second array
|
|
1172
|
-
* @param comparator the custom comparator
|
|
1173
|
-
* @signature
|
|
1174
|
-
* P.intersectionWith(array, other, comparator)
|
|
1175
|
-
* @example
|
|
1176
|
-
* P.intersectionWith(
|
|
1177
|
-
* [
|
|
1178
|
-
* { id: 1, name: 'Ryan' },
|
|
1179
|
-
* { id: 3, name: 'Emma' },
|
|
1180
|
-
* ],
|
|
1181
|
-
* [3, 5],
|
|
1182
|
-
* (a, b) => a.id === b,
|
|
1183
|
-
* ) // => [{ id: 3, name: 'Emma' }]
|
|
1184
|
-
* @dataFirst
|
|
1185
|
-
* @category Array
|
|
1186
|
-
* @pipeable
|
|
1187
|
-
*/
|
|
1188
|
-
declare function intersectionWith<TFirst, TSecond>(array: ReadonlyArray<TFirst>, other: ReadonlyArray<TSecond>, comparator: Comparator<TFirst, TSecond>): Array<TFirst>;
|
|
1189
|
-
/**
|
|
1190
|
-
* Returns a list of intersecting values based on a custom
|
|
1191
|
-
* comparator function that compares elements of both arrays.
|
|
1192
|
-
* @param other the second array
|
|
1193
|
-
* @param comparator the custom comparator
|
|
1194
|
-
* @signature
|
|
1195
|
-
* P.intersectionWith(other, comparator)(array)
|
|
1196
|
-
* @example
|
|
1197
|
-
* P.intersectionWith(
|
|
1198
|
-
* [3, 5],
|
|
1199
|
-
* (a, b) => a.id === b
|
|
1200
|
-
* )([
|
|
1201
|
-
* { id: 1, name: 'Ryan' },
|
|
1202
|
-
* { id: 3, name: 'Emma' },
|
|
1203
|
-
* ]); // => [{ id: 3, name: 'Emma' }]
|
|
1204
|
-
* @dataLast
|
|
1205
|
-
* @category Array
|
|
1206
|
-
* @pipeable
|
|
1207
|
-
*/
|
|
1208
|
-
declare function intersectionWith<TFirst, TSecond>(other: ReadonlyArray<TSecond>,
|
|
1209
|
-
/**
|
|
1210
|
-
* type inference doesn't work properly for the comparator's first parameter
|
|
1211
|
-
* in data last variant
|
|
1212
|
-
*/
|
|
1213
|
-
comparator: Comparator<TFirst, TSecond>): (array: ReadonlyArray<TFirst>) => Array<TFirst>;
|
|
1214
|
-
declare namespace intersectionWith {
|
|
1215
|
-
function lazy<TFirst, TSecond>(other: Array<TSecond>, comparator: Comparator<TFirst, TSecond>): (value: TFirst) => LazyResult<TFirst>;
|
|
1216
|
-
}
|
|
1217
|
-
|
|
1218
|
-
type Joinable = bigint | boolean | null | number | string | undefined;
|
|
1219
|
-
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;
|
|
1220
|
-
type NullishCoalesce<T, Fallback> = T extends Joinable ? T extends null | undefined ? Fallback | NonNullable<T> : T : never;
|
|
1221
|
-
/**
|
|
1222
|
-
* Joins the elements of the array by: casting them to a string and
|
|
1223
|
-
* concatenating them one to the other, with the provided glue string in between
|
|
1224
|
-
* every two elements.
|
|
1225
|
-
*
|
|
1226
|
-
* When called on a tuple and with stricter item types (union of literal values,
|
|
1227
|
-
* the result is strictly typed to the tuples shape and it's item types).
|
|
1228
|
-
*
|
|
1229
|
-
* @param data The array to join
|
|
1230
|
-
* @param glue The string to put in between every two elements
|
|
1231
|
-
* @signature
|
|
1232
|
-
* P.join(data, glue)
|
|
1233
|
-
* @example
|
|
1234
|
-
* P.join([1,2,3], ",") // => "1,2,3" (typed `string`)
|
|
1235
|
-
* P.join(['a','b','c'], "") // => "abc" (typed `string`)
|
|
1236
|
-
* P.join(['hello', 'world'] as const, " ") // => "hello world" (typed `hello world`)
|
|
1237
|
-
* @dataFirst
|
|
1238
|
-
* @category Array
|
|
1239
|
-
*/
|
|
1240
|
-
declare function join<T extends [] | ReadonlyArray<Joinable>, Glue extends string>(data: T, glue: Glue): Joined<T, Glue>;
|
|
1241
|
-
/**
|
|
1242
|
-
* Joins the elements of the array by: casting them to a string and
|
|
1243
|
-
* concatenating them one to the other, with the provided glue string in between
|
|
1244
|
-
* every two elements.
|
|
1245
|
-
*
|
|
1246
|
-
* When called on a tuple and with stricter item types (union of literal values,
|
|
1247
|
-
* the result is strictly typed to the tuples shape and it's item types).
|
|
1248
|
-
*
|
|
1249
|
-
* @param glue The string to put in between every two elements
|
|
1250
|
-
* @signature
|
|
1251
|
-
* P.join(glue)(data)
|
|
1252
|
-
* @example
|
|
1253
|
-
* P.pipe([1,2,3], P.join(",")) // => "1,2,3" (typed `string`)
|
|
1254
|
-
* P.pipe(['a','b','c'], P.join("")) // => "abc" (typed `string`)
|
|
1255
|
-
* P.pipe(['hello', 'world'] as const, P.join(" ")) // => "hello world" (typed `hello world`)
|
|
1256
|
-
* @dataLast
|
|
1257
|
-
* @category Array
|
|
1258
|
-
*/
|
|
1259
|
-
declare function join<T extends [] | ReadonlyArray<Joinable>, Glue extends string>(glue: Glue): (data: T) => Joined<T, Glue>;
|
|
1260
|
-
|
|
1261
|
-
/**
|
|
1262
|
-
* Gets the last element of `array`.
|
|
1263
|
-
* Note: In `pipe`, use `last()` form instead of `last`. Otherwise, the inferred type is lost.
|
|
1264
|
-
* @param array the array
|
|
1265
|
-
* @signature
|
|
1266
|
-
* P.last(array)
|
|
1267
|
-
* @example
|
|
1268
|
-
* P.last([1, 2, 3]) // => 3
|
|
1269
|
-
* P.last([]) // => undefined
|
|
1270
|
-
* P.pipe(
|
|
1271
|
-
* [1, 2, 4, 8, 16],
|
|
1272
|
-
* P.filter(x => x > 3),
|
|
1273
|
-
* P.last(),
|
|
1274
|
-
* x => x + 1
|
|
1275
|
-
* ); // => 17
|
|
1276
|
-
*
|
|
1277
|
-
* @category Array
|
|
1278
|
-
* @pipeable
|
|
1279
|
-
*/
|
|
1280
|
-
declare function last<T>(array: NonEmptyArray<T>): T;
|
|
1281
|
-
declare function last<T>(array: ReadonlyArray<T>): T | undefined;
|
|
1282
|
-
declare function last<T>(): (array: ReadonlyArray<T>) => T | undefined;
|
|
1283
|
-
|
|
1284
|
-
type Enumerable<T> = ArrayLike<T> | Iterable<T>;
|
|
1285
|
-
/**
|
|
1286
|
-
* Counts values of the collection or iterable.
|
|
1287
|
-
* @param items The input data.
|
|
1288
|
-
* @signature
|
|
1289
|
-
* P.length(array)
|
|
1290
|
-
* @example
|
|
1291
|
-
* P.length([1, 2, 3]) // => 3
|
|
1292
|
-
* @category Array
|
|
1293
|
-
*/
|
|
1294
|
-
declare function length<T>(items: Enumerable<T>): number;
|
|
1295
|
-
declare function length<T>(): (items: Enumerable<T>) => number;
|
|
1296
|
-
|
|
1297
|
-
interface Strict$6 {
|
|
1298
|
-
<T extends IterableContainer, K>(items: T, mapper: Pred<T[number], K>): StrictOut$1<T, K>;
|
|
1299
|
-
<T extends IterableContainer, K>(mapper: Pred<T[number], K>): (items: T) => StrictOut$1<T, K>;
|
|
1300
|
-
readonly indexed: {
|
|
1301
|
-
<T extends IterableContainer, K>(items: T, mapper: PredIndexed<T[number], K>): StrictOut$1<T, K>;
|
|
1302
|
-
<T extends IterableContainer, K>(mapper: PredIndexed<T[number], K>): (items: T) => StrictOut$1<T, K>;
|
|
1303
|
-
};
|
|
1304
|
-
}
|
|
1305
|
-
type StrictOut$1<T extends IterableContainer, K> = {
|
|
1306
|
-
-readonly [P in keyof T]: K;
|
|
1307
|
-
};
|
|
1308
|
-
/**
|
|
1309
|
-
* Map each element of an array using a defined callback function. If the input
|
|
1310
|
-
* array is a tuple use the `strict` variant to maintain it's shape.
|
|
1311
|
-
* @param array The array to map.
|
|
1312
|
-
* @param fn The function mapper.
|
|
1313
|
-
* @returns The new mapped array.
|
|
1314
|
-
* @signature
|
|
1315
|
-
* P.map(array, fn)
|
|
1316
|
-
* P.map.indexed(array, fn)
|
|
1317
|
-
* P.map.strict(array, fn)
|
|
1318
|
-
* P.map.strict.indexed(array, fn)
|
|
1319
|
-
* @example
|
|
1320
|
-
* P.map([1, 2, 3], x => x * 2) // => [2, 4, 6], typed number[]
|
|
1321
|
-
* P.map.indexed([0, 0, 0], (x, i) => i) // => [0, 1, 2], typed number[]
|
|
1322
|
-
* P.map.strict([0, 0] as const, x => x + 1) // => [1, 1], typed [number, number]
|
|
1323
|
-
* P.map.strict.indexed([0, 0] as const, (x, i) => x + i) // => [0, 1], typed [number, number]
|
|
1324
|
-
* @dataFirst
|
|
1325
|
-
* @indexed
|
|
1326
|
-
* @pipeable
|
|
1327
|
-
* @strict
|
|
1328
|
-
* @category Array
|
|
1329
|
-
*/
|
|
1330
|
-
declare function map<T, K>(array: ReadonlyArray<T>, fn: Pred<T, K>): Array<K>;
|
|
1331
|
-
/**
|
|
1332
|
-
* Map each value of an object using a defined callback function.
|
|
1333
|
-
* @param fn the function mapper
|
|
1334
|
-
* @signature
|
|
1335
|
-
* P.map(fn)(array)
|
|
1336
|
-
* P.map.indexed(fn)(array)
|
|
1337
|
-
* @example
|
|
1338
|
-
* P.pipe([0, 1, 2], P.map(x => x * 2)) // => [0, 2, 4]
|
|
1339
|
-
* P.pipe([0, 0, 0], P.map.indexed((x, i) => i)) // => [0, 1, 2]
|
|
1340
|
-
* @dataLast
|
|
1341
|
-
* @indexed
|
|
1342
|
-
* @pipeable
|
|
1343
|
-
* @category Array
|
|
1344
|
-
*/
|
|
1345
|
-
declare function map<T, K>(fn: Pred<T, K>): (array: ReadonlyArray<T>) => Array<K>;
|
|
1346
|
-
declare namespace map {
|
|
1347
|
-
function indexed<T, K>(array: ReadonlyArray<T>, fn: PredIndexed<T, K>): Array<K>;
|
|
1348
|
-
function indexed<T, K>(fn: PredIndexed<T, K>): (array: ReadonlyArray<T>) => Array<K>;
|
|
1349
|
-
const lazy: <T, K>(fn: PredIndexedOptional<T, K>) => (value: T, index?: number | undefined, array?: readonly T[] | undefined) => LazyResult<K>;
|
|
1350
|
-
const lazyIndexed: (<T, K>(fn: PredIndexedOptional<T, K>) => (value: T, index?: number | undefined, array?: readonly T[] | undefined) => LazyResult<K>) & {
|
|
1351
|
-
readonly indexed: true;
|
|
1352
|
-
};
|
|
1353
|
-
const strict: Strict$6;
|
|
1354
|
-
}
|
|
1355
|
-
|
|
1356
|
-
/**
|
|
1357
|
-
* Map each element of an array into an object using a defined callback function.
|
|
1358
|
-
* @param array The array to map.
|
|
1359
|
-
* @param fn The mapping function, which should return a tuple of [key, value], similar to Object.fromEntries
|
|
1360
|
-
* @returns The new mapped object.
|
|
1361
|
-
* @signature
|
|
1362
|
-
* P.mapToObj(array, fn)
|
|
1363
|
-
* P.mapToObj.indexed(array, fn)
|
|
1364
|
-
* @example
|
|
1365
|
-
* P.mapToObj([1, 2, 3], x => [String(x), x * 2]) // => {1: 2, 2: 4, 3: 6}
|
|
1366
|
-
* P.mapToObj.indexed([0, 0, 0], (x, i) => [i, i]) // => {0: 0, 1: 1, 2: 2}
|
|
1367
|
-
* @dataFirst
|
|
1368
|
-
* @indexed
|
|
1369
|
-
* @category Array
|
|
1370
|
-
*/
|
|
1371
|
-
declare function mapToObj<T, K extends PropertyKey, V>(array: ReadonlyArray<T>, fn: (element: T) => [K, V]): Record<K, V>;
|
|
1372
|
-
/**
|
|
1373
|
-
* Map each element of an array into an object using a defined callback function.
|
|
1374
|
-
* @param fn The mapping function, which should return a tuple of [key, value], similar to Object.fromEntries
|
|
1375
|
-
* @returns The new mapped object.
|
|
1376
|
-
* @signature
|
|
1377
|
-
* P.mapToObj(fn)(array)
|
|
1378
|
-
* P.mapToObj.indexed(fn)(array)
|
|
1379
|
-
* @example
|
|
1380
|
-
* P.pipe(
|
|
1381
|
-
* [1, 2, 3],
|
|
1382
|
-
* P.mapToObj(x => [String(x), x * 2])
|
|
1383
|
-
* ) // => {1: 2, 2: 4, 3: 6}
|
|
1384
|
-
* P.pipe(
|
|
1385
|
-
* [0, 0, 0],
|
|
1386
|
-
* P.mapToObj.indexed((x, i) => [i, i])
|
|
1387
|
-
* ) // => {0: 0, 1: 1, 2: 2}
|
|
1388
|
-
* @dataLast
|
|
1389
|
-
* @indexed
|
|
1390
|
-
* @category Array
|
|
1391
|
-
*/
|
|
1392
|
-
declare function mapToObj<T, K extends PropertyKey, V>(fn: (element: T) => [K, V]): (array: ReadonlyArray<T>) => Record<K, V>;
|
|
1393
|
-
declare namespace mapToObj {
|
|
1394
|
-
function indexed<T, K extends PropertyKey, V>(array: ReadonlyArray<T>, fn: (element: T, index: number, array: ReadonlyArray<T>) => [K, V]): Record<K, V>;
|
|
1395
|
-
function indexed<T, K extends PropertyKey, V>(fn: (element: T, index: number, array: ReadonlyArray<T>) => [K, V]): (array: ReadonlyArray<T>) => Record<K, V>;
|
|
1396
|
-
}
|
|
1397
|
-
|
|
1398
|
-
/**
|
|
1399
|
-
* Returns the max element using the provided predicate.
|
|
1400
|
-
* @param fn the predicate
|
|
1401
|
-
* @signature
|
|
1402
|
-
* P.maxBy(fn)(array)
|
|
1403
|
-
* P.maxBy.indexed(fn)(array)
|
|
1404
|
-
* @example
|
|
1405
|
-
* P.pipe(
|
|
1406
|
-
* [{a: 5}, {a: 1}, {a: 3}],
|
|
1407
|
-
* P.maxBy(x => x.a)
|
|
1408
|
-
* ) // { a: 5 }
|
|
1409
|
-
* @dataLast
|
|
1410
|
-
* @indexed
|
|
1411
|
-
* @category Array
|
|
1412
|
-
*/
|
|
1413
|
-
declare function maxBy<T>(fn: (item: T) => number): (items: ReadonlyArray<T>) => T | undefined;
|
|
1414
|
-
/**
|
|
1415
|
-
* Returns the max element using the provided predicate.
|
|
1416
|
-
* @param items the array
|
|
1417
|
-
* @param fn the predicate
|
|
1418
|
-
* @signature
|
|
1419
|
-
* P.maxBy(array, fn)
|
|
1420
|
-
* P.maxBy.indexed(array, fn)
|
|
1421
|
-
* @example
|
|
1422
|
-
* P.maxBy(
|
|
1423
|
-
* [{a: 5}, {a: 1}, {a: 3}],
|
|
1424
|
-
* x => x.a
|
|
1425
|
-
* ) // { a: 5 }
|
|
1426
|
-
* @dataFirst
|
|
1427
|
-
* @indexed
|
|
1428
|
-
* @category Array
|
|
1429
|
-
*/
|
|
1430
|
-
declare function maxBy<T>(items: ReadonlyArray<T>, fn: (item: T) => number): T | undefined;
|
|
1431
|
-
declare namespace maxBy {
|
|
1432
|
-
function indexed<T>(array: ReadonlyArray<T>, fn: PredIndexed<T, number>): T | undefined;
|
|
1433
|
-
function indexed<T>(fn: PredIndexed<T, number>): (array: ReadonlyArray<T>) => T | undefined;
|
|
1434
|
-
}
|
|
1435
|
-
|
|
1436
|
-
/**
|
|
1437
|
-
* Returns the mean of the elements of an array using the provided predicate.
|
|
1438
|
-
* @param fn predicate function
|
|
1439
|
-
* @signature
|
|
1440
|
-
* P.meanBy(fn)(array)
|
|
1441
|
-
* P.meanBy.indexed(fn)(array)
|
|
1442
|
-
* @example
|
|
1443
|
-
* P.pipe(
|
|
1444
|
-
* [{a: 5}, {a: 1}, {a: 3}],
|
|
1445
|
-
* P.meanBy(x => x.a)
|
|
1446
|
-
* ) // 3
|
|
1447
|
-
* @dataLast
|
|
1448
|
-
* @indexed
|
|
1449
|
-
* @category Array
|
|
1450
|
-
*/
|
|
1451
|
-
declare function meanBy<T>(fn: (item: T) => number): (items: ReadonlyArray<T>) => number;
|
|
1452
|
-
/**
|
|
1453
|
-
* Returns the mean of the elements of an array using the provided predicate.
|
|
1454
|
-
* @param items the array
|
|
1455
|
-
* @param fn predicate function
|
|
1456
|
-
* @signature
|
|
1457
|
-
* P.meanBy(array, fn)
|
|
1458
|
-
* P.meanBy.indexed(array, fn)
|
|
1459
|
-
* @example
|
|
1460
|
-
* P.meanBy(
|
|
1461
|
-
* [{a: 5}, {a: 1}, {a: 3}],
|
|
1462
|
-
* x => x.a
|
|
1463
|
-
* ) // 3
|
|
1464
|
-
* @dataFirst
|
|
1465
|
-
* @indexed
|
|
1466
|
-
* @category Array
|
|
1467
|
-
*/
|
|
1468
|
-
declare function meanBy<T>(items: ReadonlyArray<T>, fn: (item: T) => number): number;
|
|
1469
|
-
declare namespace meanBy {
|
|
1470
|
-
function indexed<T>(array: ReadonlyArray<T>, fn: PredIndexed<T, number>): number;
|
|
1471
|
-
function indexed<T>(fn: PredIndexed<T, number>): (array: ReadonlyArray<T>) => number;
|
|
1472
|
-
}
|
|
1473
|
-
|
|
1474
|
-
/**
|
|
1475
|
-
* Merges a list of objects into a single object.
|
|
1476
|
-
* @param array the array of objects
|
|
1477
|
-
* @signature
|
|
1478
|
-
* P.mergeAll(objects)
|
|
1479
|
-
* @example
|
|
1480
|
-
* P.mergeAll([{ a: 1, b: 1 }, { b: 2, c: 3 }, { d: 10 }]) // => { a: 1, b: 2, c: 3, d: 10 }
|
|
1481
|
-
* @category Array
|
|
1482
|
-
*/
|
|
1483
|
-
declare function mergeAll<A>(array: readonly [A]): A;
|
|
1484
|
-
declare function mergeAll<A, B>(array: readonly [A, B]): A & B;
|
|
1485
|
-
declare function mergeAll<A, B, C>(array: readonly [A, B, C]): A & B & C;
|
|
1486
|
-
declare function mergeAll<A, B, C, D>(array: readonly [A, B, C, D]): A & B & C & D;
|
|
1487
|
-
declare function mergeAll<A, B, C, D, E>(array: [A, B, C, D, E]): A & B & C & D & E;
|
|
1488
|
-
declare function mergeAll(array: ReadonlyArray<object>): object;
|
|
1489
|
-
|
|
1490
|
-
/**
|
|
1491
|
-
* Returns the min element using the provided predicate.
|
|
1492
|
-
* @param fn the predicate
|
|
1493
|
-
* @signature
|
|
1494
|
-
* P.minBy(fn)(array)
|
|
1495
|
-
* P.minBy.indexed(fn)(array)
|
|
1496
|
-
* @example
|
|
1497
|
-
* P.pipe(
|
|
1498
|
-
* [{a: 5}, {a: 1}, {a: 3}],
|
|
1499
|
-
* P.minBy(x => x.a)
|
|
1500
|
-
* ) // { a: 1 }
|
|
1501
|
-
* @dataLast
|
|
1502
|
-
* @indexed
|
|
1503
|
-
* @category Array
|
|
1504
|
-
*/
|
|
1505
|
-
declare function minBy<T>(fn: (item: T) => number): (items: ReadonlyArray<T>) => T | undefined;
|
|
1506
|
-
/**
|
|
1507
|
-
* Returns the min element using the provided predicate.
|
|
1508
|
-
* @param items the array
|
|
1509
|
-
* @param fn the predicate
|
|
1510
|
-
* @signature
|
|
1511
|
-
* P.minBy(array, fn)
|
|
1512
|
-
* P.minBy.indexed(array, fn)
|
|
1513
|
-
* @example
|
|
1514
|
-
* P.minBy(
|
|
1515
|
-
* [{a: 5}, {a: 1}, {a: 3}],
|
|
1516
|
-
* x => x.a
|
|
1517
|
-
* ) // { a: 1 }
|
|
1518
|
-
* @dataFirst
|
|
1519
|
-
* @indexed
|
|
1520
|
-
* @category Array
|
|
1521
|
-
*/
|
|
1522
|
-
declare function minBy<T>(items: ReadonlyArray<T>, fn: (item: T) => number): T | undefined;
|
|
1523
|
-
declare namespace minBy {
|
|
1524
|
-
function indexed<T>(array: ReadonlyArray<T>, fn: PredIndexed<T, number>): T | undefined;
|
|
1525
|
-
function indexed<T>(fn: PredIndexed<T, number>): (array: ReadonlyArray<T>) => T | undefined;
|
|
1526
|
-
}
|
|
1527
|
-
|
|
1528
|
-
/**
|
|
1529
|
-
* Retrieves the element that would be at the given index if the array were sorted according to specified rules.
|
|
1530
|
-
* This function uses the *QuickSelect* algorithm running at an average complexity of *O(n)*.
|
|
1531
|
-
* Semantically it is equivalent to `sortBy(data, ...rules).at(index)` which would run at *O(nlogn)*.
|
|
1532
|
-
*
|
|
1533
|
-
* See also `firstBy` which provides an even more efficient algorithm and a stricter return type,
|
|
1534
|
-
* but only for `index === 0`.
|
|
1535
|
-
* See `takeFirstBy` to get all the elements up to and including `index`.
|
|
1536
|
-
*
|
|
1537
|
-
* @param data - The input array.
|
|
1538
|
-
* @param index - The zero-based index for selecting the element in the sorted order. Negative indices count backwards from the end.
|
|
1539
|
-
* @param rules - A variadic array of order rules defining the sorting criteria. Each order rule is a projection function that extracts a comparable value from the data. Sorting is based on these extracted values using the native `<` and `>` operators. Earlier rules take precedence over later ones. Use the syntax `[projection, "desc"]` for descending order.
|
|
1540
|
-
* @returns The element at the specified index in the sorted order, or `undefined` if the index is out of bounds.
|
|
1541
|
-
* @signature
|
|
1542
|
-
* P.nthBy(data, index, ...rules);
|
|
1543
|
-
* @example
|
|
1544
|
-
* P.nthBy([2,1,4,5,3,], 2, identity); // => 3
|
|
1545
|
-
* @dataFirst
|
|
1546
|
-
* @category Array
|
|
1547
|
-
*/
|
|
1548
|
-
declare function nthBy<T extends IterableContainer>(data: T, index: number, ...rules: Readonly<NonEmptyArray<OrderRule<T[number]>>>): T[number] | undefined;
|
|
1549
|
-
/**
|
|
1550
|
-
* Retrieves the element that would be at the given index if the array were sorted according to specified rules.
|
|
1551
|
-
* This function uses the *QuickSelect* algorithm running at an average complexity of *O(n)*.
|
|
1552
|
-
* Semantically it is equivalent to `sortBy(data, ...rules)[index]` which would run at *O(nlogn)*.
|
|
1553
|
-
*
|
|
1554
|
-
* See also `firstBy` which provides an even more efficient algorithm and a stricter return type,
|
|
1555
|
-
* but only for `index === 0`.
|
|
1556
|
-
* See `takeFirstBy` to get all the elements up to and including `index`.
|
|
1557
|
-
*
|
|
1558
|
-
* @param data - The input array.
|
|
1559
|
-
* @param index - The zero-based index for selecting the element in the sorted order. Negative indices count backwards from the end.
|
|
1560
|
-
* @param rules - A variadic array of order rules defining the sorting criteria. Each order rule is a projection function that extracts a comparable value from the data. Sorting is based on these extracted values using the native `<` and `>` operators. Earlier rules take precedence over later ones. Use the syntax `[projection, "desc"]` for descending order.
|
|
1561
|
-
* @returns The element at the specified index in the sorted order, or `undefined` if the index is out of bounds.
|
|
1562
|
-
* @signature
|
|
1563
|
-
* P.nthBy(index, ...rules)(data);
|
|
1564
|
-
* @example
|
|
1565
|
-
* P.pipe([2,1,4,5,3,], P.nthBy(2, identity)); // => 3
|
|
1566
|
-
* @dataLast
|
|
1567
|
-
* @category Array
|
|
1568
|
-
*/
|
|
1569
|
-
declare function nthBy<T extends IterableContainer>(index: number, ...rules: Readonly<NonEmptyArray<OrderRule<T[number]>>>): (data: T) => T[number] | undefined;
|
|
1570
|
-
|
|
1571
|
-
type Only<T extends IterableContainer> = T extends readonly [...Array<unknown>, unknown, unknown] | readonly [] | readonly [unknown, ...Array<unknown>, unknown] | readonly [unknown, unknown, ...Array<unknown>] ? undefined : T extends readonly [unknown] ? T[number] : T[number] | undefined;
|
|
1572
|
-
/**
|
|
1573
|
-
* Returns the first and only element of `array`, or undefined otherwise.
|
|
1574
|
-
* Note: In `pipe`, use `only()` form instead of `only`. Otherwise, the
|
|
1575
|
-
* inferred type is lost.
|
|
1576
|
-
* @param array the target array
|
|
1577
|
-
* @signature
|
|
1578
|
-
* P.only(array)
|
|
1579
|
-
* @example
|
|
1580
|
-
* P.only([]) // => undefined
|
|
1581
|
-
* P.only([1]) // => 1
|
|
1582
|
-
* P.only([1, 2]) // => undefined
|
|
1583
|
-
* @pipeable
|
|
1584
|
-
* @category Array
|
|
1585
|
-
* @dataFirst
|
|
1586
|
-
*/
|
|
1587
|
-
declare function only<T extends IterableContainer>(array: Readonly<T>): Only<T>;
|
|
1588
|
-
/**
|
|
1589
|
-
* Returns the first and only element of `array`, or undefined otherwise.
|
|
1590
|
-
* Note: In `pipe`, use `only()` form instead of `only`. Otherwise, the
|
|
1591
|
-
* inferred type is lost.
|
|
1592
|
-
* @param array the target array
|
|
1593
|
-
* @signature
|
|
1594
|
-
* P.only(array)
|
|
1595
|
-
* @example
|
|
1596
|
-
* P.only([]) // => undefined
|
|
1597
|
-
* P.only([1]) // => 1
|
|
1598
|
-
* P.only([1, 2]) // => undefined
|
|
1599
|
-
* @pipeable
|
|
1600
|
-
* @category Array
|
|
1601
|
-
* @dataLast
|
|
1602
|
-
*/
|
|
1603
|
-
declare function only<T extends IterableContainer>(): (array: Readonly<T>) => Only<T>;
|
|
1604
|
-
|
|
1605
|
-
/**
|
|
1606
|
-
* Splits a collection into two groups, the first of which contains elements the `predicate` type guard passes, and the second one containing the rest.
|
|
1607
|
-
* @param items the items to split
|
|
1608
|
-
* @param predicate a type guard function to invoke on every item
|
|
1609
|
-
* @returns the array of grouped elements.
|
|
1610
|
-
* @signature
|
|
1611
|
-
* P.partition(array, fn)
|
|
1612
|
-
* @example
|
|
1613
|
-
* P.partition(['one', 'two', 'forty two'], x => x.length === 3) // => [['one', 'two'], ['forty two']]
|
|
1614
|
-
* @dataFirst
|
|
1615
|
-
* @indexed
|
|
1616
|
-
* @category Array
|
|
1617
|
-
*/
|
|
1618
|
-
declare function partition<T, S extends T>(items: ReadonlyArray<T>, predicate: (item: T) => item is S): [Array<S>, Array<Exclude<T, S>>];
|
|
1619
|
-
/**
|
|
1620
|
-
* Splits a collection into two groups, the first of which contains elements the `predicate` function matches, and the second one containing the rest.
|
|
1621
|
-
* @param items the items to split
|
|
1622
|
-
* @param predicate the function invoked per iteration
|
|
1623
|
-
* @returns the array of grouped elements.
|
|
1624
|
-
* @signature
|
|
1625
|
-
* P.partition(array, fn)
|
|
1626
|
-
* @example
|
|
1627
|
-
* P.partition(['one', 'two', 'forty two'], x => x.length === 3) // => [['one', 'two'], ['forty two']]
|
|
1628
|
-
* @dataFirst
|
|
1629
|
-
* @indexed
|
|
1630
|
-
* @category Array
|
|
1631
|
-
*/
|
|
1632
|
-
declare function partition<T>(items: ReadonlyArray<T>, predicate: (item: T) => boolean): [Array<T>, Array<T>];
|
|
1633
|
-
/**
|
|
1634
|
-
* Splits a collection into two groups, the first of which contains elements the `predicate` type guard passes, and the second one containing the rest.
|
|
1635
|
-
* @param predicate the grouping function
|
|
1636
|
-
* @returns the array of grouped elements.
|
|
1637
|
-
* @signature
|
|
1638
|
-
* P.partition(fn)(array)
|
|
1639
|
-
* @example
|
|
1640
|
-
* P.pipe(['one', 'two', 'forty two'], P.partition(x => x.length === 3)) // => [['one', 'two'], ['forty two']]
|
|
1641
|
-
* @dataLast
|
|
1642
|
-
* @indexed
|
|
1643
|
-
* @category Array
|
|
1644
|
-
*/
|
|
1645
|
-
declare function partition<T, S extends T>(predicate: (item: T) => item is S): (array: ReadonlyArray<T>) => [Array<S>, Array<Exclude<T, S>>];
|
|
1646
|
-
/**
|
|
1647
|
-
* Splits a collection into two groups, the first of which contains elements the `predicate` function matches, and the second one containing the rest.
|
|
1648
|
-
* @param predicate the grouping function
|
|
1649
|
-
* @returns the array of grouped elements.
|
|
1650
|
-
* @signature
|
|
1651
|
-
* P.partition(fn)(array)
|
|
1652
|
-
* @example
|
|
1653
|
-
* P.pipe(['one', 'two', 'forty two'], P.partition(x => x.length === 3)) // => [['one', 'two'], ['forty two']]
|
|
1654
|
-
* @dataLast
|
|
1655
|
-
* @indexed
|
|
1656
|
-
* @category Array
|
|
1657
|
-
*/
|
|
1658
|
-
declare function partition<T>(predicate: (item: T) => boolean): (array: ReadonlyArray<T>) => [Array<T>, Array<T>];
|
|
1659
|
-
declare namespace partition {
|
|
1660
|
-
function indexed<T>(array: ReadonlyArray<T>, predicate: PredIndexed<T, boolean>): [Array<T>, Array<T>];
|
|
1661
|
-
function indexed<T>(predicate: PredIndexed<T, boolean>): (array: ReadonlyArray<T>) => [Array<T>, Array<T>];
|
|
1662
|
-
}
|
|
1663
|
-
|
|
1664
|
-
/**
|
|
1665
|
-
* Returns a list of numbers from `start` (inclusive) to `end` (exclusive).
|
|
1666
|
-
* @param start the start number
|
|
1667
|
-
* @param end the end number
|
|
1668
|
-
* @signature range(start, end)
|
|
1669
|
-
* @example
|
|
1670
|
-
* P.range(1, 5) // => [1, 2, 3, 4]
|
|
1671
|
-
* @dataFirst
|
|
1672
|
-
* @category Array
|
|
1673
|
-
*/
|
|
1674
|
-
declare function range(start: number, end: number): Array<number>;
|
|
1675
|
-
/**
|
|
1676
|
-
* Returns a list of numbers from `start` (inclusive) to `end` (exclusive).
|
|
1677
|
-
* @param end the end number
|
|
1678
|
-
* @signature range(end)(start)
|
|
1679
|
-
* @example
|
|
1680
|
-
* P.range(5)(1) // => [1, 2, 3, 4]
|
|
1681
|
-
* @dataFirst
|
|
1682
|
-
* @category Array
|
|
1683
|
-
*/
|
|
1684
|
-
declare function range(end: number): (start: number) => Array<number>;
|
|
1685
|
-
|
|
1686
|
-
/**
|
|
1687
|
-
* Calculates the rank of an item in an array based on `rules`. The rank is the position where the item would appear in the sorted array. This function provides an efficient way to determine the rank in *O(n)* time, compared to *O(nlogn)* for the equivalent `sortedIndex(sortBy(data, ...rules), item)`.
|
|
1688
|
-
*
|
|
1689
|
-
* @param data - The input array.
|
|
1690
|
-
* @param item - The item whose rank is to be determined.
|
|
1691
|
-
* @param rules - A variadic array of order rules defining the sorting criteria. Each order rule is a projection function that extracts a comparable value from the data. Sorting is based on these extracted values using the native `<` and `>` operators. Earlier rules take precedence over later ones. Use the syntax `[projection, "desc"]` for descending order.
|
|
1692
|
-
* @returns - The rank of the item in the sorted array in the range [0..data.length]
|
|
1693
|
-
* @signature
|
|
1694
|
-
* P.rankBy(data, item, ...rules)
|
|
1695
|
-
* @example
|
|
1696
|
-
* const DATA = [{ a: 5 }, { a: 1 }, { a: 3 }] as const;
|
|
1697
|
-
* P.rankBy(DATA, 0, P.prop('a')) // => 0
|
|
1698
|
-
* P.rankBy(DATA, 1, P.prop('a')) // => 1
|
|
1699
|
-
* P.rankBy(DATA, 2, P.prop('a')) // => 1
|
|
1700
|
-
* P.rankBy(DATA, 3, P.prop('a')) // => 2
|
|
1701
|
-
* @dataFirst
|
|
1702
|
-
* @category Array
|
|
1703
|
-
*/
|
|
1704
|
-
declare function rankBy<T>(data: ReadonlyArray<T>, item: T, ...rules: Readonly<NonEmptyArray<OrderRule<T>>>): number;
|
|
1705
|
-
/**
|
|
1706
|
-
* Calculates the rank of an item in an array based on `rules`. The rank is the position where the item would appear in the sorted array. This function provides an efficient way to determine the rank in *O(n)* time, compared to *O(nlogn)* for the equivalent `sortedIndex(sortBy(data, ...rules), item)`.
|
|
1707
|
-
*
|
|
1708
|
-
* @param data - The input array.
|
|
1709
|
-
* @param item - The item whose rank is to be determined.
|
|
1710
|
-
* @param rules - A variadic array of order rules defining the sorting criteria. Each order rule is a projection function that extracts a comparable value from the data. Sorting is based on these extracted values using the native `<` and `>` operators. Earlier rules take precedence over later ones. Use the syntax `[projection, "desc"]` for descending order.
|
|
1711
|
-
* @returns - The rank of the item in the sorted array in the range [0..data.length]
|
|
1712
|
-
* @signature
|
|
1713
|
-
* P.rankBy(item, ...rules)(data)
|
|
1714
|
-
* @example
|
|
1715
|
-
* const DATA = [{ a: 5 }, { a: 1 }, { a: 3 }] as const;
|
|
1716
|
-
* P.pipe(DATA, P.rankBy(0, P.prop('a'))) // => 0
|
|
1717
|
-
* P.pipe(DATA, P.rankBy(1, P.prop('a'))) // => 1
|
|
1718
|
-
* P.pipe(DATA, P.rankBy(2, P.prop('a'))) // => 1
|
|
1719
|
-
* P.pipe(DATA, P.rankBy(3, P.prop('a'))) // => 2
|
|
1720
|
-
* @dataLast
|
|
1721
|
-
* @category Array
|
|
1722
|
-
*/
|
|
1723
|
-
declare function rankBy<T>(item: T, ...rules: Readonly<NonEmptyArray<OrderRule<T>>>): (data: ReadonlyArray<T>) => number;
|
|
1724
|
-
|
|
1725
|
-
/**
|
|
1726
|
-
* 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.
|
|
1727
|
-
* @param items the array to reduce
|
|
1728
|
-
* @param fn the callback function
|
|
1729
|
-
* @param initialValue the initial value to use as an accumulator value in the callback function
|
|
1730
|
-
* @signature
|
|
1731
|
-
* P.reduce(items, fn, initialValue)
|
|
1732
|
-
* P.reduce.indexed(items, fn, initialValue)
|
|
1733
|
-
* @example
|
|
1734
|
-
* P.reduce([1, 2, 3, 4, 5], (acc, x) => acc + x, 100) // => 115
|
|
1735
|
-
* P.reduce.indexed([1, 2, 3, 4, 5], (acc, x, i, array) => acc + x, 100) // => 115
|
|
1736
|
-
* @dataFirst
|
|
1737
|
-
* @indexed
|
|
1738
|
-
* @category Array
|
|
1739
|
-
*/
|
|
1740
|
-
declare function reduce<T, K>(items: ReadonlyArray<T>, fn: (acc: K, item: T) => K, initialValue: K): K;
|
|
1741
|
-
/**
|
|
1742
|
-
* 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.
|
|
1743
|
-
* @param fn the callback function
|
|
1744
|
-
* @param initialValue the initial value to use as an accumulator value in the callback function
|
|
1745
|
-
* @signature
|
|
1746
|
-
* P.reduce(fn, initialValue)(array)
|
|
1747
|
-
* @example
|
|
1748
|
-
* P.pipe([1, 2, 3, 4, 5], P.reduce((acc, x) => acc + x, 100)) // => 115
|
|
1749
|
-
* P.pipe([1, 2, 3, 4, 5], P.reduce.indexed((acc, x, i, array) => acc + x, 100)) // => 115
|
|
1750
|
-
* @dataLast
|
|
1751
|
-
* @indexed
|
|
1752
|
-
* @category Array
|
|
1753
|
-
*/
|
|
1754
|
-
declare function reduce<T, K>(fn: (acc: K, item: T) => K, initialValue: K): (items: ReadonlyArray<T>) => K;
|
|
1755
|
-
declare namespace reduce {
|
|
1756
|
-
function indexed<T, K>(array: ReadonlyArray<T>, fn: (acc: K, item: T, index: number, items: Array<T>) => K, initialValue: K): K;
|
|
1757
|
-
function indexed<T, K>(fn: (acc: K, item: T, index: number, items: Array<T>) => K, initialValue: K): (array: ReadonlyArray<T>) => K;
|
|
1758
|
-
}
|
|
1759
|
-
|
|
1760
|
-
/**
|
|
1761
|
-
* Reject the elements of an array that meet the condition specified in a callback function.
|
|
1762
|
-
* @param items The array to reject.
|
|
1763
|
-
* @param fn the callback function.
|
|
1764
|
-
* @signature
|
|
1765
|
-
* P.reject(array, fn)
|
|
1766
|
-
* P.reject.indexed(array, fn)
|
|
1767
|
-
* @example
|
|
1768
|
-
* P.reject([1, 2, 3], x => x % 2 === 0) // => [1, 3]
|
|
1769
|
-
* P.reject.indexed([1, 2, 3], (x, i, array) => x % 2 === 0) // => [1, 3]
|
|
1770
|
-
* @dataFirst
|
|
1771
|
-
* @indexed
|
|
1772
|
-
* @pipeable
|
|
1773
|
-
* @category Array
|
|
1774
|
-
*/
|
|
1775
|
-
declare function reject<T>(items: ReadonlyArray<T>, fn: Pred<T, boolean>): Array<T>;
|
|
1776
|
-
/**
|
|
1777
|
-
* Reject the elements of an array that meet the condition specified in a callback function.
|
|
1778
|
-
* @param fn the callback function.
|
|
1779
|
-
* @signature
|
|
1780
|
-
* P.reject(array, fn)
|
|
1781
|
-
* P.reject.indexed(array, fn)
|
|
1782
|
-
* @example
|
|
1783
|
-
* P.reject([1, 2, 3], x => x % 2 === 0) // => [1, 3]
|
|
1784
|
-
* P.reject.indexed([1, 2, 3], (x, i, array) => x % 2 === 0) // => [1, 3]
|
|
1785
|
-
* @dataFirst
|
|
1786
|
-
* @indexed
|
|
1787
|
-
* @pipeable
|
|
1788
|
-
* @category Array
|
|
1789
|
-
*/
|
|
1790
|
-
declare function reject<T>(fn: Pred<T, boolean>): (items: ReadonlyArray<T>) => Array<T>;
|
|
1791
|
-
declare namespace reject {
|
|
1792
|
-
function indexed<T, K>(array: ReadonlyArray<T>, fn: PredIndexed<T, boolean>): Array<K>;
|
|
1793
|
-
function indexed<T, K>(fn: PredIndexed<T, boolean>): (array: ReadonlyArray<T>) => Array<K>;
|
|
1794
|
-
const lazy: <T>(fn: PredIndexedOptional<T, boolean>) => (value: T, index?: number | undefined, array?: readonly T[] | undefined) => LazyResult<T>;
|
|
1795
|
-
const lazyIndexed: (<T>(fn: PredIndexedOptional<T, boolean>) => (value: T, index?: number | undefined, array?: readonly T[] | undefined) => LazyResult<T>) & {
|
|
1796
|
-
readonly indexed: true;
|
|
1797
|
-
};
|
|
1798
|
-
}
|
|
1799
|
-
|
|
1800
|
-
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>;
|
|
1801
|
-
type IsNoTuple<T> = T extends readonly [unknown, ...Array<unknown>] ? never : T;
|
|
1802
|
-
/**
|
|
1803
|
-
* Reverses array.
|
|
1804
|
-
* @param array the array
|
|
1805
|
-
* @signature
|
|
1806
|
-
* P.reverse(arr);
|
|
1807
|
-
* @example
|
|
1808
|
-
* P.reverse([1, 2, 3]) // [3, 2, 1]
|
|
1809
|
-
* @dataFirst
|
|
1810
|
-
* @category Array
|
|
1811
|
-
*/
|
|
1812
|
-
declare function reverse<T extends ReadonlyArray<unknown>>(array: T): Reverse<T>;
|
|
1813
|
-
/**
|
|
1814
|
-
* Reverses array.
|
|
1815
|
-
* @signature
|
|
1816
|
-
* P.reverse()(array);
|
|
1817
|
-
* @example
|
|
1818
|
-
* P.reverse()([1, 2, 3]) // [3, 2, 1]
|
|
1819
|
-
* @dataLast
|
|
1820
|
-
* @category Array
|
|
1821
|
-
*/
|
|
1822
|
-
declare function reverse<T extends ReadonlyArray<unknown>>(): (array: T) => Reverse<T>;
|
|
1823
|
-
|
|
1824
|
-
type Sampled<T extends IterableContainer, N extends number> = number extends N ? SampledGeneric<T> : undefined extends T[N] ? T : SampledLiteral<T, N>;
|
|
1825
|
-
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]>;
|
|
1826
|
-
type SampledLiteral<T extends IterableContainer, N extends number, Iteration extends Array<unknown> = []> = Iteration['length'] extends N ? [] : T extends readonly [infer First, ...infer Tail] ? [
|
|
1827
|
-
First | Tail[number],
|
|
1828
|
-
...SampledLiteral<Tail, N, [unknown, ...Iteration]>
|
|
1829
|
-
] : 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]>;
|
|
1830
|
-
/**
|
|
1831
|
-
* Returns a random subset of size `sampleSize` from `array`.
|
|
1832
|
-
*
|
|
1833
|
-
* Maintains and infers most of the typing information that could be passed
|
|
1834
|
-
* along to the output. This means that when using tuples, the output will be
|
|
1835
|
-
* a tuple too, and when using literals, those literals would be preserved.
|
|
1836
|
-
*
|
|
1837
|
-
* The items in the result are kept in the same order as they are in the input.
|
|
1838
|
-
* If you need to get a shuffled response you can pipe the shuffle function
|
|
1839
|
-
* after this one.
|
|
1840
|
-
*
|
|
1841
|
-
* @param data the array
|
|
1842
|
-
* @param sampleSize the number of elements to take
|
|
1843
|
-
* @signature
|
|
1844
|
-
* P.sample(array, sampleSize)
|
|
1845
|
-
* @example
|
|
1846
|
-
* P.sample(["hello", "world"], 1); // => ["hello"] // typed string[]
|
|
1847
|
-
* P.sample(["hello", "world"] as const, 1); // => ["world"] // typed ["hello" | "world"]
|
|
1848
|
-
* @dataFirst
|
|
1849
|
-
* @pipeable
|
|
1850
|
-
* @category Array
|
|
1851
|
-
*/
|
|
1852
|
-
declare function sample<T extends IterableContainer, N extends number = number>(data: T, sampleSize: N): Sampled<T, N>;
|
|
1853
|
-
/**
|
|
1854
|
-
* Returns a random subset of size `sampleSize` from `array`.
|
|
1855
|
-
*
|
|
1856
|
-
* Maintains and infers most of the typing information that could be passed
|
|
1857
|
-
* along to the output. This means that when using tuples, the output will be
|
|
1858
|
-
* a tuple too, and when using literals, those literals would be preserved.
|
|
1859
|
-
*
|
|
1860
|
-
* The items in the result are kept in the same order as they are in the input.
|
|
1861
|
-
* If you need to get a shuffled response you can pipe the shuffle function
|
|
1862
|
-
* after this one.
|
|
1863
|
-
*
|
|
1864
|
-
* @param sampleSize the number of elements to take
|
|
1865
|
-
* @signature
|
|
1866
|
-
* P.sample(sampleSize)(array)
|
|
1867
|
-
* @example
|
|
1868
|
-
* P.sample(1)(["hello", "world"]); // => ["hello"] // typed string[]
|
|
1869
|
-
* P.sample(1)(["hello", "world"] as const); // => ["world"] // typed ["hello" | "world"]
|
|
1870
|
-
* @dataLast
|
|
1871
|
-
* @pipeable
|
|
1872
|
-
* @category Array
|
|
1873
|
-
*/
|
|
1874
|
-
declare function sample<T extends IterableContainer, N extends number = number>(sampleSize: N): (data: T) => Sampled<T, N>;
|
|
1875
|
-
|
|
1876
|
-
/**
|
|
1877
|
-
* Shuffles the input array, returning a new array with the same elements in a random order.
|
|
1878
|
-
* @param items the array to shuffle
|
|
1879
|
-
* @signature
|
|
1880
|
-
* P.shuffle(array)
|
|
1881
|
-
* @example
|
|
1882
|
-
* P.shuffle([4, 2, 7, 5]) // => [7, 5, 4, 2]
|
|
1883
|
-
* @category Array
|
|
1884
|
-
* @dataFirst
|
|
1885
|
-
*/
|
|
1886
|
-
declare function shuffle<T>(items: ReadonlyArray<T>): Array<T>;
|
|
1887
|
-
/**
|
|
1888
|
-
* Shuffles the input array, returning a new array with the same elements in a random order.
|
|
1889
|
-
* @signature
|
|
1890
|
-
* P.shuffle()(array)
|
|
1891
|
-
* @example
|
|
1892
|
-
* P.pipe([4, 2, 7, 5], P.shuffle()) // => [7, 5, 4, 2]
|
|
1893
|
-
* @category Array
|
|
1894
|
-
* @dataLast
|
|
1895
|
-
*/
|
|
1896
|
-
declare function shuffle<T>(): (items: ReadonlyArray<T>) => Array<T>;
|
|
1897
|
-
|
|
1898
|
-
interface Strict$5 {
|
|
1899
|
-
<T extends IterableContainer>(items: T, cmp: (a: T[number], b: T[number]) => number): Sorted<T>;
|
|
1900
|
-
<T extends IterableContainer>(cmp: (a: T[number], b: T[number]) => number): (items: T) => Sorted<T>;
|
|
1901
|
-
}
|
|
1902
|
-
type Sorted<T extends IterableContainer> = {
|
|
1903
|
-
-readonly [P in keyof T]: T[number];
|
|
1904
|
-
};
|
|
1905
|
-
/**
|
|
1906
|
-
* 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.
|
|
1907
|
-
* Sorting is based on a native `sort` function. It's not guaranteed to be stable.
|
|
1908
|
-
*
|
|
1909
|
-
* If the input array is more complex (non-empty array, tuple, etc...) use the
|
|
1910
|
-
* strict mode to maintain it's shape.
|
|
1911
|
-
*
|
|
1912
|
-
* @param items the array to sort
|
|
1913
|
-
* @param cmp the comparator function
|
|
1914
|
-
* @signature
|
|
1915
|
-
* P.sort(items, cmp)
|
|
1916
|
-
* P.sort.strict(items, cmp)
|
|
1917
|
-
* @example
|
|
1918
|
-
* P.sort([4, 2, 7, 5], (a, b) => a - b) // => [2, 4, 5, 7] typed Array<number>
|
|
1919
|
-
* P.sort.strict([4, 2] as [number, number], (a, b) => a - b) // [2, 4] typed [number, number]
|
|
1920
|
-
* @dataFirst
|
|
1921
|
-
* @category Array
|
|
1922
|
-
* @strict
|
|
1923
|
-
*/
|
|
1924
|
-
declare function sort<T>(items: ReadonlyArray<T>, cmp: (a: T, b: T) => number): Array<T>;
|
|
1925
|
-
/**
|
|
1926
|
-
* 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.
|
|
1927
|
-
* Sorting is based on a native `sort` function. It's not guaranteed to be stable.
|
|
1928
|
-
*
|
|
1929
|
-
* If the input array is more complex (non-empty array, tuple, etc...) use the
|
|
1930
|
-
* strict mode to maintain it's shape.
|
|
1931
|
-
*
|
|
1932
|
-
* @param cmp the comparator function
|
|
1933
|
-
* @signature
|
|
1934
|
-
* P.sort(cmp)(items)
|
|
1935
|
-
* P.sort.strict(cmp)(items)
|
|
1936
|
-
* @example
|
|
1937
|
-
* P.pipe([4, 2, 7, 5], P.sort((a, b) => a - b)) // => [2, 4, 5, 7] typed Array<number>
|
|
1938
|
-
* P.pipe([4, 2] as [number, number], P.sort.strict((a, b) => a - b)) // => [2, 4] typed [number, number]
|
|
1939
|
-
* @dataLast
|
|
1940
|
-
* @category Array
|
|
1941
|
-
* @strict
|
|
1942
|
-
*/
|
|
1943
|
-
declare function sort<T>(cmp: (a: T, b: T) => number): (items: ReadonlyArray<T>) => Array<T>;
|
|
1944
|
-
declare namespace sort {
|
|
1945
|
-
const strict: Strict$5;
|
|
1946
|
-
}
|
|
1947
|
-
|
|
1948
|
-
declare const ALL_DIRECTIONS: readonly ["asc", "desc"];
|
|
1949
|
-
type Direction = (typeof ALL_DIRECTIONS)[number];
|
|
1950
|
-
type ComparablePrimitive = boolean | number | string;
|
|
1951
|
-
type Comparable = {
|
|
1952
|
-
valueOf(): ComparablePrimitive;
|
|
1953
|
-
} | ComparablePrimitive;
|
|
1954
|
-
type SortProjection<T> = (x: T) => Comparable;
|
|
1955
|
-
type SortPair<T> = readonly [
|
|
1956
|
-
projector: SortProjection<T>,
|
|
1957
|
-
direction: Direction
|
|
1958
|
-
];
|
|
1959
|
-
type SortRule<T> = SortPair<T> | SortProjection<T>;
|
|
1960
|
-
interface Strict$4 {
|
|
1961
|
-
<T extends IterableContainer>(...sortRules: Readonly<NonEmptyArray<SortRule<T[number]>>>): (array: T) => SortedBy<T>;
|
|
1962
|
-
<T extends IterableContainer>(array: T, ...sortRules: Readonly<NonEmptyArray<SortRule<T[number]>>>): SortedBy<T>;
|
|
1963
|
-
}
|
|
1964
|
-
type SortedBy<T extends IterableContainer> = {
|
|
1965
|
-
-readonly [P in keyof T]: T[number];
|
|
1966
|
-
};
|
|
1967
|
-
/**
|
|
1968
|
-
* Sorts the list according to the supplied functions and directions.
|
|
1969
|
-
* Sorting is based on a native `sort` function. It's not guaranteed to be stable.
|
|
1970
|
-
*
|
|
1971
|
-
* Directions are applied to functions in order and default to ascending if not specified.
|
|
1972
|
-
*
|
|
1973
|
-
* If the input array is more complex (non-empty array, tuple, etc...) use the
|
|
1974
|
-
* strict mode to maintain it's shape.
|
|
1975
|
-
*
|
|
1976
|
-
* @param sortRules main sort rule
|
|
1977
|
-
* @signature
|
|
1978
|
-
* P.sortBy(sortRule, ...additionalSortRules)(array)
|
|
1979
|
-
* P.sortBy.strict(sortRule, ...additionalSortRules)(array)
|
|
1980
|
-
* @example
|
|
1981
|
-
* P.pipe(
|
|
1982
|
-
* [{ a: 1 }, { a: 3 }, { a: 7 }, { a: 2 }],
|
|
1983
|
-
* P.sortBy(x => x.a)
|
|
1984
|
-
* ) // => [{ a: 1 }, { a: 2 }, { a: 3 }, { a: 7 }] typed Array<{a:number}>
|
|
1985
|
-
* P.pipe(
|
|
1986
|
-
* [{ a: 1 }, { a: 3 }] as const,
|
|
1987
|
-
* P.sortBy.strict(x => x.a)
|
|
1988
|
-
* ) // => [{ a: 1 }, { a: 3 }] typed [{a: 1 | 3}, {a: 1 | 3}]
|
|
1989
|
-
* @dataLast
|
|
1990
|
-
* @category Array
|
|
1991
|
-
* @strict
|
|
1992
|
-
*/
|
|
1993
|
-
declare function sortBy<T>(...sortRules: Readonly<NonEmptyArray<SortRule<T>>>): (array: ReadonlyArray<T>) => Array<T>;
|
|
1994
|
-
/**
|
|
1995
|
-
* Sorts the list according to the supplied functions and directions.
|
|
1996
|
-
* Sorting is based on a native `sort` function. It's not guaranteed to be stable.
|
|
1997
|
-
*
|
|
1998
|
-
* Directions are applied to functions in order and default to ascending if not specified.
|
|
1999
|
-
*
|
|
2000
|
-
* If the input array is more complex (non-empty array, tuple, etc...) use the
|
|
2001
|
-
* strict mode to maintain it's shape.
|
|
2002
|
-
*
|
|
2003
|
-
* @param array the array to sort
|
|
2004
|
-
* @param sortRules main sort rule
|
|
2005
|
-
* @signature
|
|
2006
|
-
* P.sortBy(array, sortRule, ...additionalSortRules)
|
|
2007
|
-
* P.sortBy.strict(array, sortRule, ...additionalSortRules)
|
|
2008
|
-
* @example
|
|
2009
|
-
* P.sortBy(
|
|
2010
|
-
* [{ a: 1 }, { a: 3 }, { a: 7 }, { a: 2 }],
|
|
2011
|
-
* x => x.a
|
|
2012
|
-
* )
|
|
2013
|
-
* // => [{ a: 1 }, { a: 2 }, { a: 3 }, { a: 7 }] typed Array<{a:number}>
|
|
2014
|
-
*
|
|
2015
|
-
* P.sortBy(
|
|
2016
|
-
* [
|
|
2017
|
-
* {color: 'red', weight: 2},
|
|
2018
|
-
* {color: 'blue', weight: 3},
|
|
2019
|
-
* {color: 'green', weight: 1},
|
|
2020
|
-
* {color: 'purple', weight: 1},
|
|
2021
|
-
* ],
|
|
2022
|
-
* [x => x.weight, 'asc'], x => x.color
|
|
2023
|
-
* )
|
|
2024
|
-
* // =>
|
|
2025
|
-
* // {color: 'green', weight: 1},
|
|
2026
|
-
* // {color: 'purple', weight: 1},
|
|
2027
|
-
* // {color: 'red', weight: 2},
|
|
2028
|
-
* // {color: 'blue', weight: 3},
|
|
2029
|
-
* // typed Array<{color: string, weight: number}>
|
|
2030
|
-
*
|
|
2031
|
-
* P.sortBy.strict(
|
|
2032
|
-
* [{ a: 1 }, { a: 3 }] as const,
|
|
2033
|
-
* x => x.a
|
|
2034
|
-
* )
|
|
2035
|
-
* // => [{ a: 1 }, { a: 3 }] typed [{a: 1 | 3}, {a: 1 | 3}]
|
|
2036
|
-
* @dataFirst
|
|
2037
|
-
* @category Array
|
|
2038
|
-
* @strict
|
|
2039
|
-
*/
|
|
2040
|
-
declare function sortBy<T>(array: ReadonlyArray<T>, ...sortRules: Readonly<NonEmptyArray<SortRule<T>>>): Array<T>;
|
|
2041
|
-
declare namespace sortBy {
|
|
2042
|
-
const strict: Strict$4;
|
|
2043
|
-
}
|
|
2044
|
-
|
|
2045
|
-
/**
|
|
2046
|
-
* Removes elements from an array and, inserts new elements in their place.
|
|
2047
|
-
* @param items the array to splice.
|
|
2048
|
-
* @param start the index from which to start removing elements.
|
|
2049
|
-
* @param deleteCount the number of elements to remove.
|
|
2050
|
-
* @param replacement the elements to insert into the array in place of the deleted elements.
|
|
2051
|
-
* @signature
|
|
2052
|
-
* P.splice(items, start, deleteCount, replacement)
|
|
2053
|
-
* @example
|
|
2054
|
-
* P.splice([1,2,3,4,5,6,7,8], 2, 3, []); //=> [1,2,6,7,8]
|
|
2055
|
-
* P.splice([1,2,3,4,5,6,7,8], 2, 3, [9, 10]); //=> [1,2,9,10,6,7,8]
|
|
2056
|
-
* @dataFirst
|
|
2057
|
-
* @category Array
|
|
2058
|
-
*/
|
|
2059
|
-
declare function splice<T>(items: ReadonlyArray<T>, start: number, deleteCount: number, replacement: ReadonlyArray<T>): Array<T>;
|
|
2060
|
-
/**
|
|
2061
|
-
* Removes elements from an array and, inserts new elements in their place.
|
|
2062
|
-
* @param items the array to splice.
|
|
2063
|
-
* @param start the index from which to start removing elements.
|
|
2064
|
-
* @param deleteCount the number of elements to remove.
|
|
2065
|
-
* @param replacement the elements to insert into the array in place of the deleted elements.
|
|
2066
|
-
* @signature
|
|
2067
|
-
* P.splice(start, deleteCount, replacement)(items)
|
|
2068
|
-
* @example
|
|
2069
|
-
* P.pipe([1,2,3,4,5,6,7,8], P.splice(2, 3, [])) // => [1,2,6,7,8]
|
|
2070
|
-
* P.pipe([1,2,3,4,5,6,7,8], P.splice(2, 3, [9, 10])) // => [1,2,9,10,6,7,8]
|
|
2071
|
-
* @dataLast
|
|
2072
|
-
* @category Array
|
|
2073
|
-
*/
|
|
2074
|
-
declare function splice<T>(start: number, deleteCount: number, replacement: ReadonlyArray<T>): (items: ReadonlyArray<T>) => Array<T>;
|
|
2075
|
-
|
|
2076
|
-
/**
|
|
2077
|
-
* Splits a given array at a given index.
|
|
2078
|
-
* @param array the array to split
|
|
2079
|
-
* @param index the index to split at
|
|
2080
|
-
* @signature
|
|
2081
|
-
* P.splitAt(array, index)
|
|
2082
|
-
* @example
|
|
2083
|
-
* P.splitAt([1, 2, 3], 1) // => [[1], [2, 3]]
|
|
2084
|
-
* P.splitAt([1, 2, 3, 4, 5], -1) // => [[1, 2, 3, 4], [5]]
|
|
2085
|
-
* @dataFirst
|
|
2086
|
-
* @category Array
|
|
2087
|
-
*/
|
|
2088
|
-
declare function splitAt<T>(array: ReadonlyArray<T>, index: number): [Array<T>, Array<T>];
|
|
2089
|
-
/**
|
|
2090
|
-
* Splits a given array at a given index.
|
|
2091
|
-
* @param index the index to split at
|
|
2092
|
-
* @signature
|
|
2093
|
-
* P.splitAt(index)(array)
|
|
2094
|
-
* @example
|
|
2095
|
-
* P.splitAt(1)([1, 2, 3]) // => [[1], [2, 3]]
|
|
2096
|
-
* P.splitAt(-1)([1, 2, 3, 4, 5]) // => [[1, 2, 3, 4], [5]]
|
|
2097
|
-
* @dataLast
|
|
2098
|
-
* @category Array
|
|
2099
|
-
*/
|
|
2100
|
-
declare function splitAt<T>(index: number): (array: ReadonlyArray<T>) => [Array<T>, Array<T>];
|
|
2101
|
-
|
|
2102
|
-
/**
|
|
2103
|
-
* Splits a given array at the first index where the given predicate returns true.
|
|
2104
|
-
* @param array the array to split
|
|
2105
|
-
* @param fn the predicate
|
|
2106
|
-
* @signature
|
|
2107
|
-
* P.splitWhen(array, fn)
|
|
2108
|
-
* @example
|
|
2109
|
-
* P.splitWhen([1, 2, 3], x => x === 2) // => [[1], [2, 3]]
|
|
2110
|
-
* @dataFirst
|
|
2111
|
-
* @category Array
|
|
2112
|
-
*/
|
|
2113
|
-
declare function splitWhen<T>(array: ReadonlyArray<T>, fn: (item: T) => boolean): [Array<T>, Array<T>];
|
|
2114
|
-
/**
|
|
2115
|
-
* Splits a given array at an index where the given predicate returns true.
|
|
2116
|
-
* @param fn the predicate
|
|
2117
|
-
* @signature
|
|
2118
|
-
* P.splitWhen(fn)(array)
|
|
2119
|
-
* @example
|
|
2120
|
-
* P.splitWhen(x => x === 2)([1, 2, 3]) // => [[1], [2, 3]]
|
|
2121
|
-
* @dataLast
|
|
2122
|
-
* @category Array
|
|
2123
|
-
*/
|
|
2124
|
-
declare function splitWhen<T>(fn: (item: T) => boolean): (array: ReadonlyArray<T>) => [Array<T>, Array<T>];
|
|
2125
|
-
|
|
2126
|
-
/**
|
|
2127
|
-
* Returns the sum of the elements of an array using the provided predicate.
|
|
2128
|
-
* @param fn predicate function
|
|
2129
|
-
* @signature
|
|
2130
|
-
* P.sumBy(fn)(array)
|
|
2131
|
-
* P.sumBy.indexed(fn)(array)
|
|
2132
|
-
* @example
|
|
2133
|
-
* P.pipe(
|
|
2134
|
-
* [{a: 5}, {a: 1}, {a: 3}],
|
|
2135
|
-
* P.sumBy(x => x.a)
|
|
2136
|
-
* ) // 9
|
|
2137
|
-
* @dataLast
|
|
2138
|
-
* @indexed
|
|
2139
|
-
* @category Array
|
|
2140
|
-
*/
|
|
2141
|
-
declare function sumBy<T>(fn: (item: T) => number): (items: ReadonlyArray<T>) => number;
|
|
2142
|
-
/**
|
|
2143
|
-
* Returns the sum of the elements of an array using the provided predicate.
|
|
2144
|
-
* @param items the array
|
|
2145
|
-
* @param fn predicate function
|
|
2146
|
-
* @signature
|
|
2147
|
-
* P.sumBy(array, fn)
|
|
2148
|
-
* P.sumBy.indexed(array, fn)
|
|
2149
|
-
* @example
|
|
2150
|
-
* P.sumBy(
|
|
2151
|
-
* [{a: 5}, {a: 1}, {a: 3}],
|
|
2152
|
-
* x => x.a
|
|
2153
|
-
* ) // 9
|
|
2154
|
-
* @dataFirst
|
|
2155
|
-
* @indexed
|
|
2156
|
-
* @category Array
|
|
2157
|
-
*/
|
|
2158
|
-
declare function sumBy<T>(items: ReadonlyArray<T>, fn: (item: T) => number): number;
|
|
2159
|
-
declare namespace sumBy {
|
|
2160
|
-
function indexed<T>(array: ReadonlyArray<T>, fn: PredIndexed<T, number>): number;
|
|
2161
|
-
function indexed<T>(fn: PredIndexed<T, number>): (array: ReadonlyArray<T>) => number;
|
|
2162
|
-
}
|
|
2163
|
-
|
|
2164
|
-
/**
|
|
2165
|
-
* @link https://github.com/sindresorhus/type-fest/blob/main/source/is-equal.d.ts
|
|
2166
|
-
*/
|
|
2167
|
-
type isEqual<A, B> = (<G>() => G extends A ? 1 : 2) extends <G>() => G extends B ? 1 : 2 ? true : false;
|
|
2168
|
-
type Difference<A extends number, B extends number> = TupleOfLength<A> extends [
|
|
2169
|
-
...infer U,
|
|
2170
|
-
...TupleOfLength<B>
|
|
2171
|
-
] ? U['length'] : never;
|
|
2172
|
-
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>>;
|
|
2173
|
-
type TupleOfLength<L extends number, T extends IterableContainer = []> = T['length'] extends L ? T : TupleOfLength<L, [...T, unknown]>;
|
|
2174
|
-
type IsNonNegative<T extends number> = number extends T ? false : `${T}` extends `-${string}` ? false : true;
|
|
2175
|
-
type CharactersTuple<T extends string> = string extends T ? Array<string> : T extends `${infer C}${infer R}` ? [C, ...CharactersTuple<R>] : [];
|
|
2176
|
-
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] ? [
|
|
2177
|
-
Position['length'] extends Index1 ? Original[Index2] : Position['length'] extends Index2 ? Original[Index1] : AtPosition,
|
|
2178
|
-
...SwapArrayInternal<Rest, Index1, Index2, [
|
|
2179
|
-
unknown,
|
|
2180
|
-
...Position
|
|
2181
|
-
], Original>
|
|
2182
|
-
] : T;
|
|
2183
|
-
type SwapString<T extends string, K1 extends number, K2 extends number> = Joined<SwapArray<CharactersTuple<T>, K1, K2>, ''>;
|
|
2184
|
-
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>;
|
|
2185
|
-
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;
|
|
2186
|
-
/**
|
|
2187
|
-
* Swaps the positions of two elements in an array or string at the provided indices.
|
|
2188
|
-
*
|
|
2189
|
-
* 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.
|
|
2190
|
-
*
|
|
2191
|
-
* If either index is out of bounds the result would be a shallow copy of the input, as-is.
|
|
2192
|
-
*
|
|
2193
|
-
* @param data the item to be manipulated. This can be an array, or a string.
|
|
2194
|
-
* @param index1 the first index
|
|
2195
|
-
* @param index2 the second index
|
|
2196
|
-
*
|
|
2197
|
-
* @signature
|
|
2198
|
-
* swapIndices(data, index1, index2)
|
|
2199
|
-
*
|
|
2200
|
-
* @example
|
|
2201
|
-
* swapIndices(['a', 'b', 'c'], 0, 1) // => ['b', 'a', 'c']
|
|
2202
|
-
* swapIndices(['a', 'b', 'c'], 1, -1) // => ['c', 'b', 'a']
|
|
2203
|
-
* swapIndices('abc', 0, 1) // => 'bac'
|
|
2204
|
-
*
|
|
2205
|
-
* @category Array
|
|
2206
|
-
*
|
|
2207
|
-
* @returns Returns the manipulated array or string.
|
|
2208
|
-
*
|
|
2209
|
-
* @dataFirst
|
|
2210
|
-
*/
|
|
2211
|
-
declare function swapIndices<T extends IterableContainer | string, K1 extends number, K2 extends number>(data: T, index1: K1, index2: K2): SwappedIndices<T, K1, K2>;
|
|
2212
|
-
/**
|
|
2213
|
-
* @param index1 the first index
|
|
2214
|
-
* @param index2 the second index
|
|
2215
|
-
*
|
|
2216
|
-
* @signature
|
|
2217
|
-
* swapIndices(index1, index2)(data)
|
|
2218
|
-
*
|
|
2219
|
-
* @example
|
|
2220
|
-
* swapIndices(0, 1)(['a', 'b', 'c']) // => ['b', 'a', 'c']
|
|
2221
|
-
* swapIndices(0, -1)('abc') // => 'cba'
|
|
2222
|
-
*
|
|
2223
|
-
* @category Array
|
|
2224
|
-
* @returns Returns the manipulated array or string.
|
|
2225
|
-
* @dataLast
|
|
2226
|
-
*/
|
|
2227
|
-
declare function swapIndices<K1 extends number, K2 extends number>(index1: K1, index2: K2): <T extends IterableContainer | string>(data: T) => SwappedIndices<T, K1, K2>;
|
|
2228
|
-
|
|
2229
|
-
/**
|
|
2230
|
-
* Returns the first `n` elements of `array`.
|
|
2231
|
-
* @param array the array
|
|
2232
|
-
* @param n the number of elements to take
|
|
2233
|
-
* @signature
|
|
2234
|
-
* P.take(array, n)
|
|
2235
|
-
* @example
|
|
2236
|
-
* P.take([1, 2, 3, 4, 3, 2, 1], 3) // => [1, 2, 3]
|
|
2237
|
-
* @dataFirst
|
|
2238
|
-
* @pipeable
|
|
2239
|
-
* @category Array
|
|
2240
|
-
*/
|
|
2241
|
-
declare function take<T>(array: ReadonlyArray<T>, n: number): Array<T>;
|
|
2242
|
-
/**
|
|
2243
|
-
* Returns the first `n` elements of `array`.
|
|
2244
|
-
* @param n the number of elements to take
|
|
2245
|
-
* @signature
|
|
2246
|
-
* P.take(n)(array)
|
|
2247
|
-
* @example
|
|
2248
|
-
* P.pipe([1, 2, 3, 4, 3, 2, 1], P.take(n)) // => [1, 2, 3]
|
|
2249
|
-
* @dataLast
|
|
2250
|
-
* @pipeable
|
|
2251
|
-
* @category Array
|
|
2252
|
-
*/
|
|
2253
|
-
declare function take<T>(n: number): (array: ReadonlyArray<T>) => Array<T>;
|
|
2254
|
-
declare namespace take {
|
|
2255
|
-
function lazy<T>(n: number): (value: T) => LazyResult<T>;
|
|
2256
|
-
}
|
|
2257
|
-
|
|
2258
|
-
/**
|
|
2259
|
-
* Take the first `n` items from `data` based on the provided ordering criteria.
|
|
2260
|
-
* This allows you to avoid sorting the array before taking the items.
|
|
2261
|
-
* The complexity of this function is *O(Nlogn)* where `N` is the length of the array.
|
|
2262
|
-
*
|
|
2263
|
-
* For the opposite operation (to drop `n` elements) see `dropFirstBy`.
|
|
2264
|
-
*
|
|
2265
|
-
* @params data - the input array
|
|
2266
|
-
* @params n - the number of items to take. If `n` is non-positive no items would be returned, if `n` is bigger then data.length a *clone* of `data` would be returned.
|
|
2267
|
-
* @param rules - A variadic array of order rules defining the sorting criteria.
|
|
2268
|
-
* Each order rule is a projection function that extracts a comparable value from the data. Sorting is based on these extracted values using the native `<` and `>` operators. Earlier rules take precedence over later ones. Use the syntax `[projection, "desc"]` for descending order.
|
|
2269
|
-
* @returns a subset of the input array.
|
|
2270
|
-
* @signature
|
|
2271
|
-
* P.takeFirstBy(data, n, ...rules);
|
|
2272
|
-
* @example
|
|
2273
|
-
* P.takeFirstBy(['aa', 'aaaa', 'a', 'aaa'], 2, x => x.length); // => ['a', 'aa']
|
|
2274
|
-
* @dataFirst
|
|
2275
|
-
* @category Array
|
|
2276
|
-
*/
|
|
2277
|
-
declare function takeFirstBy<T>(data: ReadonlyArray<T>, n: number, ...rules: Readonly<NonEmptyArray<OrderRule<T>>>): Array<T>;
|
|
2278
|
-
/**
|
|
2279
|
-
* Take the first `n` items from `data` based on the provided ordering criteria.
|
|
2280
|
-
* This allows you to avoid sorting the array before taking the items.
|
|
2281
|
-
* The complexity of this function is *O(Nlogn)* where `N` is the length of the array.
|
|
2282
|
-
*
|
|
2283
|
-
* For the opposite operation (to drop `n` elements) see `dropFirstBy`.
|
|
2284
|
-
*
|
|
2285
|
-
* @params data - the input array
|
|
2286
|
-
* @params n - the number of items to take. If `n` is non-positive no items would be returned, if `n` is bigger then data.length a *clone* of `data` would be returned.
|
|
2287
|
-
* @param rules - A variadic array of order rules defining the sorting criteria.
|
|
2288
|
-
* Each order rule is a projection function that extracts a comparable value from the data. Sorting is based on these extracted values using the native `<` and `>` operators. Earlier rules take precedence over later ones. Use the syntax `[projection, "desc"]` for descending order.
|
|
2289
|
-
* @returns a subset of the input array.
|
|
2290
|
-
* @signature
|
|
2291
|
-
* P.takeFirstBy(n, ...rules)(data);
|
|
2292
|
-
* @example
|
|
2293
|
-
* R.pipe(['aa', 'aaaa', 'a', 'aaa'], P.takeFirstBy(2, x => x.length)); // => ['a', 'aa']
|
|
2294
|
-
* @dataLast
|
|
2295
|
-
* @category Array
|
|
2296
|
-
*/
|
|
2297
|
-
declare function takeFirstBy<T>(n: number, ...rules: Readonly<NonEmptyArray<OrderRule<T>>>): (data: ReadonlyArray<T>) => Array<T>;
|
|
2298
|
-
|
|
2299
|
-
/**
|
|
2300
|
-
* Returns elements from the array until predicate returns false.
|
|
2301
|
-
* @param array the array
|
|
2302
|
-
* @param fn the predicate
|
|
2303
|
-
* @signature
|
|
2304
|
-
* P.takeWhile(array, fn)
|
|
2305
|
-
* @example
|
|
2306
|
-
* P.takeWhile([1, 2, 3, 4, 3, 2, 1], x => x !== 4) // => [1, 2, 3]
|
|
2307
|
-
* @dataFirst
|
|
2308
|
-
* @category Array
|
|
2309
|
-
*/
|
|
2310
|
-
declare function takeWhile<T>(array: ReadonlyArray<T>, fn: (item: T) => boolean): Array<T>;
|
|
2311
|
-
/**
|
|
2312
|
-
* Returns elements from the array until predicate returns false.
|
|
2313
|
-
* @param fn the predicate
|
|
2314
|
-
* @signature
|
|
2315
|
-
* P.takeWhile(fn)(array)
|
|
2316
|
-
* @example
|
|
2317
|
-
* P.pipe([1, 2, 3, 4, 3, 2, 1], P.takeWhile(x => x !== 4)) // => [1, 2, 3]
|
|
2318
|
-
* @dataLast
|
|
2319
|
-
* @category Array
|
|
2320
|
-
*/
|
|
2321
|
-
declare function takeWhile<T>(fn: (item: T) => boolean): (array: ReadonlyArray<T>) => Array<T>;
|
|
2322
|
-
|
|
2323
|
-
/**
|
|
2324
|
-
* Returns a new array containing only one copy of each element in the original list.
|
|
2325
|
-
* Elements are compared by reference using Set.
|
|
2326
|
-
* Note: In `pipe`, use `uniq()` form instead of `uniq`. Otherwise, the inferred type is lost.
|
|
2327
|
-
* @param array
|
|
2328
|
-
* @signature
|
|
2329
|
-
* P.uniq(array)
|
|
2330
|
-
* @example
|
|
2331
|
-
* P.uniq([1, 2, 2, 5, 1, 6, 7]) // => [1, 2, 5, 6, 7]
|
|
2332
|
-
* P.pipe(
|
|
2333
|
-
* [1, 2, 2, 5, 1, 6, 7], // only 4 iterations
|
|
2334
|
-
* P.uniq(),
|
|
2335
|
-
* P.take(3)
|
|
2336
|
-
* ) // => [1, 2, 5]
|
|
2337
|
-
* @pipeable
|
|
2338
|
-
* @category Array
|
|
2339
|
-
*/
|
|
2340
|
-
declare function uniq<T>(array: ReadonlyArray<T>): Array<T>;
|
|
2341
|
-
declare function uniq<T>(): (array: ReadonlyArray<T>) => Array<T>;
|
|
2342
|
-
declare namespace uniq {
|
|
2343
|
-
function lazy<T>(): (value: T) => LazyResult<T>;
|
|
2344
|
-
}
|
|
2345
|
-
|
|
2346
|
-
declare function uniqBy<T, K>(array: ReadonlyArray<T>, transformer: (item: T) => K): Array<T>;
|
|
2347
|
-
/**
|
|
2348
|
-
* Returns a new array containing only one copy of each element in the original list transformed by a function.
|
|
2349
|
-
* Elements are compared by reference using Set.
|
|
2350
|
-
* @param array
|
|
2351
|
-
* @signature
|
|
2352
|
-
* P.uniqBy(array, fn)
|
|
2353
|
-
* @example
|
|
2354
|
-
* P.uniqBy(
|
|
2355
|
-
* [{ n: 1 }, { n: 2 }, { n: 2 }, { n: 5 }, { n: 1 }, { n: 6 }, { n: 7 }],
|
|
2356
|
-
* (obj) => obj.n,
|
|
2357
|
-
* ) // => [{n: 1}, {n: 2}, {n: 5}, {n: 6}, {n: 7}]
|
|
2358
|
-
* P.pipe(
|
|
2359
|
-
* [{n: 1}, {n: 2}, {n: 2}, {n: 5}, {n: 1}, {n: 6}, {n: 7}], // only 4 iterations
|
|
2360
|
-
* P.uniqBy(obj => obj.n),
|
|
2361
|
-
* P.take(3)
|
|
2362
|
-
* ) // => [{n: 1}, {n: 2}, {n: 5}]
|
|
2363
|
-
* @pipeable
|
|
2364
|
-
* @category Array
|
|
2365
|
-
*/
|
|
2366
|
-
declare function uniqBy<T, K>(transformer: (item: T) => K): (array: ReadonlyArray<T>) => Array<T>;
|
|
2367
|
-
|
|
2368
|
-
type IsEquals<T> = (a: T, b: T) => boolean;
|
|
2369
|
-
declare function _lazy<T>(isEquals: IsEquals<T>): (value: T, index?: number, array?: ReadonlyArray<T>) => LazyResult<T>;
|
|
2370
|
-
/**
|
|
2371
|
-
* Returns a new array containing only one copy of each element in the original list.
|
|
2372
|
-
* Elements are compared by custom comparator isEquals.
|
|
2373
|
-
* @param array
|
|
2374
|
-
* @param isEquals the comparator
|
|
2375
|
-
* @signature
|
|
2376
|
-
* P.uniqWith(array, isEquals)
|
|
2377
|
-
* @example
|
|
2378
|
-
* P.uniqWith(
|
|
2379
|
-
* [{a: 1}, {a: 2}, {a: 2}, {a: 5}, {a: 1}, {a: 6}, {a: 7}],
|
|
2380
|
-
* P.equals,
|
|
2381
|
-
* ) // => [{a: 1}, {a: 2}, {a: 5}, {a: 6}, {a: 7}]
|
|
2382
|
-
* @dataFirst
|
|
2383
|
-
* @category Array
|
|
2384
|
-
*/
|
|
2385
|
-
declare function uniqWith<T>(array: ReadonlyArray<T>, isEquals: IsEquals<T>): Array<T>;
|
|
2386
|
-
/**
|
|
2387
|
-
* Returns a new array containing only one copy of each element in the original list.
|
|
2388
|
-
* Elements are compared by custom comparator isEquals.
|
|
2389
|
-
* @param isEquals the comparator
|
|
2390
|
-
* @signature P.uniqWith(isEquals)(array)
|
|
2391
|
-
* @example
|
|
2392
|
-
* P.uniqWith(P.equals)(
|
|
2393
|
-
* [{a: 1}, {a: 2}, {a: 2}, {a: 5}, {a: 1}, {a: 6}, {a: 7}],
|
|
2394
|
-
* ) // => [{a: 1}, {a: 2}, {a: 5}, {a: 6}, {a: 7}]
|
|
2395
|
-
* P.pipe(
|
|
2396
|
-
* [{a: 1}, {a: 2}, {a: 2}, {a: 5}, {a: 1}, {a: 6}, {a: 7}], // only 4 iterations
|
|
2397
|
-
* P.uniqWith(P.equals),
|
|
2398
|
-
* P.take(3)
|
|
2399
|
-
* ) // => [{a: 1}, {a: 2}, {a: 5}]
|
|
2400
|
-
* @dataLast
|
|
2401
|
-
* @category Object
|
|
2402
|
-
*/
|
|
2403
|
-
declare function uniqWith<T>(isEquals: IsEquals<T>): (array: ReadonlyArray<T>) => Array<T>;
|
|
2404
|
-
declare namespace uniqWith {
|
|
2405
|
-
const lazy: typeof _lazy & {
|
|
2406
|
-
readonly indexed: true;
|
|
2407
|
-
};
|
|
2408
|
-
}
|
|
2409
|
-
|
|
2410
|
-
interface Strict$3 {
|
|
2411
|
-
<F extends IterableContainer, S extends IterableContainer>(first: F, second: S): Zip<F, S>;
|
|
2412
|
-
<S extends IterableContainer>(second: S): <F extends IterableContainer>(first: F) => Zip<F, S>;
|
|
2413
|
-
}
|
|
2414
|
-
type Zip<Left extends IterableContainer, Right extends IterableContainer> = Left extends readonly [] ? [] : Right extends readonly [] ? [] : Left extends readonly [infer LeftHead, ...infer LeftRest] ? Right extends readonly [infer RightHead, ...infer RightRest] ? [
|
|
2415
|
-
[LeftHead, RightHead],
|
|
2416
|
-
...Zip<LeftRest, RightRest>
|
|
2417
|
-
] : [
|
|
2418
|
-
[LeftHead, Right[number]],
|
|
2419
|
-
...Zip<LeftRest, Right>
|
|
2420
|
-
] : Right extends readonly [infer RightHead, ...infer RightRest] ? [[Left[number], RightHead], ...Zip<Left, RightRest>] : Array<[Left[number], Right[number]]>;
|
|
2421
|
-
/**
|
|
2422
|
-
* Creates a new list from two supplied lists by pairing up equally-positioned items.
|
|
2423
|
-
* The length of the returned list will match the shortest of the two inputs.
|
|
2424
|
-
*
|
|
2425
|
-
* If the input array are tuples, you can use the strict option
|
|
2426
|
-
* to get another tuple instead of a generic array type.
|
|
2427
|
-
* @param first the first input list
|
|
2428
|
-
* @param second the second input list
|
|
2429
|
-
* @signature
|
|
2430
|
-
* P.zip(first, second)
|
|
2431
|
-
* @example
|
|
2432
|
-
* P.zip([1, 2], ['a', 'b']) // => [[1, 'a'], [2, 'b']] (type: [number, string][])
|
|
2433
|
-
* P.zip.strict([1, 2] as const, ['a', 'b'] as const) // => [[1, 'a'], [2, 'b']] (type: [[1, 'a'], [2, 'b']])
|
|
2434
|
-
* @dataFirst
|
|
2435
|
-
* @category Array
|
|
2436
|
-
* @strict
|
|
2437
|
-
*/
|
|
2438
|
-
declare function zip<F, S>(first: ReadonlyArray<F>, second: ReadonlyArray<S>): Array<[F, S]>;
|
|
2439
|
-
/**
|
|
2440
|
-
* Creates a new list from two supplied lists by pairing up equally-positioned items.
|
|
2441
|
-
* The length of the returned list will match the shortest of the two inputs.
|
|
2442
|
-
*
|
|
2443
|
-
* If the input array are tuples, you can use the strict option
|
|
2444
|
-
* to get another tuple instead of a generic array type.
|
|
2445
|
-
* @param second the second input list
|
|
2446
|
-
* @signature
|
|
2447
|
-
* P.zip(second)(first)
|
|
2448
|
-
* @example
|
|
2449
|
-
* P.zip(['a', 'b'])([1, 2]) // => [[1, 'a'], [2, 'b']] (type: [number, string][])
|
|
2450
|
-
* P.zip.strict(['a', 'b'] as const)([1, 2] as const) // => [[1, 'a'], [2, 'b']] (type: [[1, 'a'], [2, 'b']])
|
|
2451
|
-
* @dataLast
|
|
2452
|
-
* @category Array
|
|
2453
|
-
* @strict
|
|
2454
|
-
*/
|
|
2455
|
-
declare function zip<S>(second: ReadonlyArray<S>): <F>(first: ReadonlyArray<F>) => Array<[F, S]>;
|
|
2456
|
-
declare namespace zip {
|
|
2457
|
-
const strict: Strict$3;
|
|
2458
|
-
}
|
|
2459
|
-
|
|
2460
|
-
/**
|
|
2461
|
-
* Creates a new object from two supplied lists by pairing up equally-positioned items.
|
|
2462
|
-
* Key/value pairing is truncated to the length of the shorter of the two lists
|
|
2463
|
-
* @param first the first input list
|
|
2464
|
-
* @param second the second input list
|
|
2465
|
-
* @signature
|
|
2466
|
-
* P.zipObj(first, second)
|
|
2467
|
-
* @example
|
|
2468
|
-
* P.zipObj(['a', 'b'], [1, 2]) // => {a: 1, b: 2}
|
|
2469
|
-
* @dataFirst
|
|
2470
|
-
* @category Array
|
|
2471
|
-
*/
|
|
2472
|
-
declare function zipObj<F extends number | string | symbol, S>(first: ReadonlyArray<F>, second: ReadonlyArray<S>): Record<F, S>;
|
|
2473
|
-
/**
|
|
2474
|
-
* Creates a new object from two supplied lists by pairing up equally-positioned items.
|
|
2475
|
-
* Key/value pairing is truncated to the length of the shorter of the two lists
|
|
2476
|
-
* @param second the second input list
|
|
2477
|
-
* @signature
|
|
2478
|
-
* P.zipObj(second)(first)
|
|
2479
|
-
* @example
|
|
2480
|
-
* P.zipObj([1, 2])(['a', 'b']) // => {a: 1, b: 2}
|
|
2481
|
-
* @dataLast
|
|
2482
|
-
* @category Array
|
|
2483
|
-
*/
|
|
2484
|
-
declare function zipObj<S>(second: ReadonlyArray<S>): <F extends number | string | symbol>(first: ReadonlyArray<F>) => Record<F, S>;
|
|
2485
|
-
|
|
2486
|
-
type ZippingFunction<F = unknown, S = unknown, R = unknown> = (f: F, s: S) => R;
|
|
2487
|
-
/**
|
|
2488
|
-
* Creates a new list from two supplied lists by calling the supplied function
|
|
2489
|
-
* with the same-positioned element from each list.
|
|
2490
|
-
* @param first the first input list
|
|
2491
|
-
* @param second the second input list
|
|
2492
|
-
* @param fn the function applied to each position of the list
|
|
2493
|
-
* @signature
|
|
2494
|
-
* P.zipWith(first, second, fn)
|
|
2495
|
-
* @example
|
|
2496
|
-
* P.zipWith(['1', '2', '3'], ['a', 'b', 'c'], (a, b) => a + b) // => ['1a', '2b', '3c']
|
|
2497
|
-
* @dataFirst
|
|
2498
|
-
* @category Array
|
|
2499
|
-
*/
|
|
2500
|
-
declare function zipWith<F, S, R>(first: ReadonlyArray<F>, second: ReadonlyArray<S>, fn: ZippingFunction<F, S, R>): Array<R>;
|
|
2501
|
-
/**
|
|
2502
|
-
* Creates a new list from two supplied lists by calling the supplied function
|
|
2503
|
-
* with the same-positioned element from each list.
|
|
2504
|
-
* @param fn the function applied to each position of the list
|
|
2505
|
-
* @signature
|
|
2506
|
-
* P.zipWith(fn)(first, second)
|
|
2507
|
-
* @example
|
|
2508
|
-
* P.zipWith((a, b) => a + b)(['1', '2', '3'], ['a', 'b', 'c']) // => ['1a', '2b', '3c']
|
|
2509
|
-
* @dataLast
|
|
2510
|
-
* @category Array
|
|
2511
|
-
*/
|
|
2512
|
-
declare function zipWith<F, S, R>(fn: ZippingFunction<F, S, R>): (first: ReadonlyArray<F>, second: ReadonlyArray<S>) => Array<R>;
|
|
2513
|
-
/**
|
|
2514
|
-
* Creates a new list from two supplied lists by calling the supplied function
|
|
2515
|
-
* with the same-positioned element from each list.
|
|
2516
|
-
* @param fn the function applied to each position of the list
|
|
2517
|
-
* @param second the second input list
|
|
2518
|
-
* @signature
|
|
2519
|
-
* P.zipWith(fn)(first, second)
|
|
2520
|
-
* @example
|
|
2521
|
-
* P.zipWith((a, b) => a + b, ['a', 'b', 'c'])(['1', '2', '3']) // => ['1a', '2b', '3c']
|
|
2522
|
-
* @dataLast
|
|
2523
|
-
* @category Array
|
|
2524
|
-
*/
|
|
2525
|
-
declare function zipWith<F, S, R>(fn: ZippingFunction<F, S, R>, second: ReadonlyArray<S>): (first: ReadonlyArray<F>) => Array<R>;
|
|
2526
|
-
|
|
2527
|
-
type Case<In, Out, Thru extends In = In> = readonly [
|
|
2528
|
-
when: ((data: In) => boolean) | ((data: In) => data is Thru),
|
|
2529
|
-
then: (data: Thru) => Out
|
|
2530
|
-
];
|
|
2531
|
-
/**
|
|
2532
|
-
* Executes a transformer function based on the first matching predicate,
|
|
2533
|
-
* functioning like a series of `if...else if...` statements. It sequentially
|
|
2534
|
-
* evaluates each case and, upon finding a truthy predicate, runs the
|
|
2535
|
-
* corresponding transformer, and returns, ignoring any further cases, even if
|
|
2536
|
-
* they would match.
|
|
2537
|
-
*
|
|
2538
|
-
* !IMPORTANT! - Unlike similar implementations in frameworks like Lodash and
|
|
2539
|
-
* Ramda, this implementation does **NOT** return a default/fallback
|
|
2540
|
-
* `undefined` value when none of the cases match; and instead will **throw** an
|
|
2541
|
-
* exception in those cases.
|
|
2542
|
-
* To add a default case use the `conditional.defaultCase` helper as the final
|
|
2543
|
-
* case of your implementation. By default it returns `undefined`, but could be
|
|
2544
|
-
* provided a transformer in order to return something else.
|
|
2545
|
-
*
|
|
2546
|
-
* Due to TypeScript's inability to infer the result of negating a type-
|
|
2547
|
-
* predicate we can't refine the types used in subsequent cases based on
|
|
2548
|
-
* previous conditions. Using a `switch (true)` statement or ternary operators
|
|
2549
|
-
* is recommended for more precise type control when such type narrowing is
|
|
2550
|
-
* needed.
|
|
2551
|
-
*
|
|
2552
|
-
* @param data - The input data to be evaluated against the provided cases.
|
|
2553
|
-
* @param cases - A list of (up to 10) tuples, each defining a case. Each tuple
|
|
2554
|
-
* consists of a predicate (or a type-predicate) and a transformer function that
|
|
2555
|
-
* processes the data if its case matches.
|
|
2556
|
-
* @returns The output of the matched transformer. If no cases match, an
|
|
2557
|
-
* exception is thrown. The return type is a union of the return types of all
|
|
2558
|
-
* provided transformers.
|
|
2559
|
-
* @signature
|
|
2560
|
-
* P.conditional(...cases)(data);
|
|
2561
|
-
* @example
|
|
2562
|
-
* const nameOrId = 3 as string | number;
|
|
2563
|
-
* P.pipe(
|
|
2564
|
-
* nameOrId,
|
|
2565
|
-
* P.conditional(
|
|
2566
|
-
* [P.isString, (name) => `Hello ${name}`],
|
|
2567
|
-
* [P.isNumber, (id) => `Hello ID: ${id}`],
|
|
2568
|
-
* P.conditional.defaultCase(
|
|
2569
|
-
* (something) => `Hello something (${JSON.stringify(something)})`,
|
|
2570
|
-
* ),
|
|
2571
|
-
* ),
|
|
2572
|
-
* ); //=> 'Hello ID: 3'
|
|
2573
|
-
* @dataLast
|
|
2574
|
-
* @category Function
|
|
2575
|
-
*/
|
|
2576
|
-
declare function conditional<T, Return0, Return1 = never, Return2 = never, Return3 = never, Return4 = never, Return5 = never, Return6 = never, Return7 = never, Return8 = never, Return9 = never, Thru0 extends T = T, Thru1 extends T = T, Thru2 extends T = T, Thru3 extends T = T, Thru4 extends T = T, Thru5 extends T = T, Thru6 extends T = T, Thru7 extends T = T, Thru8 extends T = T, Thru9 extends T = T>(case0: Case<T, Return0, Thru0>, case1?: Case<T, Return1, Thru1>, case2?: Case<T, Return2, Thru2>, case3?: Case<T, Return3, Thru3>, case4?: Case<T, Return4, Thru4>, case5?: Case<T, Return5, Thru5>, case6?: Case<T, Return6, Thru6>, case7?: Case<T, Return7, Thru7>, case8?: Case<T, Return8, Thru8>, case9?: Case<T, Return9, Thru9>): (data: T) => Return0 | Return1 | Return2 | Return3 | Return4 | Return5 | Return6 | Return7 | Return8 | Return9;
|
|
2577
|
-
/**
|
|
2578
|
-
* Executes a transformer function based on the first matching predicate,
|
|
2579
|
-
* functioning like a series of `if...else if...` statements. It sequentially
|
|
2580
|
-
* evaluates each case and, upon finding a truthy predicate, runs the
|
|
2581
|
-
* corresponding transformer, and returns, ignoring any further cases, even if
|
|
2582
|
-
* they would match.
|
|
2583
|
-
*
|
|
2584
|
-
* !IMPORTANT! - Unlike similar implementations in frameworks like Lodash and
|
|
2585
|
-
* Ramda, this implementation does **NOT** return a default/fallback
|
|
2586
|
-
* `undefined` value when none of the cases match; and instead will **throw** an
|
|
2587
|
-
* exception in those cases.
|
|
2588
|
-
* To add a default case use the `conditional.defaultCase` helper as the final
|
|
2589
|
-
* case of your implementation. By default it returns `undefined`, but could be
|
|
2590
|
-
* provided a transformer in order to return something else.
|
|
2591
|
-
*
|
|
2592
|
-
* Due to TypeScript's inability to infer the result of negating a type-
|
|
2593
|
-
* predicate we can't refine the types used in subsequent cases based on
|
|
2594
|
-
* previous conditions. Using a `switch (true)` statement or ternary operators
|
|
2595
|
-
* is recommended for more precise type control when such type narrowing is
|
|
2596
|
-
* needed.
|
|
2597
|
-
*
|
|
2598
|
-
* @param data - The input data to be evaluated against the provided cases.
|
|
2599
|
-
* @param cases - A list of (up to 10) tuples, each defining a case. Each tuple
|
|
2600
|
-
* consists of a predicate (or a type-predicate) and a transformer function that
|
|
2601
|
-
* processes the data if its case matches.
|
|
2602
|
-
* @returns The output of the matched transformer. If no cases match, an
|
|
2603
|
-
* exception is thrown. The return type is a union of the return types of all
|
|
2604
|
-
* provided transformers.
|
|
2605
|
-
* @signature
|
|
2606
|
-
* P.conditional(data, ...cases);
|
|
2607
|
-
* @example
|
|
2608
|
-
* const nameOrId = 3 as string | number;
|
|
2609
|
-
* P.conditional(
|
|
2610
|
-
* nameOrId,
|
|
2611
|
-
* [P.isString, (name) => `Hello ${name}`],
|
|
2612
|
-
* [P.isNumber, (id) => `Hello ID: ${id}`],
|
|
2613
|
-
* P.conditional.defaultCase(
|
|
2614
|
-
* (something) => `Hello something (${JSON.stringify(something)})`,
|
|
2615
|
-
* ),
|
|
2616
|
-
* ); //=> 'Hello ID: 3'
|
|
2617
|
-
* @dataFirst
|
|
2618
|
-
* @category Function
|
|
2619
|
-
*/
|
|
2620
|
-
declare function conditional<T, Return0, Return1 = never, Return2 = never, Return3 = never, Return4 = never, Return5 = never, Return6 = never, Return7 = never, Return8 = never, Return9 = never, Thru0 extends T = T, Thru1 extends T = T, Thru2 extends T = T, Thru3 extends T = T, Thru4 extends T = T, Thru5 extends T = T, Thru6 extends T = T, Thru7 extends T = T, Thru8 extends T = T, Thru9 extends T = T>(data: T, case0: Case<T, Return0, Thru0>, case1?: Case<T, Return1, Thru1>, case2?: Case<T, Return2, Thru2>, case3?: Case<T, Return3, Thru3>, case4?: Case<T, Return4, Thru4>, case5?: Case<T, Return5, Thru5>, case6?: Case<T, Return6, Thru6>, case7?: Case<T, Return7, Thru7>, case8?: Case<T, Return8, Thru8>, case9?: Case<T, Return9, Thru9>): Return0 | Return1 | Return2 | Return3 | Return4 | Return5 | Return6 | Return7 | Return8 | Return9;
|
|
2621
|
-
declare namespace conditional {
|
|
2622
|
-
/**
|
|
2623
|
-
* A simplified case that accepts all data. Put this as the last case to
|
|
2624
|
-
* prevent an exception from being thrown when none of the previous cases
|
|
2625
|
-
* match.
|
|
2626
|
-
* If this is not the last case it will short-circuit anything after it.
|
|
2627
|
-
* @param then - You only need to provide the transformer, the predicate is
|
|
2628
|
-
* implicit. @default () => undefined, which is how Lodash and Ramda handle
|
|
2629
|
-
* the final fallback case.
|
|
2630
|
-
*/
|
|
2631
|
-
function defaultCase<In>(then?: (data: In) => unknown): readonly [() => boolean, (data: In) => unknown];
|
|
2632
|
-
}
|
|
2633
|
-
|
|
2634
|
-
/**
|
|
2635
|
-
* Creates a data-last pipe function. First function must be always annotated. Other functions are automatically inferred.
|
|
2636
|
-
* @signature
|
|
2637
|
-
* P.createPipe(op1, op2, op3)(data);
|
|
2638
|
-
* @example
|
|
2639
|
-
* P.createPipe(
|
|
2640
|
-
* (x: number) => x * 2,
|
|
2641
|
-
* x => x * 3
|
|
2642
|
-
* )(1) // => 6
|
|
2643
|
-
* @category Function
|
|
2644
|
-
*/
|
|
2645
|
-
declare function createPipe<A, B>(op1: (input: A) => B): (value: A) => B;
|
|
2646
|
-
declare function createPipe<A, B, C>(op1: (input: A) => B, op2: (input: B) => C): (value: A) => C;
|
|
2647
|
-
declare function createPipe<A, B, C, D>(op1: (input: A) => B, op2: (input: B) => C, op3: (input: C) => D): (value: A) => D;
|
|
2648
|
-
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;
|
|
2649
|
-
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;
|
|
2650
|
-
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;
|
|
2651
|
-
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;
|
|
2652
|
-
|
|
2653
|
-
/**
|
|
2654
|
-
* A function that always returns the param passed to it
|
|
2655
|
-
* @signature
|
|
2656
|
-
* P.identity(data)
|
|
2657
|
-
* @example
|
|
2658
|
-
* P.identity('foo') // => 'foo'
|
|
2659
|
-
* @category Function
|
|
2660
|
-
*/
|
|
2661
|
-
declare function identity<T>(value: T): T;
|
|
2662
|
-
|
|
2663
|
-
/**
|
|
2664
|
-
* A function that returns always `undefined`.
|
|
2665
|
-
* @signature
|
|
2666
|
-
* P.noop()
|
|
2667
|
-
* @example
|
|
2668
|
-
* onSomething(P.noop)
|
|
2669
|
-
* @category Function
|
|
2670
|
-
*/
|
|
2671
|
-
declare function noop(): undefined;
|
|
2672
|
-
|
|
2673
|
-
/**
|
|
2674
|
-
* Creates a function that is restricted to invoking `func` once. Repeat calls to the function return the value of the first invocation.
|
|
2675
|
-
* @param fn the function to wrap
|
|
2676
|
-
* @signature P.once(fn)
|
|
2677
|
-
* @example
|
|
2678
|
-
* const initialize = P.once(createApplication);
|
|
2679
|
-
* initialize();
|
|
2680
|
-
* initialize();
|
|
2681
|
-
* // => `createApplication` is invoked once
|
|
2682
|
-
* @category Function
|
|
2683
|
-
*/
|
|
2684
|
-
declare function once<T>(fn: () => T): () => T;
|
|
2685
|
-
|
|
2686
|
-
interface Debouncer<F extends (...args: any) => unknown, IsNullable extends boolean = true> {
|
|
2687
|
-
/**
|
|
2688
|
-
* The last computed value of the debounced function.
|
|
2689
|
-
*/
|
|
2690
|
-
readonly cachedValue: ReturnType<F> | undefined;
|
|
2691
|
-
/**
|
|
2692
|
-
* Invoke the debounced function.
|
|
2693
|
-
* @param args - same as the args for the debounced function.
|
|
2694
|
-
* @returns - the last computed value of the debounced function with the
|
|
2695
|
-
* latest args provided to it. If `timing` does not include `leading` then the
|
|
2696
|
-
* the function would return `undefined` until the first cool-down period is
|
|
2697
|
-
* over, otherwise the function would always return the return type of the
|
|
2698
|
-
* debounced function.
|
|
2699
|
-
*/
|
|
2700
|
-
readonly call: (...args: Parameters<F>) => ReturnType<F> | (true extends IsNullable ? undefined : never);
|
|
2701
|
-
/**
|
|
2702
|
-
* Cancels any debounced functions without calling them, effectively resetting
|
|
2703
|
-
* the debouncer to the same state it is when initially created.
|
|
2704
|
-
*/
|
|
2705
|
-
readonly cancel: () => void;
|
|
2706
|
-
/**
|
|
2707
|
-
* Similar to `cancel`, but would also trigger the `trailing` invocation if
|
|
2708
|
-
* the debouncer would run one at the end of the cool-down period.
|
|
2709
|
-
*/
|
|
2710
|
-
readonly flush: () => ReturnType<F> | undefined;
|
|
2711
|
-
/**
|
|
2712
|
-
* Is `true` when there is an active cool-down period currently debouncing
|
|
2713
|
-
* invocations.
|
|
2714
|
-
*/
|
|
2715
|
-
readonly isPending: boolean;
|
|
2716
|
-
}
|
|
2717
|
-
interface DebounceOptions {
|
|
2718
|
-
readonly maxWaitMs?: number;
|
|
2719
|
-
readonly waitMs?: number;
|
|
2720
|
-
}
|
|
2721
|
-
/**
|
|
2722
|
-
* Wraps `func` with a debouncer object that "debounces" (delays) invocations of the function during a defined cool-down period (`waitMs`). It can be configured to invoke the function either at the start of the cool-down period, the end of it, or at both ends (`timing`).
|
|
2723
|
-
* It can also be configured to allow invocations during the cool-down period (`maxWaitMs`).
|
|
2724
|
-
* It stores the latest call's arguments so they could be used at the end of the cool-down period when invoking `func` (if configured to invoke the function at the end of the cool-down period).
|
|
2725
|
-
* It stores the value returned by `func` whenever its invoked. This value is returned on every call, and is accessible via the `cachedValue` property of the debouncer. Its important to note that the value might be different from the value that would be returned from running `func` with the current arguments as it is a cached value from a previous invocation.
|
|
2726
|
-
* **Important**: The cool-down period defines the minimum between two invocations, and not the maximum. The period will be **extended** each time a call is made until a full cool-down period has elapsed without any additional calls.
|
|
2727
|
-
* @param func The function to debounce, the returned `call` function will have
|
|
2728
|
-
* the exact same signature.
|
|
2729
|
-
* @param options An object allowing further customization of the debouncer:
|
|
2730
|
-
* - `timing?: 'leading' | 'trailing' |'both'`. The default is `'trailing'`.
|
|
2731
|
-
* `leading` would result in the function being invoked at the start of the
|
|
2732
|
-
* cool-down period; `trailing` would result in the function being invoked at
|
|
2733
|
-
* the end of the cool-down period (using the args from the last call to the
|
|
2734
|
-
* debouncer). When `both` is selected the `trailing` invocation would only
|
|
2735
|
-
* take place if there were more than one call to the debouncer during the
|
|
2736
|
-
* cool-down period. **DEFAULT: 'trailing'**
|
|
2737
|
-
* - `waitMs?: number`. The length of the cool-down period in milliseconds. The
|
|
2738
|
-
* debouncer would wait until this amount of time has passed without **any**
|
|
2739
|
-
* additional calls to the debouncer before triggering the end-of-cool-down-
|
|
2740
|
-
* period event. When this happens, the function would be invoked (if `timing`
|
|
2741
|
-
* isn't `'leading'`) and the debouncer state would be reset. **DEFAULT: 0**
|
|
2742
|
-
* - `maxWaitMs?: number`. The length of time since a debounced call (a call
|
|
2743
|
-
* that the debouncer prevented from being invoked) was made until it would be
|
|
2744
|
-
* invoked. Because the debouncer can be continually triggered and thus never
|
|
2745
|
-
* reach the end of the cool-down period, this allows the function to still
|
|
2746
|
-
* be invoked occasionally. IMPORTANT: This param is ignored when `timing` is
|
|
2747
|
-
* `'leading'`.
|
|
2748
|
-
* @returns a debouncer object. The main function is `call`. In addition to it
|
|
2749
|
-
* the debouncer comes with the following additional functions and properties:
|
|
2750
|
-
* - `cancel` method to cancel delayed `func` invocations
|
|
2751
|
-
* - `flush` method to end the cool-down period immediately.
|
|
2752
|
-
* - `cachedValue` the latest return value of an invocation (if one occurred).
|
|
2753
|
-
* - `isPending` flag to check if there is an inflight cool-down window.
|
|
2754
|
-
* @signature
|
|
2755
|
-
* P.debounce(func, options);
|
|
2756
|
-
* @example
|
|
2757
|
-
* const debouncer = debounce(identity, { timing: 'trailing', waitMs: 1000 });
|
|
2758
|
-
* const result1 = debouncer.call(1); // => undefined
|
|
2759
|
-
* const result2 = debouncer.call(2); // => undefined
|
|
2760
|
-
* // after 1 second
|
|
2761
|
-
* const result3 = debouncer.call(3); // => 2
|
|
2762
|
-
* // after 1 second
|
|
2763
|
-
* debouncer.cachedValue; // => 3
|
|
2764
|
-
* @dataFirst
|
|
2765
|
-
* @category Function
|
|
2766
|
-
* @see https://css-tricks.com/debouncing-throttling-explained-examples/
|
|
2767
|
-
*/
|
|
2768
|
-
declare function debounce<F extends (...args: any) => any>(func: F, options: {
|
|
2769
|
-
readonly timing?: 'trailing';
|
|
2770
|
-
} & DebounceOptions): Debouncer<F>;
|
|
2771
|
-
declare function debounce<F extends (...args: any) => any>(func: F, options: ({
|
|
2772
|
-
readonly timing: 'both';
|
|
2773
|
-
} & DebounceOptions) | ({
|
|
2774
|
-
readonly timing: 'leading';
|
|
2775
|
-
} & Omit<DebounceOptions, 'maxWaitMs'>)): Debouncer<F, false>;
|
|
2776
|
-
|
|
2777
|
-
/**
|
|
2778
|
-
* Perform left-to-right function composition.
|
|
2779
|
-
* @param value The initial value.
|
|
2780
|
-
* @param arguments the list of operations to apply.
|
|
2781
|
-
* @signature P.pipe(data, op1, op2, op3)
|
|
2782
|
-
* @example
|
|
2783
|
-
* P.pipe(
|
|
2784
|
-
* [1, 2, 3, 4],
|
|
2785
|
-
* P.map(x => x * 2),
|
|
2786
|
-
* arr => [arr[0] + arr[1], arr[2] + arr[3]],
|
|
2787
|
-
* ) // => [6, 14]
|
|
2788
|
-
*
|
|
2789
|
-
*
|
|
2790
|
-
* @dataFirst
|
|
2791
|
-
* @category Function
|
|
2792
|
-
*/
|
|
2793
|
-
declare function pipe<A, B>(value: A, op1: (input: A) => B): B;
|
|
2794
|
-
declare function pipe<A, B, C>(value: A, op1: (input: A) => B, op2: (input: B) => C): C;
|
|
2795
|
-
declare function pipe<A, B, C, D>(value: A, op1: (input: A) => B, op2: (input: B) => C, op3: (input: C) => D): D;
|
|
2796
|
-
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;
|
|
2797
|
-
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;
|
|
2798
|
-
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;
|
|
2799
|
-
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;
|
|
2800
|
-
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;
|
|
2801
|
-
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;
|
|
2802
|
-
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;
|
|
2803
|
-
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;
|
|
2804
|
-
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;
|
|
2805
|
-
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;
|
|
2806
|
-
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;
|
|
2807
|
-
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;
|
|
2808
|
-
|
|
2809
|
-
/**
|
|
2810
|
-
* Creates a function with `data-first` and `data-last` signatures.
|
|
2811
|
-
*
|
|
2812
|
-
* `purry` is a dynamic function and it's not type safe. It should be wrapped by a function that have proper typings.
|
|
2813
|
-
* Refer to the example below for correct usage.
|
|
2814
|
-
*
|
|
2815
|
-
* @param fn the function to purry.
|
|
2816
|
-
* @param args the arguments
|
|
2817
|
-
* @signature P.purry(fn, arguments);
|
|
2818
|
-
* @exampleRaw
|
|
2819
|
-
* function _findIndex(array, fn) {
|
|
2820
|
-
* for (let i = 0; i < array.length; i++) {
|
|
2821
|
-
* if (fn(array[i])) {
|
|
2822
|
-
* return i;
|
|
2823
|
-
* }
|
|
2824
|
-
* }
|
|
2825
|
-
* return -1;
|
|
2826
|
-
* }
|
|
2827
|
-
*
|
|
2828
|
-
* // data-first
|
|
2829
|
-
* function findIndex<T>(array: T[], fn: (item: T) => boolean): number;
|
|
2830
|
-
*
|
|
2831
|
-
* // data-last
|
|
2832
|
-
* function findIndex<T>(fn: (item: T) => boolean): (array: T[]) => number;
|
|
2833
|
-
*
|
|
2834
|
-
* function findIndex() {
|
|
2835
|
-
* return P.purry(_findIndex, arguments);
|
|
2836
|
-
* }
|
|
2837
|
-
* @category Function
|
|
2838
|
-
*/
|
|
2839
|
-
declare function purry(fn: any, args: IArguments | ReadonlyArray<any>, lazy?: any): any;
|
|
2840
|
-
|
|
2841
|
-
/**
|
|
2842
|
-
* Delay execution for a given number of milliseconds.
|
|
2843
|
-
*
|
|
2844
|
-
* @param timeout the number of milliseconds to wait
|
|
2845
|
-
* @signature
|
|
2846
|
-
* P.sleep(timeout)
|
|
2847
|
-
* @example
|
|
2848
|
-
* P.sleep(1000) // => Promise<void>
|
|
2849
|
-
* @category Function
|
|
2850
|
-
*/
|
|
2851
|
-
declare function sleep(timeout: number): Promise<void>;
|
|
2852
|
-
|
|
2853
|
-
/**
|
|
2854
|
-
* A function that checks if the passed parameter is an Array and narrows its type accordingly
|
|
2855
|
-
* @param data the variable to check
|
|
2856
|
-
* @signature
|
|
2857
|
-
* P.isArray(data)
|
|
2858
|
-
* @returns true if the passed input is an Array, false otherwise
|
|
2859
|
-
* @example
|
|
2860
|
-
* P.isArray([5]) //=> true
|
|
2861
|
-
* P.isArray([]) //=> true
|
|
2862
|
-
* P.isArray('somethingElse') //=> false
|
|
2863
|
-
* @category Guard
|
|
2864
|
-
*/
|
|
2865
|
-
declare function isArray<T>(data: ReadonlyArray<unknown> | T): data is NarrowedTo<T, ReadonlyArray<unknown>>;
|
|
2866
|
-
|
|
2867
|
-
/**
|
|
2868
|
-
* A function that checks if the passed parameter is a boolean and narrows its type accordingly
|
|
2869
|
-
* @param data the variable to check
|
|
2870
|
-
* @signature
|
|
2871
|
-
* P.isBoolean(data)
|
|
2872
|
-
* @returns true if the passed input is a boolean, false otherwise
|
|
2873
|
-
* @example
|
|
2874
|
-
* P.isBoolean(true) //=> true
|
|
2875
|
-
* P.isBoolean(false) //=> true
|
|
2876
|
-
* P.isBoolean('somethingElse') //=> false
|
|
2877
|
-
* @category Guard
|
|
2878
|
-
*/
|
|
2879
|
-
declare function isBoolean<T>(data: T | boolean): data is NarrowedTo<T, boolean>;
|
|
2880
|
-
|
|
2881
|
-
/**
|
|
2882
|
-
* A function that checks if the passed parameter is a Date and narrows its type accordingly
|
|
2883
|
-
* @param data the variable to check
|
|
2884
|
-
* @signature
|
|
2885
|
-
* P.isDate(data)
|
|
2886
|
-
* @returns true if the passed input is a Date, false otherwise
|
|
2887
|
-
* @example
|
|
2888
|
-
* P.isDate(new Date()) //=> true
|
|
2889
|
-
* P.isDate('somethingElse') //=> false
|
|
2890
|
-
* @category Guard
|
|
2891
|
-
*/
|
|
2892
|
-
declare function isDate(data: unknown): data is Date;
|
|
2893
|
-
|
|
2894
|
-
/**
|
|
2895
|
-
* A function that checks if the passed parameter is defined and narrows its type accordingly.
|
|
2896
|
-
* To test specifically for `undefined` (and not `null`) use the strict variant of this function.
|
|
2897
|
-
* @param data the variable to check
|
|
2898
|
-
* @signature
|
|
2899
|
-
* P.isDefined(data)
|
|
2900
|
-
* P.isDefined.strict(data)
|
|
2901
|
-
* @returns true if the passed input is defined, false otherwise
|
|
2902
|
-
* @example
|
|
2903
|
-
* P.isDefined('string') //=> true
|
|
2904
|
-
* P.isDefined(null) //=> false
|
|
2905
|
-
* P.isDefined(undefined) //=> false
|
|
2906
|
-
* P.isDefined.strict(null) //=> true
|
|
2907
|
-
* P.isDefined.strict(undefined) //=> false
|
|
2908
|
-
* @category Guard
|
|
2909
|
-
* @strict
|
|
2910
|
-
*/
|
|
2911
|
-
declare function isDefined<T>(data: T): data is NonNullable<T>;
|
|
2912
|
-
declare namespace isDefined {
|
|
2913
|
-
function strict<T>(data: T | undefined): data is T;
|
|
2914
|
-
}
|
|
2915
|
-
|
|
2916
|
-
/**
|
|
2917
|
-
* A function that checks if the passed parameter is empty
|
|
2918
|
-
* @param data the variable to check
|
|
2919
|
-
* @signature
|
|
2920
|
-
* P.isEmpty(data)
|
|
2921
|
-
* @returns true if the passed input is empty, false otherwise
|
|
2922
|
-
* @example
|
|
2923
|
-
* P.isEmpty('') //=> true
|
|
2924
|
-
* P.isEmpty([]) //=> true
|
|
2925
|
-
* P.isEmpty({}) //=> true
|
|
2926
|
-
* P.isEmpty('test') //=> false
|
|
2927
|
-
* P.isEmpty([1, 2, 3]) //=> false
|
|
2928
|
-
* P.isEmpty({ length: 0 }) //=> false
|
|
2929
|
-
* @category Function
|
|
2930
|
-
*/
|
|
2931
|
-
declare function isEmpty(data: string): data is '';
|
|
2932
|
-
declare function isEmpty(data: [] | ReadonlyArray<unknown>): data is [];
|
|
2933
|
-
declare function isEmpty<T extends Readonly<Record<PropertyKey, unknown>>>(data: T): data is Record<keyof T, never>;
|
|
2934
|
-
|
|
2935
|
-
type DefinitelyError<T> = Extract<T, Error> extends never ? Error : Extract<T, Error>;
|
|
2936
|
-
/**
|
|
2937
|
-
* A function that checks if the passed parameter is an Error and narrows its type accordingly
|
|
2938
|
-
* @param data the variable to check
|
|
2939
|
-
* @signature
|
|
2940
|
-
* P.isError(data)
|
|
2941
|
-
* @returns true if the passed input is an Error, false otherwise
|
|
2942
|
-
* @example
|
|
2943
|
-
* P.isError(new Error('message')) //=> true
|
|
2944
|
-
* P.isError('somethingElse') //=> false
|
|
2945
|
-
* @category Guard
|
|
2946
|
-
*/
|
|
2947
|
-
declare function isError<T>(data: Error | T): data is DefinitelyError<T>;
|
|
2948
|
-
|
|
2949
|
-
type DefinitelyFunction<T> = Extract<T, Function> extends never ? Function : Extract<T, Function>;
|
|
2950
|
-
/**
|
|
2951
|
-
* A function that checks if the passed parameter is a Function and narrows its type accordingly
|
|
2952
|
-
* @param data the variable to check
|
|
2953
|
-
* @signature
|
|
2954
|
-
* P.isFunction(data)
|
|
2955
|
-
* @returns true if the passed input is a Function, false otherwise
|
|
2956
|
-
* @example
|
|
2957
|
-
* P.isFunction(() => {}) //=> true
|
|
2958
|
-
* P.isFunction('somethingElse') //=> false
|
|
2959
|
-
* @category Guard
|
|
2960
|
-
*/
|
|
2961
|
-
declare function isFunction<T>(data: Function | T): data is DefinitelyFunction<T>;
|
|
2962
|
-
|
|
2963
|
-
/**
|
|
2964
|
-
* A function that checks if the passed parameter is Nil (null or undefined) and narrows its type accordingly
|
|
2965
|
-
* @param data the variable to check
|
|
2966
|
-
* @signature
|
|
2967
|
-
* P.isNil(data)
|
|
2968
|
-
* @returns true if the passed input is Nil (null or undefined), false otherwise
|
|
2969
|
-
* @example
|
|
2970
|
-
* P.isNil(undefined) //=> true
|
|
2971
|
-
* P.isNil(null) //=> true
|
|
2972
|
-
* P.isNil('somethingElse') //=> false
|
|
2973
|
-
* @category Guard
|
|
2974
|
-
*/
|
|
2975
|
-
declare function isNil<T>(data: T): data is Extract<T, null | undefined>;
|
|
2976
|
-
|
|
2977
|
-
/**
|
|
2978
|
-
* A function that checks if the passed parameter is not `null` and narrows its type accordingly.
|
|
2979
|
-
* Notice that `undefined` is not null!
|
|
2980
|
-
* @param data the variable to check
|
|
2981
|
-
* @signature
|
|
2982
|
-
* P.isNonNull(data)
|
|
2983
|
-
* @returns true if the passed input is defined, false otherwise
|
|
2984
|
-
* @example
|
|
2985
|
-
* P.isNonNull('string') //=> true
|
|
2986
|
-
* P.isNonNull(null) //=> false
|
|
2987
|
-
* P.isNonNull(undefined) //=> true
|
|
2988
|
-
* @category Guard
|
|
2989
|
-
*/
|
|
2990
|
-
declare function isNonNull<T>(data: T | null): data is T;
|
|
2991
|
-
|
|
2992
|
-
/**
|
|
2993
|
-
* A function that takes a guard function as predicate and returns a guard that negates it
|
|
2994
|
-
* @param predicate the guard function to negate
|
|
2995
|
-
* @signature
|
|
2996
|
-
* P.isNot(P.isTruthy)(data)
|
|
2997
|
-
* @returns function A guard function
|
|
2998
|
-
* @example
|
|
2999
|
-
* P.isNot(P.isTruthy)(false) //=> true
|
|
3000
|
-
* P.isNot(P.isTruthy)(true) //=> false
|
|
3001
|
-
* @dataLast
|
|
3002
|
-
* @category Guard
|
|
3003
|
-
*/
|
|
3004
|
-
declare function isNot<T, S extends T>(predicate: (data: T) => data is S): (data: T) => data is Exclude<T, S>;
|
|
3005
|
-
declare function isNot<T>(predicate: (data: T) => any): (data: T) => boolean;
|
|
3006
|
-
|
|
3007
|
-
/**
|
|
3008
|
-
* A function that checks if the passed parameter is a number and narrows its type accordingly
|
|
3009
|
-
* @param data the variable to check
|
|
3010
|
-
* @signature
|
|
3011
|
-
* P.isNumber(data)
|
|
3012
|
-
* @returns true if the passed input is a number, false otherwise
|
|
3013
|
-
* @example
|
|
3014
|
-
* P.isNumber(1) //=> true
|
|
3015
|
-
* P.isNumber('notANumber') //=> false
|
|
3016
|
-
* @category Guard
|
|
3017
|
-
*/
|
|
3018
|
-
declare function isNumber<T>(data: T | number): data is NarrowedTo<T, number>;
|
|
3019
|
-
|
|
3020
|
-
/**
|
|
3021
|
-
* Checks if `data` is a "plain" object. A plain object is defined as an object with string keys and values of any type, including primitives, other objects, functions, classes, etc (aka struct/shape/record/simple). Technically, a plain object is one whose prototype is either `Object.prototype` or `null`, ensuring it does not inherit properties or methods from other object types.
|
|
3022
|
-
*
|
|
3023
|
-
* This function is narrower in scope than `isObjectType`, which accepts any entity considered an `"object"` by JavaScript's `typeof`.
|
|
3024
|
-
*
|
|
3025
|
-
* Note that Maps, Arrays, and Sets are not considered plain objects and would return `false`.
|
|
3026
|
-
*
|
|
3027
|
-
* @param data - The variable to check.
|
|
3028
|
-
* @returns - The input type, narrowed to only plain objects.
|
|
3029
|
-
* @signature
|
|
3030
|
-
* P.isObject(data)
|
|
3031
|
-
* @example
|
|
3032
|
-
* // true
|
|
3033
|
-
* P.isObject({}) //=> true
|
|
3034
|
-
* P.isObject({ a: 123 }) //=> true
|
|
3035
|
-
*
|
|
3036
|
-
* // false
|
|
3037
|
-
* P.isObject([]) //=> false
|
|
3038
|
-
* P.isObject(Promise.resolve("something")) //=> false
|
|
3039
|
-
* P.isObject(new Date()) //=> false
|
|
3040
|
-
* P.isObject(new Error("error")) //=> false
|
|
3041
|
-
* P.isObject('somethingElse') //=> false
|
|
3042
|
-
* P.isObject(null) //=> false
|
|
3043
|
-
* @category Guard
|
|
3044
|
-
*/
|
|
3045
|
-
declare function isObject<T>(data: Record<PropertyKey, unknown> | T): data is NarrowedTo<T, Record<PropertyKey, unknown>>;
|
|
3046
|
-
|
|
3047
|
-
/**
|
|
3048
|
-
* A function that checks if the passed parameter is a Promise and narrows its type accordingly
|
|
3049
|
-
* @param data the variable to check
|
|
3050
|
-
* @signature
|
|
3051
|
-
* P.isPromise(data)
|
|
3052
|
-
* @returns true if the passed input is a Promise, false otherwise
|
|
3053
|
-
* @example
|
|
3054
|
-
* P.isPromise(Promise.resolve(5)) //=> true
|
|
3055
|
-
* P.isPromise(Promise.reject(5)) //=> true
|
|
3056
|
-
* P.isPromise('somethingElse') //=> false
|
|
3057
|
-
* @category Guard
|
|
3058
|
-
*/
|
|
3059
|
-
declare function isPromise<T, S>(data: Promise<T> | S): data is Promise<T>;
|
|
3060
|
-
|
|
3061
|
-
/**
|
|
3062
|
-
* A function that checks if the passed parameter is a string and narrows its type accordingly
|
|
3063
|
-
* @param data the variable to check
|
|
3064
|
-
* @signature
|
|
3065
|
-
* P.isString(data)
|
|
3066
|
-
* @returns true if the passed input is a string, false otherwise
|
|
3067
|
-
* @example
|
|
3068
|
-
* P.isString('string') //=> true
|
|
3069
|
-
* P.isString(1) //=> false
|
|
3070
|
-
* @category Guard
|
|
3071
|
-
*/
|
|
3072
|
-
declare function isString<T>(data: T | string): data is NarrowedTo<T, string>;
|
|
3073
|
-
|
|
3074
|
-
/**
|
|
3075
|
-
* A function that checks if the passed parameter is a symbol and narrows its type accordingly
|
|
3076
|
-
* @param data the variable to check
|
|
3077
|
-
* @signature
|
|
3078
|
-
* P.isSymbol(data)
|
|
3079
|
-
* @returns true if the passed input is a symbol, false otherwise
|
|
3080
|
-
* @example
|
|
3081
|
-
* P.isSymbol(Symbol('foo')) //=> true
|
|
3082
|
-
* P.isSymbol(1) //=> false
|
|
3083
|
-
* @category Guard
|
|
3084
|
-
*/
|
|
3085
|
-
declare function isSymbol<T>(data: T | symbol): data is NarrowedTo<T, symbol>;
|
|
3086
|
-
|
|
3087
|
-
/**
|
|
3088
|
-
* A function that checks if the passed parameter is truthy and narrows its type accordingly
|
|
3089
|
-
* @param data the variable to check
|
|
3090
|
-
* @signature
|
|
3091
|
-
* P.isTruthy(data)
|
|
3092
|
-
* @returns true if the passed input is truthy, false otherwise
|
|
3093
|
-
* @example
|
|
3094
|
-
* P.isTruthy('somethingElse') //=> true
|
|
3095
|
-
* P.isTruthy(null) //=> false
|
|
3096
|
-
* P.isTruthy(undefined) //=> false
|
|
3097
|
-
* P.isTruthy(false) //=> false
|
|
3098
|
-
* P.isTruthy(0) //=> false
|
|
3099
|
-
* P.isTruthy('') //=> false
|
|
3100
|
-
* @category Guard
|
|
3101
|
-
*/
|
|
3102
|
-
declare function isTruthy<T>(data: T): data is Exclude<T, '' | 0 | false | null | undefined>;
|
|
3103
|
-
|
|
3104
|
-
/**
|
|
3105
|
-
* Adds two numbers.
|
|
3106
|
-
* @param value The number.
|
|
3107
|
-
* @param addend The number to add to the value.
|
|
3108
|
-
* @signature
|
|
3109
|
-
* P.add(value, addend);
|
|
3110
|
-
* @example
|
|
3111
|
-
* P.add(10, 5) // => 15
|
|
3112
|
-
* P.add(10, -5) // => 5
|
|
3113
|
-
* P.reduce([1, 2, 3, 4], P.add, 0) // => 10
|
|
3114
|
-
* @dataFirst
|
|
3115
|
-
* @category Number
|
|
3116
|
-
*/
|
|
3117
|
-
declare function add(value: number, addend: number): number;
|
|
3118
|
-
/**
|
|
3119
|
-
* Adds two numbers.
|
|
3120
|
-
* @param value The number.
|
|
3121
|
-
* @param addend The number to add to the value.
|
|
3122
|
-
* @signature
|
|
3123
|
-
* P.add(addend)(value);
|
|
3124
|
-
* @example
|
|
3125
|
-
* P.add(5)(10) // => 15
|
|
3126
|
-
* P.add(-5)(10) // => 5
|
|
3127
|
-
* P.map([1, 2, 3, 4], P.add(1)) // => [2, 3, 4, 5]
|
|
3128
|
-
* @dataLast
|
|
3129
|
-
* @category Number
|
|
3130
|
-
*/
|
|
3131
|
-
declare function add(addend: number): (value: number) => number;
|
|
3132
|
-
|
|
3133
|
-
/**
|
|
3134
|
-
* Rounds up a given number to a specific precision.
|
|
3135
|
-
* If you'd like to round up to an integer (i.e. use this function with constant `precision === 0`),
|
|
3136
|
-
* use `Math.ceil` instead, as it won't incur the additional library overhead.
|
|
3137
|
-
* @param value The number to round up.
|
|
3138
|
-
* @param precision The precision to round up to. Must be an integer between -15 and 15.
|
|
3139
|
-
* @signature
|
|
3140
|
-
* P.ceil(value, precision);
|
|
3141
|
-
* @example
|
|
3142
|
-
* P.ceil(123.9876, 3) // => 123.988
|
|
3143
|
-
* P.ceil(483.22243, 1) // => 483.3
|
|
3144
|
-
* P.ceil(8541, -1) // => 8550
|
|
3145
|
-
* P.ceil(456789, -3) // => 457000
|
|
3146
|
-
* @dataFirst
|
|
3147
|
-
* @category Number
|
|
3148
|
-
*/
|
|
3149
|
-
declare function ceil(value: number, precision: number): number;
|
|
3150
|
-
/**
|
|
3151
|
-
* Rounds up a given number to a specific precision.
|
|
3152
|
-
* If you'd like to round up to an integer (i.e. use this function with constant `precision === 0`),
|
|
3153
|
-
* use `Math.ceil` instead, as it won't incur the additional library overhead.
|
|
3154
|
-
* @param value The number to round up.
|
|
3155
|
-
* @param precision The precision to round up to. Must be an integer between -15 and 15.
|
|
3156
|
-
* @signature
|
|
3157
|
-
* P.ceil(precision)(value);
|
|
3158
|
-
* @example
|
|
3159
|
-
* P.ceil(3)(123.9876) // => 123.988
|
|
3160
|
-
* P.ceil(1)(483.22243) // => 483.3
|
|
3161
|
-
* P.ceil(-1)(8541) // => 8550
|
|
3162
|
-
* P.ceil(-3)(456789) // => 457000
|
|
3163
|
-
* @dataLast
|
|
3164
|
-
* @category Number
|
|
3165
|
-
*/
|
|
3166
|
-
declare function ceil(precision: number): (value: number) => number;
|
|
3167
|
-
|
|
3168
|
-
/**
|
|
3169
|
-
* Clamp the given value within the inclusive min and max bounds.
|
|
3170
|
-
* @param value the number
|
|
3171
|
-
* @param limits the bounds limits
|
|
3172
|
-
* @param limits.min the minimal bounds limits
|
|
3173
|
-
* @param limits.max the maximal bounds limits
|
|
3174
|
-
* @signature
|
|
3175
|
-
* P.clamp(value, { min, max });
|
|
3176
|
-
* @example
|
|
3177
|
-
* clamp(10, { min: 20 }) // => 20
|
|
3178
|
-
* clamp(10, { max: 5 }) // => 5
|
|
3179
|
-
* clamp(10, { max: 20, min: 5 }) // => 10
|
|
3180
|
-
* @dataFirst
|
|
3181
|
-
* @category Number
|
|
3182
|
-
*/
|
|
3183
|
-
declare function clamp(value: number, limits: {
|
|
3184
|
-
max?: number;
|
|
3185
|
-
min?: number;
|
|
3186
|
-
}): number;
|
|
3187
|
-
/**
|
|
3188
|
-
* Clamp the given value within the inclusive min and max bounds.
|
|
3189
|
-
* @param limits the bounds limits
|
|
3190
|
-
* @param limits.min the minimal bounds limits
|
|
3191
|
-
* @param limits.max the maximal bounds limits
|
|
3192
|
-
* @signature
|
|
3193
|
-
* P.clamp({ min, max })(value);
|
|
3194
|
-
* @example
|
|
3195
|
-
* clamp({ min: 20 })(10) // => 20
|
|
3196
|
-
* clamp({ max: 5 })(10) // => 5
|
|
3197
|
-
* clamp({ max: 20, min: 5 })(10) // => 10
|
|
3198
|
-
* @dataLast
|
|
3199
|
-
* @category Number
|
|
3200
|
-
*/
|
|
3201
|
-
declare function clamp(limits: {
|
|
3202
|
-
max?: number;
|
|
3203
|
-
min?: number;
|
|
3204
|
-
}): (value: number) => number;
|
|
3205
|
-
|
|
3206
|
-
/**
|
|
3207
|
-
* Divides two numbers.
|
|
3208
|
-
* @param value The number.
|
|
3209
|
-
* @param divisor The number to divide the value by.
|
|
3210
|
-
* @signature
|
|
3211
|
-
* P.divide(value, divisor);
|
|
3212
|
-
* @example
|
|
3213
|
-
* P.divide(12, 3) // => 4
|
|
3214
|
-
* P.reduce([1, 2, 3, 4], P.divide, 24) // => 1
|
|
3215
|
-
* @dataFirst
|
|
3216
|
-
* @category Number
|
|
3217
|
-
*/
|
|
3218
|
-
declare function divide(value: number, divisor: number): number;
|
|
3219
|
-
/**
|
|
3220
|
-
* Divides two numbers.
|
|
3221
|
-
* @param value The number.
|
|
3222
|
-
* @param divisor The number to divide the value by.
|
|
3223
|
-
* @signature
|
|
3224
|
-
* P.divide(divisor)(value);
|
|
3225
|
-
* @example
|
|
3226
|
-
* P.divide(3)(12) // => 4
|
|
3227
|
-
* P.map([2, 4, 6, 8], P.divide(2)) // => [1, 2, 3, 4]
|
|
3228
|
-
* @dataLast
|
|
3229
|
-
* @category Number
|
|
3230
|
-
*/
|
|
3231
|
-
declare function divide(divisor: number): (value: number) => number;
|
|
3232
|
-
|
|
3233
|
-
/**
|
|
3234
|
-
* Rounds down a given number to a specific precision.
|
|
3235
|
-
* If you'd like to round down to an integer (i.e. use this function with constant `precision === 0`),
|
|
3236
|
-
* use `Math.floor` instead, as it won't incur the additional library overhead.
|
|
3237
|
-
* @param value The number to round down.
|
|
3238
|
-
* @param precision The precision to round down to. Must be an integer between -15 and 15.
|
|
3239
|
-
* @signature
|
|
3240
|
-
* P.floor(value, precision);
|
|
3241
|
-
* @example
|
|
3242
|
-
* P.floor(123.9876, 3) // => 123.987
|
|
3243
|
-
* P.floor(483.22243, 1) // => 483.2
|
|
3244
|
-
* P.floor(8541, -1) // => 8540
|
|
3245
|
-
* P.floor(456789, -3) // => 456000
|
|
3246
|
-
* @dataFirst
|
|
3247
|
-
* @category Number
|
|
3248
|
-
*/
|
|
3249
|
-
declare function floor(value: number, precision: number): number;
|
|
3250
|
-
/**
|
|
3251
|
-
* Rounds down a given number to a specific precision.
|
|
3252
|
-
* If you'd like to round down to an integer (i.e. use this function with constant `precision === 0`),
|
|
3253
|
-
* use `Math.floor` instead, as it won't incur the additional library overhead.
|
|
3254
|
-
* @param value The number to round down.
|
|
3255
|
-
* @param precision The precision to round down to. Must be an integer between -15 and 15.
|
|
3256
|
-
* @signature
|
|
3257
|
-
* P.floor(precision)(value);
|
|
3258
|
-
* @example
|
|
3259
|
-
* P.floor(3)(123.9876) // => 123.987
|
|
3260
|
-
* P.floor(1)(483.22243) // => 483.2
|
|
3261
|
-
* P.floor(-1)(8541) // => 8540
|
|
3262
|
-
* P.floor(-3)(456789) // => 456000
|
|
3263
|
-
* @dataLast
|
|
3264
|
-
* @category Number
|
|
3265
|
-
*/
|
|
3266
|
-
declare function floor(precision: number): (value: number) => number;
|
|
3267
|
-
|
|
3268
|
-
/**
|
|
3269
|
-
* Multiplies two numbers.
|
|
3270
|
-
* @param value The number.
|
|
3271
|
-
* @param multiplicand The number to multiply the value by.
|
|
3272
|
-
* @signature
|
|
3273
|
-
* P.multiply(value, multiplicand);
|
|
3274
|
-
* @example
|
|
3275
|
-
* P.multiply(3, 4) // => 12
|
|
3276
|
-
* P.reduce([1, 2, 3, 4], P.multiply, 1) // => 24
|
|
3277
|
-
* @dataFirst
|
|
3278
|
-
* @category Number
|
|
3279
|
-
*/
|
|
3280
|
-
declare function multiply(value: number, multiplicand: number): number;
|
|
3281
|
-
/**
|
|
3282
|
-
* Multiplies two numbers.
|
|
3283
|
-
* @param value The number.
|
|
3284
|
-
* @param multiplicand The number to multiply the value by.
|
|
3285
|
-
* @signature
|
|
3286
|
-
* P.multiply(multiplicand)(value);
|
|
3287
|
-
* @example
|
|
3288
|
-
* P.multiply(4)(3) // => 12
|
|
3289
|
-
* P.map([1, 2, 3, 4], P.multiply(2)) // => [2, 4, 6, 8]
|
|
3290
|
-
* @dataLast
|
|
3291
|
-
* @category Number
|
|
3292
|
-
*/
|
|
3293
|
-
declare function multiply(multiplicand: number): (value: number) => number;
|
|
3294
|
-
|
|
3295
|
-
/**
|
|
3296
|
-
* Rounds a given number to a specific precision.
|
|
3297
|
-
* If you'd like to round to an integer (i.e. use this function with constant `precision === 0`),
|
|
3298
|
-
* use `Math.round` instead, as it won't incur the additional library overhead.
|
|
3299
|
-
* @param value The number to round.
|
|
3300
|
-
* @param precision The precision to round to. Must be an integer between -15 and 15.
|
|
3301
|
-
* @signature
|
|
3302
|
-
* P.round(value, precision);
|
|
3303
|
-
* @example
|
|
3304
|
-
* P.round(123.9876, 3) // => 123.988
|
|
3305
|
-
* P.round(483.22243, 1) // => 483.2
|
|
3306
|
-
* P.round(8541, -1) // => 8540
|
|
3307
|
-
* P.round(456789, -3) // => 457000
|
|
3308
|
-
* @dataFirst
|
|
3309
|
-
* @category Number
|
|
3310
|
-
*/
|
|
3311
|
-
declare function round(value: number, precision: number): number;
|
|
3312
|
-
/**
|
|
3313
|
-
* Rounds a given number to a specific precision.
|
|
3314
|
-
* If you'd like to round to an integer (i.e. use this function with constant `precision === 0`),
|
|
3315
|
-
* use `Math.round` instead, as it won't incur the additional library overhead.
|
|
3316
|
-
* @param value The number to round.
|
|
3317
|
-
* @param precision The precision to round to. Must be an integer between -15 and 15.
|
|
3318
|
-
* @signature
|
|
3319
|
-
* P.round(precision)(value);
|
|
3320
|
-
* @example
|
|
3321
|
-
* P.round(3)(123.9876) // => 123.988
|
|
3322
|
-
* P.round(1)(483.22243) // => 483.2
|
|
3323
|
-
* P.round(-1)(8541) // => 8540
|
|
3324
|
-
* P.round(-3)(456789) // => 457000
|
|
3325
|
-
* @dataLast
|
|
3326
|
-
* @category Number
|
|
3327
|
-
*/
|
|
3328
|
-
declare function round(precision: number): (value: number) => number;
|
|
3329
|
-
|
|
3330
|
-
/**
|
|
3331
|
-
* Subtracts two numbers.
|
|
3332
|
-
* @param value The number.
|
|
3333
|
-
* @param subtrahend The number to subtract from the value.
|
|
3334
|
-
* @signature
|
|
3335
|
-
* P.subtract(value, subtrahend);
|
|
3336
|
-
* @example
|
|
3337
|
-
* P.subtract(10, 5) // => 5
|
|
3338
|
-
* P.subtract(10, -5) // => 15
|
|
3339
|
-
* R.reduce([1, 2, 3, 4], P.subtract, 20) // => 10
|
|
3340
|
-
* @dataFirst
|
|
3341
|
-
* @category Number
|
|
3342
|
-
*/
|
|
3343
|
-
declare function subtract(value: number, subtrahend: number): number;
|
|
3344
|
-
/**
|
|
3345
|
-
* Subtracts two numbers.
|
|
3346
|
-
* @param value The number.
|
|
3347
|
-
* @param subtrahend The number to subtract from the value.
|
|
3348
|
-
* @signature
|
|
3349
|
-
* P.subtract(subtrahend)(value);
|
|
3350
|
-
* @example
|
|
3351
|
-
* P.subtract(5)(10) // => 5
|
|
3352
|
-
* P.subtract(-5)(10) // => 15
|
|
3353
|
-
* P.map([1, 2, 3, 4], P.subtract(1)) // => [0, 1, 2, 3]
|
|
3354
|
-
* @dataLast
|
|
3355
|
-
* @category Number
|
|
3356
|
-
*/
|
|
3357
|
-
declare function subtract(subtrahend: number): (value: number) => number;
|
|
3358
|
-
|
|
3359
|
-
/**
|
|
3360
|
-
* Add a new property to an object.
|
|
3361
|
-
* @param obj the target object
|
|
3362
|
-
* @param prop the property name
|
|
3363
|
-
* @param value the property value
|
|
3364
|
-
* @signature
|
|
3365
|
-
* P.addProp(obj, prop, value)
|
|
3366
|
-
* @example
|
|
3367
|
-
* P.addProp({firstName: 'john'}, 'lastName', 'doe') // => {firstName: 'john', lastName: 'doe'}
|
|
3368
|
-
* @dataFirst
|
|
3369
|
-
* @category Object
|
|
3370
|
-
*/
|
|
3371
|
-
declare function addProp<T extends Record<PropertyKey, any>, K extends string, V>(obj: T, prop: K, value: V): T & {
|
|
3372
|
-
[x in K]: V;
|
|
3373
|
-
};
|
|
3374
|
-
/**
|
|
3375
|
-
* Add a new property to an object.
|
|
3376
|
-
* @param prop the property name
|
|
3377
|
-
* @param value the property value
|
|
3378
|
-
* @signature
|
|
3379
|
-
* P.addProp(prop, value)(obj)
|
|
3380
|
-
* @example
|
|
3381
|
-
* P.addProp('lastName', 'doe')({firstName: 'john'}) // => {firstName: 'john', lastName: 'doe'}
|
|
3382
|
-
* @dataLast
|
|
3383
|
-
* @category Object
|
|
3384
|
-
*/
|
|
3385
|
-
declare function addProp<T extends Record<PropertyKey, any>, K extends string, V>(prop: K, value: V): (obj: T) => T & {
|
|
3386
|
-
[x in K]: V;
|
|
3387
|
-
};
|
|
3388
|
-
|
|
3389
|
-
/**
|
|
3390
|
-
* Creates a deep copy of the value. Supported types: `Array`, `Object`, `Number`, `String`, `Boolean`, `Date`, `RegExp`. Functions are assigned by reference rather than copied.
|
|
3391
|
-
* @param value the object to clone
|
|
3392
|
-
* @category Object
|
|
3393
|
-
* @signature P.clone(value)
|
|
3394
|
-
* @example P.clone({foo: 'bar'}) // {foo: 'bar'}
|
|
3395
|
-
*/
|
|
3396
|
-
declare function clone<T>(value: T): T;
|
|
3397
|
-
|
|
3398
|
-
/**
|
|
3399
|
-
* Returns true if its arguments are equivalent, false otherwise.
|
|
3400
|
-
* NOTE: Doesn't handle cyclical data structures.
|
|
3401
|
-
* @param a the first object to compare
|
|
3402
|
-
* @param b the second object to compare
|
|
3403
|
-
* @signature
|
|
3404
|
-
* P.equals(a, b)
|
|
3405
|
-
* @example
|
|
3406
|
-
* P.equals(1, 1) //=> true
|
|
3407
|
-
* P.equals(1, '1') //=> false
|
|
3408
|
-
* P.equals([1, 2, 3], [1, 2, 3]) //=> true
|
|
3409
|
-
* @dataFirst
|
|
3410
|
-
* @category Object
|
|
3411
|
-
*/
|
|
3412
|
-
declare function equals(a: any, b: any): boolean;
|
|
3413
|
-
/**
|
|
3414
|
-
* Returns true if its arguments are equivalent, false otherwise.
|
|
3415
|
-
* NOTE: Doesn't handle cyclical data structures.
|
|
3416
|
-
* @param a the first object to compare
|
|
3417
|
-
* @signature
|
|
3418
|
-
* P.equals(b)(a)
|
|
3419
|
-
* @example
|
|
3420
|
-
* P.equals(1)(1) //=> true
|
|
3421
|
-
* P.equals('1')(1) //=> false
|
|
3422
|
-
* P.equals([1, 2, 3])([1, 2, 3]) //=> true
|
|
3423
|
-
* @dataLast
|
|
3424
|
-
* @category Object
|
|
3425
|
-
*/
|
|
3426
|
-
declare function equals(a: any): (b: any) => boolean;
|
|
3427
|
-
|
|
3428
|
-
type IndexedIteratee<T extends Record<PropertyKey, any>, K extends keyof T> = (value: T[K], key: K, obj: T) => void;
|
|
3429
|
-
type UnindexedIteratee<T extends Record<PropertyKey, any>> = (value: T[keyof T]) => void;
|
|
3430
|
-
/**
|
|
3431
|
-
* Iterate an object using a defined callback function. The original object is returned.
|
|
3432
|
-
* @param object The object.
|
|
3433
|
-
* @param fn The callback function.
|
|
3434
|
-
* @returns The original object
|
|
3435
|
-
* @signature
|
|
3436
|
-
* P.forEachObj(object, fn)
|
|
3437
|
-
* @example
|
|
3438
|
-
* P.forEachObj({a: 1}, (val) => {
|
|
3439
|
-
* console.log(`${val}`)
|
|
3440
|
-
* }) // "1"
|
|
3441
|
-
* P.forEachObj.indexed({a: 1}, (val, key, obj) => {
|
|
3442
|
-
* console.log(`${key}: ${val}`)
|
|
3443
|
-
* }) // "a: 1"
|
|
3444
|
-
* @dataFirst
|
|
3445
|
-
* @category Object
|
|
3446
|
-
*/
|
|
3447
|
-
declare function forEachObj<T extends Record<PropertyKey, any>>(object: T, fn: UnindexedIteratee<T>): T;
|
|
3448
|
-
/**
|
|
3449
|
-
* Iterate an object using a defined callback function. The original object is returned.
|
|
3450
|
-
* @param fn The callback function.
|
|
3451
|
-
* @signature
|
|
3452
|
-
* P.forEachObj(fn)(object)
|
|
3453
|
-
* @example
|
|
3454
|
-
* P.pipe(
|
|
3455
|
-
* {a: 1},
|
|
3456
|
-
* P.forEachObj((val) => console.log(`${val}`))
|
|
3457
|
-
* ) // "1"
|
|
3458
|
-
* P.pipe(
|
|
3459
|
-
* {a: 1},
|
|
3460
|
-
* P.forEachObj.indexed((val, key) => console.log(`${key}: ${val}`))
|
|
3461
|
-
* ) // "a: 1"
|
|
3462
|
-
* @dataLast
|
|
3463
|
-
* @category Object
|
|
3464
|
-
*/
|
|
3465
|
-
declare function forEachObj<T extends Record<PropertyKey, any>>(fn: UnindexedIteratee<T>): (object: T) => T;
|
|
3466
|
-
declare namespace forEachObj {
|
|
3467
|
-
function indexed<T extends Record<PropertyKey, any>>(object: T, fn: IndexedIteratee<T, keyof T>): T;
|
|
3468
|
-
function indexed<T extends Record<PropertyKey, any>>(fn: IndexedIteratee<T, keyof T>): (object: T) => T;
|
|
3469
|
-
}
|
|
3470
|
-
|
|
3471
|
-
type Entry<Key extends PropertyKey = PropertyKey, Value = unknown> = readonly [
|
|
3472
|
-
key: Key,
|
|
3473
|
-
value: Value
|
|
3474
|
-
];
|
|
3475
|
-
type Strict$2 = <Entries extends IterableContainer<Entry>>(entries: Entries) => StrictOut<Entries>;
|
|
3476
|
-
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';
|
|
3477
|
-
type FromPairsTuple<E, Rest> = E extends Entry ? Record<E[0], E[1]> & StrictOut<Rest> : 'ERROR: Array-like contains a non-entry element';
|
|
3478
|
-
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>;
|
|
3479
|
-
type FromPairsArrayWithLiteralKeys<Entries extends IterableContainer<Entry>> = {
|
|
3480
|
-
[K in AllKeys$1<Entries>]?: ValueForKey<Entries, K>;
|
|
3481
|
-
};
|
|
3482
|
-
type AllKeys$1<Entries extends IterableContainer<Entry>> = Extract<Entries[number], Entry>[0];
|
|
3483
|
-
type ValueForKey<Entries extends IterableContainer<Entry>, K extends PropertyKey> = (Extract<Entries[number], Entry<K>> extends never ? Entries[number] : Extract<Entries[number], Entry<K>>)[1];
|
|
3484
|
-
/**
|
|
3485
|
-
* Creates a new object from an array of tuples by pairing up first and second elements as {[key]: value}.
|
|
3486
|
-
* If a tuple is not supplied for any element in the array, the element will be ignored
|
|
3487
|
-
* If duplicate keys exist, the tuple with the greatest index in the input array will be preferred.
|
|
3488
|
-
*
|
|
3489
|
-
* The strict option supports more sophisticated use-cases like those that would
|
|
3490
|
-
* result when calling the strict `toPairs` function.
|
|
3491
|
-
* @param pairs the list of input tuples
|
|
3492
|
-
* @signature
|
|
3493
|
-
* P.fromPairs(tuples)
|
|
3494
|
-
* P.fromPairs.strict(tuples)
|
|
3495
|
-
* @example
|
|
3496
|
-
* P.fromPairs([['a', 'b'], ['c', 'd']]) // => {a: 'b', c: 'd'} (type: Record<string, string>)
|
|
3497
|
-
* P.fromPairs.strict(['a', 1] as const) // => {a: 1} (type: {a: 1})
|
|
3498
|
-
* @category Object
|
|
3499
|
-
* @strict
|
|
3500
|
-
*/
|
|
3501
|
-
declare function fromPairs<V>(pairs: ReadonlyArray<Entry<number, V>>): Record<number, V>;
|
|
3502
|
-
declare function fromPairs<V>(pairs: ReadonlyArray<Entry<string, V>>): Record<string, V>;
|
|
3503
|
-
declare namespace fromPairs {
|
|
3504
|
-
const strict: Strict$2;
|
|
3505
|
-
}
|
|
3506
|
-
|
|
3507
|
-
type Inverted<T extends object> = T[keyof T] extends PropertyKey ? Record<T[keyof T], keyof T> : never;
|
|
3508
|
-
/**
|
|
3509
|
-
* Returns an object whose keys are values are swapped. If the object contains duplicate values,
|
|
3510
|
-
* subsequent values will overwrite previous values.
|
|
3511
|
-
* @param object the object
|
|
3512
|
-
* @signature
|
|
3513
|
-
* P.invert(object)
|
|
3514
|
-
* @example
|
|
3515
|
-
* P.invert({ a: "d", b: "e", c: "f" }) // => { d: "a", e: "b", f: "c" }
|
|
3516
|
-
* @dataFirst
|
|
3517
|
-
* @category Object
|
|
3518
|
-
* @pipeable
|
|
3519
|
-
*/
|
|
3520
|
-
declare function invert<T extends object>(object: T): Inverted<T>;
|
|
3521
|
-
/**
|
|
3522
|
-
* Returns an object whose keys are values are swapped. If the object contains duplicate values,
|
|
3523
|
-
* subsequent values will overwrite previous values.
|
|
3524
|
-
* @signature
|
|
3525
|
-
* P.invert()(object)
|
|
3526
|
-
* @example
|
|
3527
|
-
* P.pipe({ a: "d", b: "e", c: "f" }, P.invert()); // => { d: "a", e: "b", f: "c" }
|
|
3528
|
-
* @dataLast
|
|
3529
|
-
* @category Object
|
|
3530
|
-
* @pipeable
|
|
3531
|
-
*/
|
|
3532
|
-
declare function invert<T extends object>(): (object: T) => Inverted<T>;
|
|
3533
|
-
|
|
3534
|
-
type Strict$1 = <T extends object>(source: T) => Keys<T>;
|
|
3535
|
-
type Keys<T> = T extends IterableContainer ? ArrayKeys<T> : ObjectKeys<T>;
|
|
3536
|
-
type ArrayKeys<T extends IterableContainer> = {
|
|
3537
|
-
-readonly [Index in keyof T]: Index extends number | string ? `${IsIndexAfterSpread<T, Index> extends true ? number : Index}` : never;
|
|
3538
|
-
};
|
|
3539
|
-
type IsIndexAfterSpread<T extends IterableContainer, Index extends number | string> = IndicesAfterSpread<T> extends never ? false : Index extends `${IndicesAfterSpread<T>}` ? true : false;
|
|
3540
|
-
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'];
|
|
3541
|
-
type ObjectKeys<T> = T extends Record<PropertyKey, never> ? [] : Array<`${Exclude<keyof T, symbol>}`>;
|
|
3542
|
-
/**
|
|
3543
|
-
* Returns a new array containing the keys of the array or object.
|
|
3544
|
-
* @param source Either an array or an object
|
|
3545
|
-
* @signature
|
|
3546
|
-
* P.keys(source)
|
|
3547
|
-
* P.keys.strict(source)
|
|
3548
|
-
* @example
|
|
3549
|
-
* P.keys(['x', 'y', 'z']) // => ['0', '1', '2']
|
|
3550
|
-
* P.keys({ a: 'x', b: 'y', c: 'z' }) // => ['a', 'b', 'c']
|
|
3551
|
-
* P.pipe(
|
|
3552
|
-
* { a: 'x', b: 'y', c: 'z' },
|
|
3553
|
-
* P.keys,
|
|
3554
|
-
* P.first
|
|
3555
|
-
* ) // => 'a'
|
|
3556
|
-
* P.keys.strict({ a: 'x', b: 'y', 5: 'z' } as const ) // => ['a', 'b', '5'], typed Array<'a' | 'b' | '5'>
|
|
3557
|
-
* @pipeable
|
|
3558
|
-
* @strict
|
|
3559
|
-
* @category Object
|
|
3560
|
-
*/
|
|
3561
|
-
declare function keys(source: ArrayLike<unknown> | Record<PropertyKey, unknown>): Array<string>;
|
|
3562
|
-
declare namespace keys {
|
|
3563
|
-
const strict: Strict$1;
|
|
3564
|
-
}
|
|
3565
|
-
|
|
3566
|
-
/**
|
|
3567
|
-
* Maps keys of `object` and keeps the same values.
|
|
3568
|
-
* @param data the object to map
|
|
3569
|
-
* @param fn the mapping function
|
|
3570
|
-
* @signature
|
|
3571
|
-
* P.mapKeys(object, fn)
|
|
3572
|
-
* @example
|
|
3573
|
-
* P.mapKeys({a: 1, b: 2}, (key, value) => key + value) // => { a1: 1, b2: 2 }
|
|
3574
|
-
* @dataFirst
|
|
3575
|
-
* @category Object
|
|
3576
|
-
*/
|
|
3577
|
-
declare function mapKeys<T, S extends PropertyKey>(data: T, fn: (key: keyof T, value: Required<T>[keyof T]) => S): Record<S, T[keyof T]>;
|
|
3578
|
-
/**
|
|
3579
|
-
* Maps keys of `object` and keeps the same values.
|
|
3580
|
-
* @param fn the mapping function
|
|
3581
|
-
* @signature
|
|
3582
|
-
* P.mapKeys(fn)(object)
|
|
3583
|
-
* @example
|
|
3584
|
-
* P.pipe({a: 1, b: 2}, P.mapKeys((key, value) => key + value)) // => { a1: 1, b2: 2 }
|
|
3585
|
-
* @dataLast
|
|
3586
|
-
* @category Object
|
|
3587
|
-
*/
|
|
3588
|
-
declare function mapKeys<T, S extends PropertyKey>(fn: (key: keyof T, value: Required<T>[keyof T]) => S): (data: T) => Record<S, T[keyof T]>;
|
|
3589
|
-
|
|
3590
|
-
/**
|
|
3591
|
-
* Maps values of `object` and keeps the same keys.
|
|
3592
|
-
* @param data the object to map
|
|
3593
|
-
* @param fn the mapping function
|
|
3594
|
-
* @signature
|
|
3595
|
-
* P.mapValues(object, fn)
|
|
3596
|
-
* @example
|
|
3597
|
-
* P.mapValues({a: 1, b: 2}, (value, key) => value + key) // => {a: '1a', b: '2b'}
|
|
3598
|
-
* @dataFirst
|
|
3599
|
-
* @category Object
|
|
3600
|
-
*/
|
|
3601
|
-
declare function mapValues<T extends Record<PropertyKey, unknown>, S>(data: T, fn: (value: T[ObjectKeys$1<T>], key: ObjectKeys$1<T>) => S): Record<ObjectKeys$1<T>, S>;
|
|
3602
|
-
/**
|
|
3603
|
-
* Maps values of `object` and keeps the same keys.
|
|
3604
|
-
* @param fn the mapping function
|
|
3605
|
-
* @signature
|
|
3606
|
-
* P.mapValues(fn)(object)
|
|
3607
|
-
* @example
|
|
3608
|
-
* P.pipe({a: 1, b: 2}, P.mapValues((value, key) => value + key)) // => {a: '1a', b: '2b'}
|
|
3609
|
-
* @dataLast
|
|
3610
|
-
* @category Object
|
|
3611
|
-
*/
|
|
3612
|
-
declare function mapValues<T extends Record<PropertyKey, unknown>, S>(fn: (value: T[keyof T], key: keyof T) => S): (data: T) => Record<ObjectKeys$1<T>, S>;
|
|
3613
|
-
|
|
3614
|
-
/**
|
|
3615
|
-
* Merges two objects. The same as `Object.assign`.
|
|
3616
|
-
* `b` object will override properties of `a`.
|
|
3617
|
-
* @param a the first object
|
|
3618
|
-
* @param b the second object
|
|
3619
|
-
* @signature
|
|
3620
|
-
* P.merge(a, b)
|
|
3621
|
-
* @example
|
|
3622
|
-
* P.merge({ x: 1, y: 2 }, { y: 10, z: 2 }) // => { x: 1, y: 10, z: 2 }
|
|
3623
|
-
* @dataFirst
|
|
3624
|
-
* @category Object
|
|
3625
|
-
*/
|
|
3626
|
-
declare function merge<A, B>(a: A, b: B): A & B;
|
|
3627
|
-
/**
|
|
3628
|
-
* Merges two objects. The same as `Object.assign`. `b` object will override properties of `a`.
|
|
3629
|
-
* @param b the second object
|
|
3630
|
-
* @signature
|
|
3631
|
-
* P.merge(b)(a)
|
|
3632
|
-
* @example
|
|
3633
|
-
* P.merge({ y: 10, z: 2 })({ x: 1, y: 2 }) // => { x: 1, y: 10, z: 2 }
|
|
3634
|
-
* @dataLast
|
|
3635
|
-
* @category Object
|
|
3636
|
-
*/
|
|
3637
|
-
declare function merge<A, B>(b: B): (a: A) => A & B;
|
|
3638
|
-
|
|
3639
|
-
/**
|
|
3640
|
-
* Merges the `source` object into the `destination` object. The merge is similar to performing `{ ...destination, ... source }` (where disjoint values from each object would be copied as-is, and for any overlapping props the value from `source` would be used); But for *each prop* (`p`), if **both** `destination` and `source` have a **plain-object** as a value, the value would be taken as the result of recursively deepMerging them (`result.p === deepMerge(destination.p, source.p)`).
|
|
3641
|
-
*
|
|
3642
|
-
* @param destination - The object to merge into. In general, this object would have it's values overridden.
|
|
3643
|
-
* @param source - The object to merge from. In general, shared keys would be taken from this object.
|
|
3644
|
-
* @returns - The merged object.
|
|
3645
|
-
* @signature
|
|
3646
|
-
* P.mergeDeep(destination, source)
|
|
3647
|
-
* @example
|
|
3648
|
-
* P.mergeDeep({ foo: 'bar', x: 1 }, { foo: 'baz', y: 2 }) // => { foo: 'baz', x: 1, y: 2 }
|
|
3649
|
-
* @dataFirst
|
|
3650
|
-
* @category Object
|
|
3651
|
-
*/
|
|
3652
|
-
declare function mergeDeep<Destination extends Record<string, unknown>, Source extends Record<string, unknown>>(destination: Destination, source: Source): MergeDeep<Destination, Source>;
|
|
3653
|
-
/**
|
|
3654
|
-
* Merges the `source` object into the `destination` object. The merge is similar to performing `{ ...destination, ... source }` (where disjoint values from each object would be copied as-is, and for any overlapping props the value from `source` would be used); But for *each prop* (`p`), if **both** `destination` and `source` have a **plain-object** as a value, the value would be taken as the result of recursively deepMerging them (`result.p === deepMerge(destination.p, source.p)`).
|
|
3655
|
-
*
|
|
3656
|
-
* @param source - The object to merge from. In general, shared keys would be taken from this object.
|
|
3657
|
-
* @returns - The merged object.
|
|
3658
|
-
* @signature
|
|
3659
|
-
* P.mergeDeep(source)(destination)
|
|
3660
|
-
* @example
|
|
3661
|
-
* P.pipe(
|
|
3662
|
-
* { foo: 'bar', x: 1 },
|
|
3663
|
-
* P.mergeDeep({ foo: 'baz', y: 2 }),
|
|
3664
|
-
* ); // => { foo: 'baz', x: 1, y: 2 }
|
|
3665
|
-
* @dataLast
|
|
3666
|
-
* @category Object
|
|
3667
|
-
*/
|
|
3668
|
-
declare function mergeDeep<Destination extends Record<string, unknown>, Source extends Record<string, unknown>>(source: Source): (target: Destination) => MergeDeep<Destination, Source>;
|
|
3669
|
-
|
|
3670
|
-
/**
|
|
3671
|
-
* Returns a partial copy of an object omitting the keys specified.
|
|
3672
|
-
* @param propNames the property names
|
|
3673
|
-
* @signature
|
|
3674
|
-
* P.omit(propNames)(obj);
|
|
3675
|
-
* @example
|
|
3676
|
-
* P.pipe({ a: 1, b: 2, c: 3, d: 4 }, P.omit(['a', 'd'])) // => { b: 2, c: 3 }
|
|
3677
|
-
* @dataLast
|
|
3678
|
-
* @category Object
|
|
3679
|
-
*/
|
|
3680
|
-
declare function omit<T extends object, K extends keyof T>(propNames: ReadonlyArray<K>): (data: T) => Omit<T, K>;
|
|
3681
|
-
/**
|
|
3682
|
-
* Returns a partial copy of an object omitting the keys specified.
|
|
3683
|
-
* @param data the object
|
|
3684
|
-
* @param propNames the property names
|
|
3685
|
-
* @signature
|
|
3686
|
-
* P.omit(obj, names);
|
|
3687
|
-
* @example
|
|
3688
|
-
* P.omit({ a: 1, b: 2, c: 3, d: 4 }, ['a', 'd']) // => { b: 2, c: 3 }
|
|
3689
|
-
* @dataFirst
|
|
3690
|
-
* @category Object
|
|
3691
|
-
*/
|
|
3692
|
-
declare function omit<T extends object, K extends keyof T>(data: T, propNames: ReadonlyArray<K>): Omit<T, K>;
|
|
3693
|
-
|
|
3694
|
-
/**
|
|
3695
|
-
* Returns a partial copy of an object omitting the keys matching predicate.
|
|
3696
|
-
* @param object the target object
|
|
3697
|
-
* @param fn the predicate
|
|
3698
|
-
* @signature P.omitBy(object, fn)
|
|
3699
|
-
* @example
|
|
3700
|
-
* P.omitBy({a: 1, b: 2, A: 3, B: 4}, (val, key) => key.toUpperCase() === key) // => {a: 1, b: 2}
|
|
3701
|
-
* @dataFirst
|
|
3702
|
-
* @category Object
|
|
3703
|
-
*/
|
|
3704
|
-
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>;
|
|
3705
|
-
/**
|
|
3706
|
-
* Returns a partial copy of an object omitting the keys matching predicate.
|
|
3707
|
-
* @param fn the predicate
|
|
3708
|
-
* @signature P.omitBy(fn)(object)
|
|
3709
|
-
* @example
|
|
3710
|
-
* P.omitBy((val, key) => key.toUpperCase() === key)({a: 1, b: 2, A: 3, B: 4}) // => {a: 1, b: 2}
|
|
3711
|
-
* @dataLast
|
|
3712
|
-
* @category Object
|
|
3713
|
-
*/
|
|
3714
|
-
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>;
|
|
3715
|
-
|
|
3716
|
-
/**
|
|
3717
|
-
* Given a union of indexable types `T`, we derive an indexable type
|
|
3718
|
-
* containing all of the keys of each variant of `T`. If a key is
|
|
3719
|
-
* present in multiple variants of `T`, then the corresponding type in
|
|
3720
|
-
* `Pathable<T>` will be the intersection of all types for that key.
|
|
3721
|
-
* @example
|
|
3722
|
-
* type T1 = Pathable<{a: number} | {a: string; b: boolean}>
|
|
3723
|
-
* // {a: number | string; b: boolean}
|
|
3724
|
-
*
|
|
3725
|
-
* type T2 = Pathable<{a?: {b: string}}
|
|
3726
|
-
* // {a: {b: string} | undefined}
|
|
3727
|
-
*
|
|
3728
|
-
* type T3 = Pathable<{a: string} | number>
|
|
3729
|
-
* // {a: string}
|
|
3730
|
-
*
|
|
3731
|
-
* type T4 = Pathable<{a: number} | {a: string} | {b: boolean}>
|
|
3732
|
-
* // {a: number | string; b: boolean}
|
|
3733
|
-
*
|
|
3734
|
-
* This type lets us answer the questions:
|
|
3735
|
-
* - Given some object of type `T`, what keys might this object have?
|
|
3736
|
-
* - If this object did happen to have a particular key, what values
|
|
3737
|
-
* might that key have?
|
|
3738
|
-
*/
|
|
3739
|
-
type Pathable<T> = {
|
|
3740
|
-
[K in AllKeys<T>]: TypesForKey<T, K>;
|
|
3741
|
-
};
|
|
3742
|
-
type AllKeys<T> = T extends infer I ? keyof I : never;
|
|
3743
|
-
type TypesForKey<T, K extends PropertyKey> = T extends infer I ? K extends keyof I ? I[K] : never : never;
|
|
3744
|
-
type StrictlyRequired<T> = {
|
|
3745
|
-
[K in keyof T]-?: NonNullable<T[K]>;
|
|
3746
|
-
};
|
|
3747
|
-
/**
|
|
3748
|
-
* Given some `A` which is a key of at least one variant of `T`, derive
|
|
3749
|
-
* `T[A]` for the cases where `A` is present in `T`, and `T[A]` is not
|
|
3750
|
-
* null or undefined.
|
|
3751
|
-
*/
|
|
3752
|
-
type PathValue1<T, A extends keyof Pathable<T>> = StrictlyRequired<Pathable<T>>[A];
|
|
3753
|
-
/** All possible options after successfully reaching `T[A]` */
|
|
3754
|
-
type Pathable1<T, A extends keyof Pathable<T>> = Pathable<PathValue1<T, A>>;
|
|
3755
|
-
/** As `PathValue1`, but for `T[A][B]` */
|
|
3756
|
-
type PathValue2<T, A extends keyof Pathable<T>, B extends keyof Pathable1<T, A>> = StrictlyRequired<Pathable1<T, A>>[B];
|
|
3757
|
-
/** As `Pathable1`, but for `T[A][B]` */
|
|
3758
|
-
type Pathable2<T, A extends keyof Pathable<T>, B extends keyof Pathable1<T, A>> = Pathable<PathValue2<T, A, B>>;
|
|
3759
|
-
/** As `PathValue1`, but for `T[A][B][C]` */
|
|
3760
|
-
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];
|
|
3761
|
-
/**
|
|
3762
|
-
* Gets the value at `path` of `object`. If the resolved value is `undefined`, the `defaultValue` is returned in its place.
|
|
3763
|
-
* @param object the target object
|
|
3764
|
-
* @param path the path of the property to get
|
|
3765
|
-
* @param defaultValue the default value
|
|
3766
|
-
* @signature P.pathOr(object, array, defaultValue)
|
|
3767
|
-
* @example
|
|
3768
|
-
* P.pathOr({x: 10}, ['y'], 2) // 2
|
|
3769
|
-
* P.pathOr({y: 10}, ['y'], 2) // 10
|
|
3770
|
-
* @dataFirst
|
|
3771
|
-
* @category Object
|
|
3772
|
-
*/
|
|
3773
|
-
declare function pathOr<T, A extends keyof Pathable<T>>(object: T, path: readonly [A], defaultValue: PathValue1<T, A>): PathValue1<T, A>;
|
|
3774
|
-
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>;
|
|
3775
|
-
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>;
|
|
3776
|
-
/**
|
|
3777
|
-
* Gets the value at `path` of `object`. If the resolved value is `undefined`, the `defaultValue` is returned in its place.
|
|
3778
|
-
* @param path the path of the property to get
|
|
3779
|
-
* @param defaultValue the default value
|
|
3780
|
-
* @signature P.pathOr(array, defaultValue)(object)
|
|
3781
|
-
* @example
|
|
3782
|
-
* P.pipe({x: 10}, P.pathOr(['y'], 2)) // 2
|
|
3783
|
-
* P.pipe({y: 10}, P.pathOr(['y'], 2)) // 10
|
|
3784
|
-
* @dataLast
|
|
3785
|
-
* @category Object
|
|
3786
|
-
*/
|
|
3787
|
-
declare function pathOr<T, A extends keyof Pathable<T>>(path: readonly [A], defaultValue: PathValue1<T, A>): (object: T) => PathValue1<T, A>;
|
|
3788
|
-
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>;
|
|
3789
|
-
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>;
|
|
3790
|
-
|
|
3791
|
-
/**
|
|
3792
|
-
* Creates an object composed of the picked `object` properties.
|
|
3793
|
-
* @param object the target object
|
|
3794
|
-
* @param names the properties names
|
|
3795
|
-
* @signature P.pick(object, [prop1, prop2])
|
|
3796
|
-
* @example
|
|
3797
|
-
* P.pick({ a: 1, b: 2, c: 3, d: 4 }, ['a', 'd']) // => { a: 1, d: 4 }
|
|
3798
|
-
* @dataFirst
|
|
3799
|
-
* @category Object
|
|
3800
|
-
*/
|
|
3801
|
-
declare function pick<T extends object, K extends keyof T>(object: T, names: ReadonlyArray<K>): Pick<T, K>;
|
|
3802
|
-
/**
|
|
3803
|
-
* Creates an object composed of the picked `object` properties.
|
|
3804
|
-
* @param names the properties names
|
|
3805
|
-
* @signature P.pick([prop1, prop2])(object)
|
|
3806
|
-
* @example
|
|
3807
|
-
* P.pipe({ a: 1, b: 2, c: 3, d: 4 }, P.pick(['a', 'd'])) // => { a: 1, d: 4 }
|
|
3808
|
-
* @dataLast
|
|
3809
|
-
* @category Object
|
|
3810
|
-
*/
|
|
3811
|
-
declare function pick<T extends object, K extends keyof T>(names: ReadonlyArray<K>): (object: T) => Pick<T, K>;
|
|
3812
|
-
|
|
3813
|
-
/**
|
|
3814
|
-
* Creates an object composed of the picked `object` properties.
|
|
3815
|
-
* @param object the target object
|
|
3816
|
-
* @param fn the predicate
|
|
3817
|
-
* @signature P.pickBy(object, fn)
|
|
3818
|
-
* @example
|
|
3819
|
-
* P.pickBy({a: 1, b: 2, A: 3, B: 4}, (val, key) => key.toUpperCase() === key) // => {A: 3, B: 4}
|
|
3820
|
-
* @dataFirst
|
|
3821
|
-
* @category Object
|
|
3822
|
-
*/
|
|
3823
|
-
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>;
|
|
3824
|
-
/**
|
|
3825
|
-
* Creates an object composed of the picked `object` properties.
|
|
3826
|
-
* @param fn the predicate
|
|
3827
|
-
* @signature P.pickBy(fn)(object)
|
|
3828
|
-
* @example
|
|
3829
|
-
* P.pickBy((val, key) => key.toUpperCase() === key)({a: 1, b: 2, A: 3, B: 4}) // => {A: 3, B: 4}
|
|
3830
|
-
* @dataLast
|
|
3831
|
-
* @category Object
|
|
3832
|
-
*/
|
|
3833
|
-
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>;
|
|
3834
|
-
|
|
3835
|
-
/**
|
|
3836
|
-
* Gets the value of the given property.
|
|
3837
|
-
* @param propName the property name
|
|
3838
|
-
* @signature P.prop(prop)(object)
|
|
3839
|
-
* @example
|
|
3840
|
-
* P.pipe({foo: 'bar'}, P.prop('foo')) // => 'bar'
|
|
3841
|
-
* @dataLast
|
|
3842
|
-
* @category Object
|
|
3843
|
-
*/
|
|
3844
|
-
declare function prop<T, K extends keyof T>(propName: K): ({ [propName]: value }: T) => T[K];
|
|
3845
|
-
|
|
3846
|
-
/**
|
|
3847
|
-
* Sets the `value` at `prop` of `object`.
|
|
3848
|
-
* @param obj the target method
|
|
3849
|
-
* @param prop the property name
|
|
3850
|
-
* @param value the value to set
|
|
3851
|
-
* @signature
|
|
3852
|
-
* P.set(obj, prop, value)
|
|
3853
|
-
* @example
|
|
3854
|
-
* P.set({ a: 1 }, 'a', 2) // => { a: 2 }
|
|
3855
|
-
* @dataFirst
|
|
3856
|
-
* @category Object
|
|
3857
|
-
*/
|
|
3858
|
-
declare function set<T, K extends keyof T>(obj: T, prop: K, value: T[K]): T;
|
|
3859
|
-
/**
|
|
3860
|
-
* Sets the `value` at `prop` of `object`.
|
|
3861
|
-
* @param prop the property name
|
|
3862
|
-
* @param value the value to set
|
|
3863
|
-
* @signature
|
|
3864
|
-
* P.set(prop, value)(obj)
|
|
3865
|
-
* @example
|
|
3866
|
-
* P.pipe({ a: 1 }, P.set('a', 2)) // => { a: 2 }
|
|
3867
|
-
* @dataLast
|
|
3868
|
-
* @category Object
|
|
3869
|
-
*/
|
|
3870
|
-
declare function set<T, K extends keyof T>(prop: K, value: T[K]): (obj: T) => T;
|
|
3871
|
-
|
|
3872
|
-
/**
|
|
3873
|
-
* Copied from ts-toolbelt
|
|
3874
|
-
* https://github.com/millsp/ts-toolbelt/blob/master/sources/Function/Narrow.ts
|
|
3875
|
-
*/
|
|
3876
|
-
/**
|
|
3877
|
-
* Similar to [[Cast]] but with a custom fallback `Catch`. If it fails,
|
|
3878
|
-
* it will enforce `Catch` instead of `A2`.
|
|
3879
|
-
* @param A1 to check against
|
|
3880
|
-
* @param A2 to try/test with
|
|
3881
|
-
* @param Catch to fallback to if the test failed
|
|
3882
|
-
* @returns `A1 | Catch`
|
|
3883
|
-
* @example
|
|
3884
|
-
* ```ts
|
|
3885
|
-
* import {A} from 'ts-toolbelt'
|
|
3886
|
-
*
|
|
3887
|
-
* type test0 = A.Try<'42', string> // '42'
|
|
3888
|
-
* type test1 = A.Try<'42', number> // never
|
|
3889
|
-
* type test1 = A.Try<'42', number, 'tried'> // 'tried'
|
|
3890
|
-
* ```
|
|
3891
|
-
*/
|
|
3892
|
-
type Try<A1, A2, Catch = never> = A1 extends A2 ? A1 : Catch;
|
|
3893
|
-
/**
|
|
3894
|
-
* Describes types that can be narrowed
|
|
3895
|
-
*/
|
|
3896
|
-
type Narrowable = bigint | boolean | number | string;
|
|
3897
|
-
/**
|
|
3898
|
-
* @hidden
|
|
3899
|
-
*/
|
|
3900
|
-
type NarrowRaw<A> = {
|
|
3901
|
-
[K in keyof A]: A[K] extends (...args: Array<any>) => any ? A[K] : NarrowRaw<A[K]>;
|
|
3902
|
-
} | (A extends [] ? [] : never) | (A extends Narrowable ? A : never);
|
|
3903
|
-
/**
|
|
3904
|
-
* Prevent type widening on generic function parameters
|
|
3905
|
-
* @param A to narrow
|
|
3906
|
-
* @returns `A`
|
|
3907
|
-
* @example
|
|
3908
|
-
* ```ts
|
|
3909
|
-
* import {F} from 'ts-toolbelt'
|
|
3910
|
-
*
|
|
3911
|
-
* declare function foo<A extends any[]>(x: F.Narrow<A>): A;
|
|
3912
|
-
* declare function bar<A extends object>(x: F.Narrow<A>): A;
|
|
3913
|
-
*
|
|
3914
|
-
* const test0 = foo(['e', 2, true, {f: ['g', ['h']]}])
|
|
3915
|
-
* // `A` inferred : ['e', 2, true, {f: ['g']}]
|
|
3916
|
-
*
|
|
3917
|
-
* const test1 = bar({a: 1, b: 'c', d: ['e', 2, true, {f: ['g']}]})
|
|
3918
|
-
* // `A` inferred : {a: 1, b: 'c', d: ['e', 2, true, {f: ['g']}]}
|
|
3919
|
-
* ```
|
|
3920
|
-
*/
|
|
3921
|
-
type Narrow<A> = Try<A, [], NarrowRaw<A>>;
|
|
3922
|
-
|
|
3923
|
-
type Path<Obj, Prefix extends Array<PropertyKey> = []> = Obj extends Primitive ? Prefix : Obj extends Array<infer Item> ? Path<Item, [...Prefix, number]> | Prefix : PathsOfObject<Obj, Prefix> | Prefix;
|
|
3924
|
-
type PathsOfObject<Obj, Prefix extends Array<PropertyKey>> = {
|
|
3925
|
-
[K in keyof Obj]: Path<Obj[K], [...Prefix, K]>;
|
|
3926
|
-
}[keyof Obj];
|
|
3927
|
-
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;
|
|
3928
|
-
type SupportsValueAtPath<Obj, Path extends Array<PropertyKey>, Value> = Value extends ValueAtPath<Obj, Path> ? Obj : never;
|
|
3929
|
-
type Primitive = boolean | null | number | string | symbol | undefined;
|
|
3930
|
-
|
|
3931
|
-
/**
|
|
3932
|
-
* Sets the value at `path` of `object`. `path` can be an array or a path string.
|
|
3933
|
-
* @param object the target method
|
|
3934
|
-
* @param path the property name
|
|
3935
|
-
* @param value the value to set
|
|
3936
|
-
* @signature
|
|
3937
|
-
* P.setPath(obj, path, value)
|
|
3938
|
-
* @example
|
|
3939
|
-
* P.setPath({ a: { b: 1 } }, ['a', 'b'], 2) // => { a: { b: 2 } }
|
|
3940
|
-
* @dataFirst
|
|
3941
|
-
* @category Object
|
|
3942
|
-
*/
|
|
3943
|
-
declare function setPath<T, TPath extends Array<PropertyKey> & Path<T>>(object: T, path: Narrow<TPath>, value: ValueAtPath<T, TPath>): T;
|
|
3944
|
-
/**
|
|
3945
|
-
* Sets the value at `path` of `object`. `path` can be an array or a path string.
|
|
3946
|
-
* @param path the property name
|
|
3947
|
-
* @param value the value to set
|
|
3948
|
-
* @signature
|
|
3949
|
-
* P.setPath(path, value)
|
|
3950
|
-
* @example
|
|
3951
|
-
* P.pipe({ a: { b: 1 } }, P.setPath(['a', 'b'], 2)) // { a: { b: 2 } }
|
|
3952
|
-
* @dataFirst
|
|
3953
|
-
* @category Object
|
|
3954
|
-
*/
|
|
3955
|
-
declare function setPath<TPath extends Array<PropertyKey>, Value>(path: Narrow<TPath>, value: Value): <Obj>(object: SupportsValueAtPath<Obj, TPath, Value>) => Obj;
|
|
3956
|
-
declare function _setPath(object: any, path: Array<any>, defaultValue: any): any;
|
|
3957
|
-
|
|
3958
|
-
type SwappedProps<T, K1 extends keyof T, K2 extends keyof T> = {
|
|
3959
|
-
[K in keyof T]: T[K1 extends K ? K2 : K2 extends K ? K1 : K];
|
|
3960
|
-
};
|
|
3961
|
-
/**
|
|
3962
|
-
* Swaps the positions of two properties in an object based on the provided keys.
|
|
3963
|
-
*
|
|
3964
|
-
* @param data the object to be manipulated
|
|
3965
|
-
* @param key1 the first property key
|
|
3966
|
-
* @param key2 the second property key
|
|
3967
|
-
*
|
|
3968
|
-
* @signature
|
|
3969
|
-
* swap(data, key1, key2)
|
|
3970
|
-
*
|
|
3971
|
-
* @returns Returns the manipulated object.
|
|
3972
|
-
*
|
|
3973
|
-
* @example
|
|
3974
|
-
* swap({a: 1, b: 2, c: 3}, 'a', 'b') // => {a: 2, b: 1, c: 3}
|
|
3975
|
-
*
|
|
3976
|
-
* @category Object
|
|
3977
|
-
*
|
|
3978
|
-
* @dataFirst
|
|
3979
|
-
*/
|
|
3980
|
-
declare function swapProps<T extends object, K1 extends keyof T, K2 extends keyof T>(data: T, key1: K1, key2: K2): SwappedProps<T, K1, K2>;
|
|
3981
|
-
/**
|
|
3982
|
-
* Swaps the positions of two properties in an object based on the provided keys.
|
|
3983
|
-
*
|
|
3984
|
-
* @param key1 the first property key
|
|
3985
|
-
* @param key2 the second property key
|
|
3986
|
-
*
|
|
3987
|
-
* @signature
|
|
3988
|
-
* swap(key1, key2)(data)
|
|
3989
|
-
*
|
|
3990
|
-
* @example
|
|
3991
|
-
* swap('a', 'b')({a: 1, b: 2, c: 3}) // => {a: 2, b: 1, c: 3}
|
|
3992
|
-
*
|
|
3993
|
-
* @returns Returns the manipulated object.
|
|
3994
|
-
*
|
|
3995
|
-
* @category Object
|
|
3996
|
-
*
|
|
3997
|
-
* @dataLast
|
|
3998
|
-
*/
|
|
3999
|
-
declare function swapProps<T extends object, K1 extends keyof T, K2 extends keyof T>(key1: K1, key2: K2): (data: T) => SwappedProps<T, K1, K2>;
|
|
4000
|
-
|
|
4001
|
-
type Pairs<T> = Array<{
|
|
4002
|
-
[K in keyof T]-?: [key: K, value: Required<T>[K]];
|
|
4003
|
-
}[keyof T]>;
|
|
4004
|
-
interface Strict {
|
|
4005
|
-
<T extends NonNullable<unknown>>(object: T): Pairs<T>;
|
|
4006
|
-
}
|
|
4007
|
-
/**
|
|
4008
|
-
* Returns an array of key/values of the enumerable properties of an object.
|
|
4009
|
-
* @param object
|
|
4010
|
-
* @signature
|
|
4011
|
-
* P.toPairs(object)
|
|
4012
|
-
* P.toPairs.strict(object)
|
|
4013
|
-
* @example
|
|
4014
|
-
* P.toPairs({ a: 1, b: 2, c: 3 }) // => [['a', 1], ['b', 2], ['c', 3]]
|
|
4015
|
-
* P.toPairs.strict({ a: 1 } as const) // => [['a', 1]] typed Array<['a', 1]>
|
|
4016
|
-
* P.pipe(
|
|
4017
|
-
* { a: 1, b: 2, c: 3 },
|
|
4018
|
-
* toPairs,
|
|
4019
|
-
* ); // => [['a', 1], ['b', 2], ['c', 3]]
|
|
4020
|
-
* P.pipe(
|
|
4021
|
-
* { a: 1 } as const,
|
|
4022
|
-
* toPairs.strict,
|
|
4023
|
-
* ); // => [['a', 1]] typed Array<['a', 1]>
|
|
4024
|
-
* @strict
|
|
4025
|
-
* @category Object
|
|
4026
|
-
* @dataFirst
|
|
4027
|
-
*/
|
|
4028
|
-
declare function toPairs<T>(object: Record<string, T>): Array<[string, T]>;
|
|
4029
|
-
declare namespace toPairs {
|
|
4030
|
-
const strict: Strict;
|
|
4031
|
-
}
|
|
4032
|
-
|
|
4033
|
-
/**
|
|
4034
|
-
* Returns a new array containing the values of the array or object.
|
|
4035
|
-
* @param source Either an array or an object
|
|
4036
|
-
* @signature
|
|
4037
|
-
* P.values(source)
|
|
4038
|
-
* @example
|
|
4039
|
-
* P.values(['x', 'y', 'z']) // => ['x', 'y', 'z']
|
|
4040
|
-
* P.values({ a: 'x', b: 'y', c: 'z' }) // => ['x', 'y', 'z']
|
|
4041
|
-
* P.pipe(
|
|
4042
|
-
* { a: 'x', b: 'y', c: 'z' },
|
|
4043
|
-
* P.values,
|
|
4044
|
-
* P.first
|
|
4045
|
-
* ) // => 'x'
|
|
4046
|
-
* @pipeable
|
|
4047
|
-
* @category Object
|
|
4048
|
-
*/
|
|
4049
|
-
type Values<T extends object> = T extends [] | ReadonlyArray<unknown> ? Array<T[number]> : Array<T[keyof T]>;
|
|
4050
|
-
declare function values<T extends object>(source: T): Values<T>;
|
|
4051
|
-
|
|
4052
|
-
type Splitter = '.' | '/' | '_' | '-';
|
|
4053
|
-
type FirstOfString<S extends string> = S extends `${infer F}${string}` ? F : never;
|
|
4054
|
-
type RemoveFirstOfString<S extends string> = S extends `${string}${infer R}` ? R : never;
|
|
4055
|
-
type IsUpper<S extends string> = S extends Uppercase<S> ? true : false;
|
|
4056
|
-
type IsLower<S extends string> = S extends Lowercase<S> ? true : false;
|
|
4057
|
-
type SameLetterCase<X extends string, Y extends string> = IsUpper<X> extends IsUpper<Y> ? true : IsLower<X> extends IsLower<Y> ? true : false;
|
|
4058
|
-
type CapitalizedWords<T extends readonly string[], Accumulator extends string = '', Normalize extends boolean | undefined = false> = T extends readonly [infer F extends string, ...infer R extends string[]] ? CapitalizedWords<R, `${Accumulator}${Capitalize<Normalize extends true ? Lowercase<F> : F>}`, Normalize> : Accumulator;
|
|
4059
|
-
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;
|
|
4060
|
-
type LastOfArray<T extends any[]> = T extends [...any, infer R] ? R : never;
|
|
4061
|
-
type RemoveLastOfArray<T extends any[]> = T extends [...infer F, any] ? F : never;
|
|
4062
|
-
interface CaseOptions {
|
|
4063
|
-
normalize?: boolean;
|
|
4064
|
-
}
|
|
4065
|
-
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, [
|
|
4066
|
-
...RemoveLastOfArray<Accumulator>,
|
|
4067
|
-
`${LastOfArray<Accumulator>}${F}`
|
|
4068
|
-
]> : 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, [
|
|
4069
|
-
...Accumulator,
|
|
4070
|
-
FirstOfString<R>
|
|
4071
|
-
]> : SplitByCase<R, Separator, [...Accumulator, '']> : SplitByCase<R, Separator, [
|
|
4072
|
-
...RemoveLastOfArray<Accumulator>,
|
|
4073
|
-
`${LastOfArray<Accumulator>}${F}`
|
|
4074
|
-
]> : IsLower<F> extends true ? SplitByCase<RemoveFirstOfString<R>, Separator, [
|
|
4075
|
-
...RemoveLastOfArray<Accumulator>,
|
|
4076
|
-
`${LastOfArray<Accumulator>}${F}`,
|
|
4077
|
-
FirstOfString<R>
|
|
4078
|
-
]> : SplitByCase<R, Separator, [...Accumulator, F]> : never : Accumulator extends [] ? T extends '' ? [] : string[] : Accumulator;
|
|
4079
|
-
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;
|
|
4080
|
-
type PascalCase<T, Normalize extends boolean | undefined = false> = string extends T ? string : string[] extends T ? string : T extends string ? SplitByCase<T> extends readonly string[] ? CapitalizedWords<SplitByCase<T>, '', Normalize> : never : T extends readonly string[] ? CapitalizedWords<T, '', Normalize> : never;
|
|
4081
|
-
type CamelCase<T, Normalize extends boolean | undefined = false> = string extends T ? string : string[] extends T ? string : Uncapitalize<PascalCase<T, Normalize>>;
|
|
4082
|
-
type KebabCase<T extends readonly string[] | string, Joiner extends string = '-'> = JoinByCase<T, Joiner>;
|
|
4083
|
-
type SnakeCase<T extends readonly string[] | string> = JoinByCase<T, '_'>;
|
|
4084
|
-
type TrainCase<T, Normalize extends boolean | undefined = false, Joiner extends string = '-'> = string extends T ? string : string[] extends T ? string : T extends string ? SplitByCase<T> extends readonly string[] ? CapitalizedWords<SplitByCase<T>, Joiner> : never : T extends readonly string[] ? CapitalizedWords<T, Joiner, Normalize> : never;
|
|
4085
|
-
type FlatCase<T extends readonly string[] | string, Joiner extends string = ''> = JoinByCase<T, Joiner>;
|
|
4086
|
-
|
|
4087
|
-
declare function isUppercase(char?: string): boolean | undefined;
|
|
4088
|
-
declare function splitByCase<T extends string>(str: T): SplitByCase<T>;
|
|
4089
|
-
declare function splitByCase<T extends string, Separator extends readonly string[]>(str: T, separators: Separator): SplitByCase<T, Separator[number]>;
|
|
4090
|
-
declare function toUpperFirst<S extends string>(str: S): Capitalize<S>;
|
|
4091
|
-
declare function toLowerFirst<S extends string>(str: S): Uncapitalize<S>;
|
|
4092
|
-
declare function toPascalCase(): '';
|
|
4093
|
-
declare function toPascalCase<T extends readonly string[] | string, UserCaseOptions extends CaseOptions = CaseOptions>(str: T, opts?: CaseOptions): PascalCase<T, UserCaseOptions['normalize']>;
|
|
4094
|
-
declare function toCamelCase(): '';
|
|
4095
|
-
declare function toCamelCase<T extends readonly string[] | string, UserCaseOptions extends CaseOptions = CaseOptions>(str: T, opts?: UserCaseOptions): CamelCase<T, UserCaseOptions['normalize']>;
|
|
4096
|
-
declare function toKebabCase(): '';
|
|
4097
|
-
declare function toKebabCase<T extends readonly string[] | string>(str: T): KebabCase<T>;
|
|
4098
|
-
declare function toKebabCase<T extends readonly string[] | string, Joiner extends string>(str: T, joiner: Joiner): KebabCase<T, Joiner>;
|
|
4099
|
-
declare function toSnakeCase(): '';
|
|
4100
|
-
declare function toSnakeCase<T extends readonly string[] | string>(str: T): SnakeCase<T>;
|
|
4101
|
-
declare function toFlatCase(): '';
|
|
4102
|
-
declare function toFlatCase<T extends readonly string[] | string>(str: T): FlatCase<T>;
|
|
4103
|
-
declare function toTrainCase(): '';
|
|
4104
|
-
declare function toTrainCase<T extends readonly string[] | string, UserCaseOptions extends CaseOptions = CaseOptions>(str: T, opts?: UserCaseOptions): TrainCase<T, UserCaseOptions['normalize']>;
|
|
4105
|
-
declare function titleCase(): '';
|
|
4106
|
-
declare function titleCase<T extends readonly string[] | string, UserCaseOptions extends CaseOptions = CaseOptions>(str: T, opts?: UserCaseOptions): TrainCase<T, UserCaseOptions['normalize'], ' '>;
|
|
4107
|
-
|
|
4108
|
-
/**
|
|
4109
|
-
* Returns human readable file size.
|
|
4110
|
-
* @param bytes the file size in bytes
|
|
4111
|
-
* @param base the base (1000 or 1024)
|
|
4112
|
-
* @signature
|
|
4113
|
-
* P.humanReadableFileSize(bytes, base)
|
|
4114
|
-
* @example
|
|
4115
|
-
* P.humanReadableFileSize(1000) // => '1.0 kB'
|
|
4116
|
-
* P.humanReadableFileSize(2097152, 1024) // => '2.0 Mib'
|
|
4117
|
-
* @category String
|
|
4118
|
-
*/
|
|
4119
|
-
declare function humanReadableFileSize(bytes: number, base?: 1000 | 1024): string;
|
|
4120
|
-
|
|
4121
|
-
/**
|
|
4122
|
-
* Random a non-cryptographic random string from characters a-zA-Z0-9.
|
|
4123
|
-
* @param length the length of the random string
|
|
4124
|
-
* @signature randomString(length)
|
|
4125
|
-
* @example
|
|
4126
|
-
* randomString(5) // => aB92J
|
|
4127
|
-
* @category String
|
|
4128
|
-
*/
|
|
4129
|
-
declare function randomString(length: number): string;
|
|
4130
|
-
|
|
4131
|
-
/**
|
|
4132
|
-
* Turn any string into a URL/DOM safe string.
|
|
4133
|
-
* @param str the string to slugify
|
|
4134
|
-
* @signature
|
|
4135
|
-
* P.slugify(str)
|
|
4136
|
-
* @example
|
|
4137
|
-
* P.slugify('FooBar') // => 'foobar'
|
|
4138
|
-
* P.slugify('This!-is*&%#@^up!') // => 'this-is-up'
|
|
4139
|
-
* @category String
|
|
4140
|
-
*/
|
|
4141
|
-
declare function slugify(str: string): string;
|
|
4142
|
-
|
|
4143
|
-
/**
|
|
4144
|
-
* Converts a path string to an array of keys.
|
|
4145
|
-
* @param path a string path
|
|
4146
|
-
* @signature P.stringToPathArray(path)
|
|
4147
|
-
* @example P.stringToPathArray('a.b[0].c') // => ['a', 'b', 0, 'c']
|
|
4148
|
-
* @dataFirst
|
|
4149
|
-
* @category String
|
|
4150
|
-
*/
|
|
4151
|
-
declare function stringToPath<Path extends string>(path: Path): StringToPath<Path>;
|
|
4152
|
-
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];
|
|
4153
|
-
|
|
4154
|
-
/**
|
|
4155
|
-
* 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'.
|
|
4156
|
-
* @param val
|
|
4157
|
-
* @signature
|
|
4158
|
-
* P.type(obj)
|
|
4159
|
-
* @example
|
|
4160
|
-
* P.type({}); //=> "Object"
|
|
4161
|
-
* P.type(1); //=> "Number"
|
|
4162
|
-
* P.type(false); //=> "Boolean"
|
|
4163
|
-
* P.type('s'); //=> "String"
|
|
4164
|
-
* P.type(null); //=> "Null"
|
|
4165
|
-
* P.type([]); //=> "Array"
|
|
4166
|
-
* P.type(/[A-z]/); //=> "RegExp"
|
|
4167
|
-
* P.type(() => {}); //=> "Function"
|
|
4168
|
-
* P.type(undefined); //=> "Undefined"
|
|
4169
|
-
* @category Type
|
|
4170
|
-
*/
|
|
4171
|
-
declare function type(val: unknown): string;
|
|
4172
|
-
|
|
4173
|
-
declare const isBrowser: boolean;
|
|
4174
|
-
|
|
4175
|
-
export { type Joined, KEY_CODES, type StringToPath, _setPath, add, addProp, allPass, anyPass, ceil, chunk, clamp, clone, compact, concat, conditional, countBy, createPipe, debounce, difference, differenceWith, divide, drop, dropFirstBy, dropLast, dropLastWhile, dropWhile, equals, filter, find, findIndex, findLast, findLastIndex, first, firstBy, flatMap, flatMapToObj, flatten, flattenDeep, floor, forEach, forEachObj, fromPairs, groupBy, hasAtLeast, humanReadableFileSize, identity, indexBy, intersection, intersectionWith, invert, isArray, isBoolean, isBrowser, isDate, isDefined, isEmpty, isError, isFunction, isNil, isNonNull, isNot, isNumber, isObject, isPromise, isString, isSymbol, isTruthy, isUppercase, join, keys, last, length, map, mapKeys, mapToObj, mapValues, maxBy, meanBy, merge, mergeAll, mergeDeep, minBy, multiply, noop, nthBy, omit, omitBy, once, only, partition, pathOr, pick, pickBy, pipe, prop, purry, randomString, range, rankBy, reduce, reject, reverse, round, sample, set, setPath, shuffle, sleep, slugify, sort, sortBy, splice, splitAt, splitByCase, splitWhen, stringToPath, subtract, sumBy, swapIndices, swapProps, take, takeFirstBy, takeWhile, titleCase, toCamelCase, toFlatCase, toKebabCase, toLowerFirst, toPairs, toPascalCase, toSnakeCase, toTrainCase, toUpperFirst, type, uniq, uniqBy, uniqWith, values, zip, zipObj, zipWith };
|