@vinicunca/perkakas 1.5.0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/add-prop.cjs +1 -1
- package/dist/add-prop.d.cts +1 -1
- package/dist/add-prop.d.ts +1 -1
- package/dist/add-prop.js +1 -1
- package/dist/add.cjs +1 -1
- package/dist/add.js +1 -1
- package/dist/all-pass.cjs +1 -1
- package/dist/all-pass.js +1 -1
- package/dist/any-pass.cjs +1 -1
- package/dist/any-pass.js +1 -1
- package/dist/array-required-prefix-Ck4lHkbA.d.cts +33 -0
- package/dist/array-required-prefix-DXv_WnmG.d.ts +33 -0
- package/dist/bounded-partial-BqwRN49U.d.cts +15 -0
- package/dist/bounded-partial-BzynYDVs.d.ts +15 -0
- package/dist/ceil.cjs +1 -1
- package/dist/ceil.js +1 -1
- package/dist/{chunk-AJQEGHF5.cjs → chunk-22AQJBPW.cjs} +1 -1
- package/dist/chunk-2HQM73IT.cjs +1 -0
- package/dist/chunk-2XGSSTCA.js +1 -0
- package/dist/chunk-3DOG24FJ.cjs +1 -0
- package/dist/{chunk-6ENW2VLC.cjs → chunk-3LC3CLYE.cjs} +1 -1
- package/dist/chunk-44LUF6RO.js +1 -0
- package/dist/chunk-4BTTPOEU.cjs +1 -0
- package/dist/chunk-4Y6KJJOW.js +1 -0
- package/dist/chunk-5PMGMODH.js +1 -0
- package/dist/{chunk-GVYLRJPB.cjs → chunk-66JP4PUG.cjs} +1 -1
- package/dist/chunk-6M4IYQFZ.js +1 -0
- package/dist/chunk-76VE5EC6.cjs +1 -0
- package/dist/{chunk-TNA73S2T.cjs → chunk-7C7R7JNX.cjs} +1 -1
- package/dist/{chunk-WONMP5WS.js → chunk-7V7IBWP5.js} +1 -1
- package/dist/chunk-B6SBIS6W.js +1 -0
- package/dist/chunk-BEMQAYI5.cjs +1 -0
- package/dist/chunk-BKBHW2XJ.js +1 -0
- package/dist/chunk-BSNCALDT.cjs +1 -0
- package/dist/chunk-CTGIT5TY.js +1 -0
- package/dist/{chunk-UGWBDJPI.cjs → chunk-D4TUHKBA.cjs} +1 -1
- package/dist/chunk-EK7ODJWE.js +1 -0
- package/dist/chunk-FGMSPUSF.cjs +1 -0
- package/dist/chunk-FIO5FNV2.js +1 -0
- package/dist/chunk-FOUZI2Q3.cjs +1 -0
- package/dist/chunk-GRKRFDIL.js +1 -0
- package/dist/chunk-GW4KDK3D.cjs +1 -0
- package/dist/chunk-HSNPZS6R.cjs +1 -0
- package/dist/chunk-ITDJLXHO.js +1 -0
- package/dist/{chunk-FLQYTU5W.cjs → chunk-JHFSYEXB.cjs} +1 -1
- package/dist/{chunk-WCPENZWH.js → chunk-JI5FJX2E.js} +1 -1
- package/dist/chunk-JYWIRZ2Z.js +1 -0
- package/dist/chunk-K26HQR4Y.cjs +1 -0
- package/dist/chunk-KYMVIFAW.cjs +1 -0
- package/dist/chunk-MBGSSEZN.cjs +1 -0
- package/dist/{chunk-22IDCBFS.js → chunk-MPWQN3WY.js} +1 -1
- package/dist/chunk-NHTBBY2L.js +1 -0
- package/dist/chunk-NQUTCPKD.js +1 -0
- package/dist/{chunk-ZQXE6PIV.cjs → chunk-NVCXF5UR.cjs} +1 -1
- package/dist/chunk-O74TUGYF.js +1 -0
- package/dist/chunk-OKBFQ7B6.js +1 -0
- package/dist/{chunk-MHEODCN3.cjs → chunk-OMHZCALN.cjs} +1 -1
- package/dist/chunk-P7RCAO7P.cjs +438 -0
- package/dist/chunk-QGF2XNZS.cjs +1 -0
- package/dist/chunk-R4O7XE2F.cjs +1 -0
- package/dist/chunk-RMOD5JNB.cjs +1 -0
- package/dist/chunk-RTFVY5D4.cjs +1 -0
- package/dist/chunk-SG2YWG6U.cjs +1 -0
- package/dist/chunk-SXNRBENP.cjs +1 -0
- package/dist/chunk-TSP3FU72.cjs +1 -0
- package/dist/chunk-TVMG2NYC.js +1 -0
- package/dist/chunk-TWCEO47X.cjs +1 -0
- package/dist/{chunk-L4FN2W5Q.cjs → chunk-TXPRX236.cjs} +1 -1
- package/dist/{chunk-3K7SNX4D.cjs → chunk-UURK6I3D.cjs} +1 -1
- package/dist/chunk-UWMBE6BM.js +1 -0
- package/dist/{chunk-VBH6SKKO.js → chunk-VI2QG3FU.js} +1 -1
- package/dist/chunk-XCG2UC6T.js +1 -0
- package/dist/chunk-YCSQX2SY.js +1 -0
- package/dist/{chunk-6XVLHSPK.js → chunk-YRVN4PYH.js} +1 -1
- package/dist/chunk-YWIXN5BR.js +1 -0
- package/dist/chunk-Z23BZCCD.js +438 -0
- package/dist/{chunk-EDZFEURO.js → chunk-Z5YZYBC2.js} +1 -1
- package/dist/chunk-Z7D7Q6U3.js +1 -0
- package/dist/chunk-ZITGCTSW.js +1 -0
- package/dist/chunk-ZMG3NQDL.js +1 -0
- package/dist/chunk.cjs +1 -1
- package/dist/chunk.d.cts +37 -41
- package/dist/chunk.d.ts +37 -41
- package/dist/chunk.js +1 -1
- package/dist/clamp.cjs +1 -1
- package/dist/clamp.js +1 -1
- package/dist/clamped-integer-subtract-DZ7rsJE4.d.cts +15 -0
- package/dist/clamped-integer-subtract-DZ7rsJE4.d.ts +15 -0
- package/dist/clone.cjs +1 -1
- package/dist/clone.js +1 -1
- package/dist/coerced-array-DRz3tqda.d.cts +14 -0
- package/dist/coerced-array-DRz3tqda.d.ts +14 -0
- package/dist/concat.cjs +1 -1
- package/dist/concat.js +1 -1
- package/dist/conditional.cjs +1 -1
- package/dist/conditional.d.cts +133 -43
- package/dist/conditional.d.ts +133 -43
- package/dist/conditional.js +1 -1
- package/dist/constant.cjs +1 -1
- package/dist/constant.js +1 -1
- package/dist/count-by.cjs +1 -1
- package/dist/count-by.d.cts +5 -4
- package/dist/count-by.d.ts +5 -4
- package/dist/count-by.js +1 -1
- package/dist/curry.cjs +1 -1
- package/dist/curry.js +1 -1
- package/dist/debounce.cjs +1 -1
- package/dist/debounce.js +1 -1
- package/dist/difference-with.cjs +1 -1
- package/dist/difference-with.js +1 -1
- package/dist/difference.cjs +1 -1
- package/dist/difference.js +1 -1
- package/dist/divide.cjs +1 -1
- package/dist/divide.js +1 -1
- package/dist/do-nothing.cjs +1 -1
- package/dist/do-nothing.js +1 -1
- package/dist/drop-first-by.cjs +1 -1
- package/dist/drop-first-by.d.cts +1 -1
- package/dist/drop-first-by.d.ts +1 -1
- package/dist/drop-first-by.js +1 -1
- package/dist/drop-last-while.cjs +1 -1
- package/dist/drop-last-while.js +1 -1
- package/dist/drop-last.cjs +1 -1
- package/dist/drop-last.js +1 -1
- package/dist/drop-while.cjs +1 -1
- package/dist/drop-while.js +1 -1
- package/dist/drop.cjs +1 -1
- package/dist/drop.d.cts +18 -30
- package/dist/drop.d.ts +18 -30
- package/dist/drop.js +1 -1
- package/dist/entries.cjs +1 -1
- package/dist/entries.d.cts +8 -5
- package/dist/entries.d.ts +8 -5
- package/dist/entries.js +1 -1
- package/dist/{enumerable-string-key-of-BQ4aR5ep.d.cts → enumerable-string-key-of-C4gsorXe.d.ts} +3 -1
- package/dist/{enumerable-string-key-of-BQ4aR5ep.d.ts → enumerable-string-key-of-D8w_3Yg8.d.cts} +3 -1
- package/dist/enumerable-string-keyed-value-of-BU9R_cEk.d.cts +9 -0
- package/dist/enumerable-string-keyed-value-of-BU9R_cEk.d.ts +9 -0
- package/dist/evolve.cjs +1 -1
- package/dist/evolve.js +1 -1
- package/dist/filter.cjs +1 -1
- package/dist/filter.d.cts +12 -4
- package/dist/filter.d.ts +12 -4
- package/dist/filter.js +1 -1
- package/dist/filtered-array-BCjySbC6.d.cts +18 -0
- package/dist/filtered-array-JKATL39M.d.ts +18 -0
- package/dist/find-index.cjs +1 -1
- package/dist/find-index.js +1 -1
- package/dist/find-last-index.cjs +1 -1
- package/dist/find-last-index.js +1 -1
- package/dist/find-last.cjs +1 -1
- package/dist/find-last.js +1 -1
- package/dist/find.cjs +1 -1
- package/dist/find.js +1 -1
- package/dist/first-by.cjs +1 -1
- package/dist/first-by.d.cts +1 -1
- package/dist/first-by.d.ts +1 -1
- package/dist/first-by.js +1 -1
- package/dist/first.cjs +1 -1
- package/dist/first.js +1 -1
- package/dist/flat-map.cjs +1 -1
- package/dist/flat-map.js +1 -1
- package/dist/flat.cjs +1 -1
- package/dist/flat.d.cts +2 -5
- package/dist/flat.d.ts +2 -5
- package/dist/flat.js +1 -1
- package/dist/floor.cjs +1 -1
- package/dist/floor.js +1 -1
- package/dist/for-each-obj.cjs +1 -1
- package/dist/for-each-obj.d.cts +3 -2
- package/dist/for-each-obj.d.ts +3 -2
- package/dist/for-each-obj.js +1 -1
- package/dist/for-each.cjs +1 -1
- package/dist/for-each.js +1 -1
- package/dist/from-entries.cjs +1 -1
- package/dist/from-entries.d.cts +4 -2
- package/dist/from-entries.d.ts +4 -2
- package/dist/from-entries.js +1 -1
- package/dist/from-keys.cjs +1 -1
- package/dist/from-keys.d.cts +4 -3
- package/dist/from-keys.d.ts +4 -3
- package/dist/from-keys.js +1 -1
- package/dist/funnel.cjs +1 -1
- package/dist/funnel.d.cts +7 -7
- package/dist/funnel.d.ts +7 -7
- package/dist/funnel.js +1 -1
- package/dist/funnel.lodash-debounce-with-cached-value.test.cjs +1 -1
- package/dist/funnel.lodash-debounce-with-cached-value.test.js +1 -1
- package/dist/funnel.lodash-debounce.test.cjs +1 -1
- package/dist/funnel.lodash-debounce.test.js +1 -1
- package/dist/funnel.lodash-throttle-with-cached-value.test.cjs +1 -1
- package/dist/funnel.lodash-throttle-with-cached-value.test.js +1 -1
- package/dist/funnel.lodash-throttle.test.cjs +1 -1
- package/dist/funnel.lodash-throttle.test.js +1 -1
- package/dist/funnel.perkakas-debounce.test.cjs +1 -0
- package/dist/funnel.perkakas-debounce.test.js +1 -0
- package/dist/funnel.reference-batch.test.cjs +1 -1
- package/dist/funnel.reference-batch.test.js +1 -1
- package/dist/funnel.test-d.cjs +1 -1
- package/dist/funnel.test-d.js +1 -1
- package/dist/funnel.test.cjs +1 -1
- package/dist/funnel.test.js +1 -1
- package/dist/group-by-prop.cjs +1 -0
- package/dist/group-by-prop.d.cts +93 -0
- package/dist/group-by-prop.d.ts +93 -0
- package/dist/group-by-prop.js +1 -0
- package/dist/group-by.cjs +1 -1
- package/dist/group-by.d.cts +15 -4
- package/dist/group-by.d.ts +15 -4
- package/dist/group-by.js +1 -1
- package/dist/has-at-least.cjs +1 -1
- package/dist/has-at-least.d.cts +7 -15
- package/dist/has-at-least.d.ts +7 -15
- package/dist/has-at-least.js +1 -1
- package/dist/has-sub-object.cjs +1 -1
- package/dist/has-sub-object.js +1 -1
- package/dist/human-readable-file-size.cjs +1 -1
- package/dist/human-readable-file-size.js +1 -1
- package/dist/identity.cjs +1 -1
- package/dist/identity.js +1 -1
- package/dist/if-D4QIikQ1.d.cts +5 -0
- package/dist/if-D4QIikQ1.d.ts +5 -0
- package/dist/index-by.cjs +1 -1
- package/dist/index-by.d.cts +5 -4
- package/dist/index-by.d.ts +5 -4
- package/dist/index-by.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +15 -8
- package/dist/index.d.ts +15 -8
- package/dist/index.js +1 -1
- package/dist/intersection-with.cjs +1 -1
- package/dist/intersection-with.js +1 -1
- package/dist/intersection.cjs +1 -1
- package/dist/intersection.js +1 -1
- package/dist/invert.cjs +1 -1
- package/dist/invert.d.cts +2 -1
- package/dist/invert.d.ts +2 -1
- package/dist/invert.js +1 -1
- package/dist/is-array.cjs +1 -1
- package/dist/is-array.js +1 -1
- package/dist/is-big-int.cjs +1 -1
- package/dist/is-big-int.js +1 -1
- package/dist/is-boolean.cjs +1 -1
- package/dist/is-boolean.js +1 -1
- package/dist/is-bounded-record-C9WAwfA8.d.cts +30 -0
- package/dist/is-bounded-record-C9WAwfA8.d.ts +30 -0
- package/dist/is-date.cjs +1 -1
- package/dist/is-date.js +1 -1
- package/dist/is-deep-equal.cjs +1 -1
- package/dist/is-deep-equal.js +1 -1
- package/dist/is-defined.cjs +1 -1
- package/dist/is-defined.js +1 -1
- package/dist/is-empty.cjs +1 -1
- package/dist/is-empty.js +1 -1
- package/dist/is-error.cjs +1 -1
- package/dist/is-error.js +1 -1
- package/dist/is-function.cjs +1 -1
- package/dist/is-function.js +1 -1
- package/dist/is-included-in.cjs +1 -1
- package/dist/is-included-in.js +1 -1
- package/dist/is-non-null.cjs +1 -1
- package/dist/is-non-null.js +1 -1
- package/dist/is-non-nullish.cjs +1 -1
- package/dist/is-non-nullish.js +1 -1
- package/dist/is-not.cjs +1 -1
- package/dist/is-not.js +1 -1
- package/dist/is-nullish.cjs +1 -1
- package/dist/is-nullish.js +1 -1
- package/dist/is-number.cjs +1 -1
- package/dist/is-number.js +1 -1
- package/dist/is-object-type.cjs +1 -1
- package/dist/is-object-type.js +1 -1
- package/dist/is-plain-object.cjs +1 -1
- package/dist/is-plain-object.js +1 -1
- package/dist/is-promise.cjs +1 -1
- package/dist/is-promise.js +1 -1
- package/dist/is-shallow-equal.cjs +1 -1
- package/dist/is-shallow-equal.js +1 -1
- package/dist/is-strict-equal.cjs +1 -1
- package/dist/is-strict-equal.js +1 -1
- package/dist/is-string.cjs +1 -1
- package/dist/is-string.js +1 -1
- package/dist/is-symbol.cjs +1 -1
- package/dist/is-symbol.js +1 -1
- package/dist/is-truthy.cjs +1 -1
- package/dist/is-truthy.js +1 -1
- package/dist/join.cjs +1 -1
- package/dist/join.js +1 -1
- package/dist/key-codes.cjs +1 -1
- package/dist/key-codes.js +1 -1
- package/dist/keys.cjs +1 -1
- package/dist/keys.d.cts +4 -3
- package/dist/keys.d.ts +4 -3
- package/dist/keys.js +1 -1
- package/dist/last.cjs +1 -1
- package/dist/last.js +1 -1
- package/dist/length.cjs +1 -1
- package/dist/length.js +1 -1
- package/dist/magic-string.es-2ADFIHOO.cjs +13 -0
- package/dist/magic-string.es-PNCTE22R.js +13 -0
- package/dist/map-keys.cjs +1 -1
- package/dist/map-keys.d.cts +8 -6
- package/dist/map-keys.d.ts +8 -6
- package/dist/map-keys.js +1 -1
- package/dist/map-to-obj.cjs +1 -1
- package/dist/map-to-obj.d.cts +30 -12
- package/dist/map-to-obj.d.ts +30 -12
- package/dist/map-to-obj.js +1 -1
- package/dist/map-values.cjs +1 -1
- package/dist/map-values.d.cts +3 -2
- package/dist/map-values.d.ts +3 -2
- package/dist/map-values.js +1 -1
- package/dist/map-with-feedback.cjs +1 -1
- package/dist/map-with-feedback.js +1 -1
- package/dist/map.cjs +1 -1
- package/dist/map.js +1 -1
- package/dist/mean-by.cjs +1 -1
- package/dist/mean-by.js +1 -1
- package/dist/merge-all.cjs +1 -1
- package/dist/merge-all.d.cts +2 -1
- package/dist/merge-all.d.ts +2 -1
- package/dist/merge-all.js +1 -1
- package/dist/merge-deep.cjs +1 -1
- package/dist/merge-deep.js +1 -1
- package/dist/merge.cjs +1 -1
- package/dist/merge.js +1 -1
- package/dist/multiply.cjs +1 -1
- package/dist/multiply.js +1 -1
- package/dist/nth-by.cjs +1 -1
- package/dist/nth-by.d.cts +1 -1
- package/dist/nth-by.d.ts +1 -1
- package/dist/nth-by.js +1 -1
- package/dist/obj-of.cjs +1 -1
- package/dist/obj-of.js +1 -1
- package/dist/omit-by.cjs +1 -1
- package/dist/omit-by.d.cts +7 -6
- package/dist/omit-by.d.ts +7 -6
- package/dist/omit-by.js +1 -1
- package/dist/omit.cjs +1 -1
- package/dist/omit.js +1 -1
- package/dist/once.cjs +1 -1
- package/dist/once.js +1 -1
- package/dist/only.cjs +1 -1
- package/dist/only.js +1 -1
- package/dist/partial-array-Vnf1fBtl.d.cts +10 -0
- package/dist/partial-array-Vnf1fBtl.d.ts +10 -0
- package/dist/partition.cjs +1 -1
- package/dist/partition.js +1 -1
- package/dist/path-or.cjs +1 -1
- package/dist/path-or.js +1 -1
- package/dist/perkakas-type-error-8wPb8T2y.d.cts +17 -0
- package/dist/perkakas-type-error-8wPb8T2y.d.ts +17 -0
- package/dist/pick-by.cjs +1 -1
- package/dist/pick-by.d.cts +11 -11
- package/dist/pick-by.d.ts +11 -11
- package/dist/pick-by.js +1 -1
- package/dist/pick.cjs +1 -1
- package/dist/pick.d.cts +52 -7
- package/dist/pick.d.ts +52 -7
- package/dist/pick.js +1 -1
- package/dist/pipe.cjs +1 -1
- package/dist/pipe.js +1 -1
- package/dist/piped.cjs +1 -1
- package/dist/piped.js +1 -1
- package/dist/product.cjs +1 -1
- package/dist/product.js +1 -1
- package/dist/prop.cjs +1 -1
- package/dist/prop.js +1 -1
- package/dist/pull-object.cjs +1 -1
- package/dist/pull-object.d.cts +5 -4
- package/dist/pull-object.d.ts +5 -4
- package/dist/pull-object.js +1 -1
- package/dist/random-integer.cjs +1 -1
- package/dist/random-integer.js +1 -1
- package/dist/random-string.cjs +1 -1
- package/dist/random-string.js +1 -1
- package/dist/range.cjs +1 -1
- package/dist/range.js +1 -1
- package/dist/rank-by.cjs +1 -1
- package/dist/rank-by.d.cts +1 -1
- package/dist/rank-by.d.ts +1 -1
- package/dist/rank-by.js +1 -1
- package/dist/reduce.cjs +1 -1
- package/dist/reduce.js +1 -1
- package/dist/reverse.cjs +1 -1
- package/dist/reverse.js +1 -1
- package/dist/round.cjs +1 -1
- package/dist/round.js +1 -1
- package/dist/sample.cjs +1 -1
- package/dist/sample.js +1 -1
- package/dist/set-path.cjs +1 -1
- package/dist/set-path.d.cts +18 -7
- package/dist/set-path.d.ts +18 -7
- package/dist/set-path.js +1 -1
- package/dist/set.cjs +1 -1
- package/dist/set.d.cts +1 -1
- package/dist/set.d.ts +1 -1
- package/dist/set.js +1 -1
- package/dist/shuffle.cjs +1 -1
- package/dist/shuffle.js +1 -1
- package/dist/sleep.cjs +1 -1
- package/dist/sleep.js +1 -1
- package/dist/slice-string.cjs +1 -1
- package/dist/slice-string.js +1 -1
- package/dist/slugify.cjs +1 -1
- package/dist/slugify.js +1 -1
- package/dist/sort-by.cjs +1 -1
- package/dist/sort-by.d.cts +1 -1
- package/dist/sort-by.d.ts +1 -1
- package/dist/sort-by.js +1 -1
- package/dist/sort.cjs +1 -1
- package/dist/sort.js +1 -1
- package/dist/sorted-index-by.cjs +1 -1
- package/dist/sorted-index-by.js +1 -1
- package/dist/sorted-index-with.cjs +1 -1
- package/dist/sorted-index-with.js +1 -1
- package/dist/sorted-index.cjs +1 -1
- package/dist/sorted-index.js +1 -1
- package/dist/sorted-last-index-by.cjs +1 -1
- package/dist/sorted-last-index-by.js +1 -1
- package/dist/sorted-last-index.cjs +1 -1
- package/dist/sorted-last-index.js +1 -1
- package/dist/splice.cjs +1 -1
- package/dist/splice.js +1 -1
- package/dist/split-at.cjs +1 -1
- package/dist/split-at.js +1 -1
- package/dist/split-when.cjs +1 -1
- package/dist/split-when.js +1 -1
- package/dist/split.cjs +1 -1
- package/dist/split.js +1 -1
- package/dist/string-to-path.cjs +1 -1
- package/dist/string-to-path.d.cts +33 -11
- package/dist/string-to-path.d.ts +33 -11
- package/dist/string-to-path.js +1 -1
- package/dist/subtract.cjs +1 -1
- package/dist/subtract.js +1 -1
- package/dist/sum-by.cjs +1 -1
- package/dist/sum-by.js +1 -1
- package/dist/sum.cjs +1 -1
- package/dist/sum.js +1 -1
- package/dist/swap-indices.cjs +1 -1
- package/dist/swap-indices.js +1 -1
- package/dist/swap-props.cjs +1 -1
- package/dist/swap-props.js +1 -1
- package/dist/take-first-by.cjs +1 -1
- package/dist/take-first-by.d.cts +1 -1
- package/dist/take-first-by.d.ts +1 -1
- package/dist/take-first-by.js +1 -1
- package/dist/take-last-while.cjs +1 -1
- package/dist/take-last-while.d.cts +2 -0
- package/dist/take-last-while.d.ts +2 -0
- package/dist/take-last-while.js +1 -1
- package/dist/take-last.cjs +1 -1
- package/dist/take-last.js +1 -1
- package/dist/take-while.cjs +1 -1
- package/dist/take-while.d.cts +2 -0
- package/dist/take-while.d.ts +2 -0
- package/dist/take-while.js +1 -1
- package/dist/take.cjs +1 -1
- package/dist/take.js +1 -1
- package/dist/tap.cjs +1 -1
- package/dist/tap.js +1 -1
- package/dist/times.cjs +1 -1
- package/dist/times.d.cts +1 -9
- package/dist/times.d.ts +1 -9
- package/dist/times.js +1 -1
- package/dist/to-camel-case.cjs +1 -1
- package/dist/to-camel-case.js +1 -1
- package/dist/to-capital-case.cjs +1 -1
- package/dist/to-capital-case.js +1 -1
- package/dist/to-constant-case.cjs +1 -1
- package/dist/to-constant-case.js +1 -1
- package/dist/to-kebab-case.cjs +1 -1
- package/dist/to-kebab-case.js +1 -1
- package/dist/to-no-case.cjs +1 -1
- package/dist/to-no-case.js +1 -1
- package/dist/to-pascal-case.cjs +1 -1
- package/dist/to-pascal-case.js +1 -1
- package/dist/to-pascal-snake-case.cjs +1 -1
- package/dist/to-pascal-snake-case.js +1 -1
- package/dist/to-sentence-case.cjs +1 -1
- package/dist/to-sentence-case.js +1 -1
- package/dist/to-snake-case.cjs +1 -1
- package/dist/to-snake-case.js +1 -1
- package/dist/to-string-DO8zw6jS.d.cts +11 -0
- package/dist/to-string-DO8zw6jS.d.ts +11 -0
- package/dist/to-train-case.cjs +1 -1
- package/dist/to-train-case.js +1 -1
- package/dist/tuple-parts-BTivqbtT.d.ts +86 -0
- package/dist/tuple-parts-v6av7LMU.d.cts +86 -0
- package/dist/unique-by.cjs +1 -1
- package/dist/unique-by.js +1 -1
- package/dist/unique-with.cjs +1 -1
- package/dist/unique-with.js +1 -1
- package/dist/unique.cjs +1 -1
- package/dist/unique.js +1 -1
- package/dist/{upsert-prop-tIHFi_F_.d.cts → upsert-prop-Cc3jEW9l.d.cts} +1 -2
- package/dist/{upsert-prop-D0N8486l.d.ts → upsert-prop-CdUtD50i.d.ts} +1 -2
- package/dist/values.cjs +1 -1
- package/dist/values.d.cts +1 -1
- package/dist/values.d.ts +1 -1
- package/dist/values.js +1 -1
- package/dist/zip-with.cjs +1 -1
- package/dist/zip-with.js +1 -1
- package/dist/zip.cjs +1 -1
- package/dist/zip.js +1 -1
- package/package.json +12 -12
- package/dist/chunk-2MU3SHCO.js +0 -1
- package/dist/chunk-3CFBQYOQ.js +0 -1
- package/dist/chunk-5SAUYUEK.js +0 -1
- package/dist/chunk-5VXKW6SI.cjs +0 -1
- package/dist/chunk-6HSB3NFW.js +0 -1
- package/dist/chunk-6L5XEBJG.js +0 -1
- package/dist/chunk-A2PAJNYA.js +0 -1
- package/dist/chunk-APUBIDDU.cjs +0 -1
- package/dist/chunk-AWXJSK4F.js +0 -1
- package/dist/chunk-B5QDOWVQ.cjs +0 -1
- package/dist/chunk-B7RHAPUE.js +0 -1
- package/dist/chunk-BOOMUHPG.js +0 -1
- package/dist/chunk-CZLV6ZLZ.js +0 -1
- package/dist/chunk-DLXKXNZT.js +0 -1
- package/dist/chunk-F3JXHUP4.cjs +0 -1
- package/dist/chunk-FMUPPQZE.js +0 -1
- package/dist/chunk-GFQXVPLP.cjs +0 -1
- package/dist/chunk-GOUUMCT7.cjs +0 -1
- package/dist/chunk-HRK4GMT2.cjs +0 -1
- package/dist/chunk-I7K3Z4BT.js +0 -1
- package/dist/chunk-ICYGL2YZ.js +0 -1
- package/dist/chunk-IJ4I5A3K.js +0 -1
- package/dist/chunk-IXGOK22A.cjs +0 -1
- package/dist/chunk-L4ITKDYB.cjs +0 -1
- package/dist/chunk-MBC7VZHY.js +0 -1
- package/dist/chunk-NQGMUM3E.cjs +0 -1
- package/dist/chunk-OBWPUDD3.cjs +0 -1
- package/dist/chunk-OEJ5J23C.js +0 -1
- package/dist/chunk-OL2TQDYM.cjs +0 -1
- package/dist/chunk-PIF5X7RQ.cjs +0 -1
- package/dist/chunk-PWHX2554.js +0 -1
- package/dist/chunk-QQMFHVPX.cjs +0 -1
- package/dist/chunk-SQZULO7V.js +0 -1
- package/dist/chunk-THE6MSJO.cjs +0 -1
- package/dist/chunk-UDSRBKNR.js +0 -1
- package/dist/chunk-UUYCL4G2.js +0 -1
- package/dist/chunk-VRZNQSZN.cjs +0 -1
- package/dist/chunk-WYM2JV5T.cjs +0 -1
- package/dist/chunk-XLGD5ZUY.cjs +0 -1
- package/dist/chunk-XU4TDKMD.cjs +0 -1
- package/dist/chunk-YCM6N46T.js +0 -1
- package/dist/chunk-Z46FX2Y4.js +0 -1
- package/dist/enumerable-string-keyed-value-of-CLzltniW.d.cts +0 -15
- package/dist/enumerable-string-keyed-value-of-CLzltniW.d.ts +0 -15
- package/dist/exact-record-Dhbe_K-E.d.ts +0 -5
- package/dist/exact-record-_isi2JMR.d.cts +0 -5
- package/dist/funnel.remeda-debounce.test.cjs +0 -1
- package/dist/funnel.remeda-debounce.test.js +0 -1
- package/dist/if-bounded-record-Drd4UbBU.d.cts +0 -29
- package/dist/if-bounded-record-Drd4UbBU.d.ts +0 -29
- package/dist/n-tuple-5jljrt4c.d.cts +0 -10
- package/dist/n-tuple-5jljrt4c.d.ts +0 -10
- package/dist/reconstructed-record-DchLaSO8.d.cts +0 -10
- package/dist/reconstructed-record-DuxOLlMs.d.ts +0 -10
- package/dist/take-last-while.spec-d-.cjs +0 -1
- package/dist/take-last-while.spec-d-.d.cts +0 -2
- package/dist/take-last-while.spec-d-.d.ts +0 -2
- package/dist/take-last-while.spec-d-.js +0 -1
- package/dist/tuple-parts-CP0H7BrE.d.cts +0 -37
- package/dist/tuple-parts-CP0H7BrE.d.ts +0 -37
- /package/dist/{funnel.remeda-debounce.test.d.cts → funnel.perkakas-debounce.test.d.cts} +0 -0
- /package/dist/{funnel.remeda-debounce.test.d.ts → funnel.perkakas-debounce.test.d.ts} +0 -0
package/dist/conditional.d.cts
CHANGED
|
@@ -8,9 +8,12 @@
|
|
|
8
8
|
type GuardType<T, Fallback = never> = T extends (x: any, ...rest: any) => x is infer U ? U : Fallback;
|
|
9
9
|
|
|
10
10
|
type Case<In, Out, When extends (x: In) => boolean = (x: In) => boolean> = readonly [when: When, then: (x: GuardType<When, In> & In) => Out];
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
type DefaultCase<In, Out> = (x: In) => Out;
|
|
12
|
+
interface Utilities {
|
|
13
|
+
readonly defaultCase: typeof defaultCase;
|
|
14
|
+
}
|
|
15
|
+
type WithUtils<T> = T & Utilities;
|
|
16
|
+
declare const conditionalPlus: WithUtils<typeof conditional>;
|
|
14
17
|
|
|
15
18
|
/**
|
|
16
19
|
* Executes a transformer function based on the first matching predicate,
|
|
@@ -19,13 +22,18 @@ declare const conditionalPlus: typeof conditional & {
|
|
|
19
22
|
* corresponding transformer, and returns, ignoring any further cases, even if
|
|
20
23
|
* they would match.
|
|
21
24
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
25
|
+
* NOTE*: Some type-predicates may fail to narrow the param type of their
|
|
26
|
+
* transformer; in such cases wrap your type-predicate in an anonymous arrow
|
|
27
|
+
* function: e.g., instead of
|
|
28
|
+
* `conditional(..., [myTypePredicate, myTransformer], ...)`, use
|
|
29
|
+
* `conditional(..., [($) => myTypePredicate($), myTransformer], ...)`.
|
|
30
|
+
*
|
|
31
|
+
* To add a a default, catch-all, case you can provide a single callback
|
|
32
|
+
* function (instead of a 2-tuple) as the last case. This is equivalent to
|
|
33
|
+
* adding a case with a trivial always-true predicate as it's condition (see
|
|
34
|
+
* example).
|
|
35
|
+
*
|
|
36
|
+
* For simpler cases you should also consider using `when` instead.
|
|
29
37
|
*
|
|
30
38
|
* Due to TypeScript's inability to infer the result of negating a type-
|
|
31
39
|
* predicate we can't refine the types used in subsequent cases based on
|
|
@@ -33,30 +41,62 @@ declare const conditionalPlus: typeof conditional & {
|
|
|
33
41
|
* is recommended for more precise type control when such type narrowing is
|
|
34
42
|
* needed.
|
|
35
43
|
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
44
|
+
* !IMPORTANT! - Unlike similar implementations in Lodash and Ramda, this
|
|
45
|
+
* implementation **doesn't** implicitly return `undefined` as a fallback when
|
|
46
|
+
* when none of the cases match; and instead **throws** an exception in those
|
|
47
|
+
* cases! You have to explicitly provide a default case, and can use
|
|
48
|
+
* `constant(undefined)` as your last case to replicate that behavior.
|
|
49
|
+
*
|
|
50
|
+
* @param cases - A list of (up to 10) cases. Each case can be either:
|
|
51
|
+
* - A 2-tuple consisting of a predicate (or type-predicate) and a transformer
|
|
52
|
+
* function that processes the data if the predicate matches.
|
|
53
|
+
* - A single callback function that acts as a default fallback case.
|
|
39
54
|
* @returns The output of the matched transformer. If no cases match, an
|
|
40
55
|
* exception is thrown. The return type is a union of the return types of all
|
|
41
56
|
* provided transformers.
|
|
42
57
|
* @signature
|
|
43
58
|
* P.conditional(...cases)(data);
|
|
44
59
|
* @example
|
|
45
|
-
* const nameOrId = 3 as string | number;
|
|
60
|
+
* const nameOrId = 3 as string | number | boolean;
|
|
61
|
+
*
|
|
46
62
|
* P.pipe(
|
|
47
63
|
* nameOrId,
|
|
48
64
|
* P.conditional(
|
|
49
65
|
* [P.isString, (name) => `Hello ${name}`],
|
|
50
66
|
* [P.isNumber, (id) => `Hello ID: ${id}`],
|
|
51
|
-
* P.conditional.defaultCase(
|
|
52
|
-
* (something) => `Hello something (${JSON.stringify(something)})`,
|
|
53
|
-
* ),
|
|
54
67
|
* ),
|
|
55
|
-
* ); //=> 'Hello ID: 3'
|
|
68
|
+
* ); //=> 'Hello ID: 3' (typed as `string`), can throw!.
|
|
69
|
+
*
|
|
70
|
+
* P.pipe(
|
|
71
|
+
* nameOrId,
|
|
72
|
+
* P.conditional(
|
|
73
|
+
* [P.isString, (name) => `Hello ${name}`],
|
|
74
|
+
* [P.isNumber, (id) => `Hello ID: ${id}`],
|
|
75
|
+
* P.constant(undefined),
|
|
76
|
+
* ),
|
|
77
|
+
* ); //=> 'Hello ID: 3' (typed as `string | undefined`), won't throw.
|
|
78
|
+
*
|
|
79
|
+
* P.pipe(
|
|
80
|
+
* nameOrId,
|
|
81
|
+
* P.conditional(
|
|
82
|
+
* [P.isString, (name) => `Hello ${name}`],
|
|
83
|
+
* [P.isNumber, (id) => `Hello ID: ${id}`],
|
|
84
|
+
* (something) => `Hello something (${JSON.stringify(something)})`,
|
|
85
|
+
* ),
|
|
86
|
+
* ); //=> 'Hello ID: 3' (typed as `string`), won't throw.
|
|
56
87
|
* @dataLast
|
|
57
88
|
* @category Function
|
|
58
89
|
*/
|
|
59
|
-
declare function conditional<T, Fn0 extends (x: T) => boolean,
|
|
90
|
+
declare function conditional<T, Fn0 extends (x: T) => boolean, Return0, Fallback = never>(case0: Case<T, Return0, Fn0>, fallback?: DefaultCase<T, Fallback>): (data: T) => Return0 | Fallback;
|
|
91
|
+
declare function conditional<T, Fn0 extends (x: T) => boolean, Fn1 extends (x: T) => boolean, Return0, Return1, Fallback = never>(case0: Case<T, Return0, Fn0>, case1: Case<T, Return1, Fn1>, fallback?: DefaultCase<T, Fallback>): (data: T) => Return0 | Return1 | Fallback;
|
|
92
|
+
declare function conditional<T, Fn0 extends (x: T) => boolean, Fn1 extends (x: T) => boolean, Fn2 extends (x: T) => boolean, Return0, Return1, Return2, Fallback = never>(case0: Case<T, Return0, Fn0>, case1: Case<T, Return1, Fn1>, case2: Case<T, Return2, Fn2>, fallback?: DefaultCase<T, Fallback>): (data: T) => Return0 | Return1 | Return2 | Fallback;
|
|
93
|
+
declare function conditional<T, Fn0 extends (x: T) => boolean, Fn1 extends (x: T) => boolean, Fn2 extends (x: T) => boolean, Fn3 extends (x: T) => boolean, Return0, Return1, Return2, Return3, Fallback = never>(case0: Case<T, Return0, Fn0>, case1: Case<T, Return1, Fn1>, case2: Case<T, Return2, Fn2>, case3: Case<T, Return3, Fn3>, fallback?: DefaultCase<T, Fallback>): (data: T) => Return0 | Return1 | Return2 | Return3 | Fallback;
|
|
94
|
+
declare function conditional<T, Fn0 extends (x: T) => boolean, Fn1 extends (x: T) => boolean, Fn2 extends (x: T) => boolean, Fn3 extends (x: T) => boolean, Fn4 extends (x: T) => boolean, Return0, Return1, Return2, Return3, Return4, Fallback = never>(case0: Case<T, Return0, Fn0>, case1: Case<T, Return1, Fn1>, case2: Case<T, Return2, Fn2>, case3: Case<T, Return3, Fn3>, case4: Case<T, Return4, Fn4>, fallback?: DefaultCase<T, Fallback>): (data: T) => Return0 | Return1 | Return2 | Return3 | Return4 | Fallback;
|
|
95
|
+
declare function conditional<T, Fn0 extends (x: T) => boolean, Fn1 extends (x: T) => boolean, Fn2 extends (x: T) => boolean, Fn3 extends (x: T) => boolean, Fn4 extends (x: T) => boolean, Fn5 extends (x: T) => boolean, Return0, Return1, Return2, Return3, Return4, Return5, Fallback = never>(case0: Case<T, Return0, Fn0>, case1: Case<T, Return1, Fn1>, case2: Case<T, Return2, Fn2>, case3: Case<T, Return3, Fn3>, case4: Case<T, Return4, Fn4>, case5: Case<T, Return5, Fn5>, fallback?: DefaultCase<T, Fallback>): (data: T) => Return0 | Return1 | Return2 | Return3 | Return4 | Return5 | Fallback;
|
|
96
|
+
declare function conditional<T, Fn0 extends (x: T) => boolean, Fn1 extends (x: T) => boolean, Fn2 extends (x: T) => boolean, Fn3 extends (x: T) => boolean, Fn4 extends (x: T) => boolean, Fn5 extends (x: T) => boolean, Fn6 extends (x: T) => boolean, Return0, Return1, Return2, Return3, Return4, Return5, Return6, Fallback = never>(case0: Case<T, Return0, Fn0>, case1: Case<T, Return1, Fn1>, case2: Case<T, Return2, Fn2>, case3: Case<T, Return3, Fn3>, case4: Case<T, Return4, Fn4>, case5: Case<T, Return5, Fn5>, case6: Case<T, Return6, Fn6>, fallback?: DefaultCase<T, Fallback>): (data: T) => Return0 | Return1 | Return2 | Return3 | Return4 | Return5 | Return6 | Fallback;
|
|
97
|
+
declare function conditional<T, Fn0 extends (x: T) => boolean, Fn1 extends (x: T) => boolean, Fn2 extends (x: T) => boolean, Fn3 extends (x: T) => boolean, Fn4 extends (x: T) => boolean, Fn5 extends (x: T) => boolean, Fn6 extends (x: T) => boolean, Fn7 extends (x: T) => boolean, Return0, Return1, Return2, Return3, Return4, Return5, Return6, Return7, Fallback = never>(case0: Case<T, Return0, Fn0>, case1: Case<T, Return1, Fn1>, case2: Case<T, Return2, Fn2>, case3: Case<T, Return3, Fn3>, case4: Case<T, Return4, Fn4>, case5: Case<T, Return5, Fn5>, case6: Case<T, Return6, Fn6>, case7: Case<T, Return7, Fn7>, fallback?: DefaultCase<T, Fallback>): (data: T) => Return0 | Return1 | Return2 | Return3 | Return4 | Return5 | Return6 | Return7 | Fallback;
|
|
98
|
+
declare function conditional<T, Fn0 extends (x: T) => boolean, Fn1 extends (x: T) => boolean, Fn2 extends (x: T) => boolean, Fn3 extends (x: T) => boolean, Fn4 extends (x: T) => boolean, Fn5 extends (x: T) => boolean, Fn6 extends (x: T) => boolean, Fn7 extends (x: T) => boolean, Fn8 extends (x: T) => boolean, Return0, Return1, Return2, Return3, Return4, Return5, Return6, Return7, Return8, Fallback = never>(case0: Case<T, Return0, Fn0>, case1: Case<T, Return1, Fn1>, case2: Case<T, Return2, Fn2>, case3: Case<T, Return3, Fn3>, case4: Case<T, Return4, Fn4>, case5: Case<T, Return5, Fn5>, case6: Case<T, Return6, Fn6>, case7: Case<T, Return7, Fn7>, case8: Case<T, Return8, Fn8>, fallback?: DefaultCase<T, Fallback>): (data: T) => Return0 | Return1 | Return2 | Return3 | Return4 | Return5 | Return6 | Return7 | Return8 | Fallback;
|
|
99
|
+
declare function conditional<T, Fn0 extends (x: T) => boolean, Fn1 extends (x: T) => boolean, Fn2 extends (x: T) => boolean, Fn3 extends (x: T) => boolean, Fn4 extends (x: T) => boolean, Fn5 extends (x: T) => boolean, Fn6 extends (x: T) => boolean, Fn7 extends (x: T) => boolean, Fn8 extends (x: T) => boolean, Fn9 extends (x: T) => boolean, Return0, Return1, Return2, Return3, Return4, Return5, Return6, Return7, Return8, Return9, Fallback = never>(case0: Case<T, Return0, Fn0>, case1: Case<T, Return1, Fn1>, case2: Case<T, Return2, Fn2>, case3: Case<T, Return3, Fn3>, case4: Case<T, Return4, Fn4>, case5: Case<T, Return5, Fn5>, case6: Case<T, Return6, Fn6>, case7: Case<T, Return7, Fn7>, case8: Case<T, Return8, Fn8>, case9: Case<T, Return9, Fn9>, fallback?: DefaultCase<T, Fallback>): (data: T) => Return0 | Return1 | Return2 | Return3 | Return4 | Return5 | Return6 | Return7 | Return8 | Return9 | Fallback;
|
|
60
100
|
/**
|
|
61
101
|
* Executes a transformer function based on the first matching predicate,
|
|
62
102
|
* functioning like a series of `if...else if...` statements. It sequentially
|
|
@@ -64,13 +104,18 @@ declare function conditional<T, Fn0 extends (x: T) => boolean, Fn1 extends (x: T
|
|
|
64
104
|
* corresponding transformer, and returns, ignoring any further cases, even if
|
|
65
105
|
* they would match.
|
|
66
106
|
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
107
|
+
* NOTE*: Some type-predicates may fail to narrow the param type of their
|
|
108
|
+
* transformer; in such cases wrap your type-predicate in an anonymous arrow
|
|
109
|
+
* function: e.g., instead of
|
|
110
|
+
* `conditional(..., [myTypePredicate, myTransformer], ...)`, use
|
|
111
|
+
* `conditional(..., [($) => myTypePredicate($), myTransformer], ...)`.
|
|
112
|
+
*
|
|
113
|
+
* To add a a default, catch-all, case you can provide a single callback
|
|
114
|
+
* function (instead of a 2-tuple) as the last case. This is equivalent to
|
|
115
|
+
* adding a case with a trivial always-true predicate as it's condition (see
|
|
116
|
+
* example).
|
|
117
|
+
*
|
|
118
|
+
* For simpler cases you should also consider using `when` instead.
|
|
74
119
|
*
|
|
75
120
|
* Due to TypeScript's inability to infer the result of negating a type-
|
|
76
121
|
* predicate we can't refine the types used in subsequent cases based on
|
|
@@ -78,34 +123,76 @@ declare function conditional<T, Fn0 extends (x: T) => boolean, Fn1 extends (x: T
|
|
|
78
123
|
* is recommended for more precise type control when such type narrowing is
|
|
79
124
|
* needed.
|
|
80
125
|
*
|
|
126
|
+
* !IMPORTANT! - Unlike similar implementations in Lodash and Ramda, this
|
|
127
|
+
* implementation **doesn't** implicitly return `undefined` as a fallback when
|
|
128
|
+
* when none of the cases match; and instead **throws** an exception in those
|
|
129
|
+
* cases! You have to explicitly provide a default case, and can use
|
|
130
|
+
* `constant(undefined)` as your last case to replicate that behavior.
|
|
131
|
+
*
|
|
81
132
|
* @param data - The input data to be evaluated against the provided cases.
|
|
82
|
-
* @param cases - A list of (up to 10)
|
|
83
|
-
*
|
|
84
|
-
* processes the data if
|
|
133
|
+
* @param cases - A list of (up to 10) cases. Each case can be either:
|
|
134
|
+
* - A 2-tuple consisting of a predicate (or type-predicate) and a transformer
|
|
135
|
+
* function that processes the data if the predicate matches.
|
|
136
|
+
* - A single callback function that acts as a default fallback case.
|
|
85
137
|
* @returns The output of the matched transformer. If no cases match, an
|
|
86
138
|
* exception is thrown. The return type is a union of the return types of all
|
|
87
139
|
* provided transformers.
|
|
88
140
|
* @signature
|
|
89
141
|
* P.conditional(data, ...cases);
|
|
90
142
|
* @example
|
|
91
|
-
* const nameOrId = 3 as string | number;
|
|
143
|
+
* const nameOrId = 3 as string | number | boolean;
|
|
144
|
+
*
|
|
92
145
|
* P.conditional(
|
|
93
146
|
* nameOrId,
|
|
94
147
|
* [P.isString, (name) => `Hello ${name}`],
|
|
95
148
|
* [P.isNumber, (id) => `Hello ID: ${id}`],
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
149
|
+
* ); //=> 'Hello ID: 3' (typed as `string`), can throw!.
|
|
150
|
+
*
|
|
151
|
+
* P.conditional(
|
|
152
|
+
* nameOrId,
|
|
153
|
+
* [P.isString, (name) => `Hello ${name}`],
|
|
154
|
+
* [P.isNumber, (id) => `Hello ID: ${id}`],
|
|
155
|
+
* P.constant(undefined),
|
|
156
|
+
* ); //=> 'Hello ID: 3' (typed as `string | undefined`), won't throw.
|
|
157
|
+
*
|
|
158
|
+
* P.conditional(
|
|
159
|
+
* nameOrId,
|
|
160
|
+
* [P.isString, (name) => `Hello ${name}`],
|
|
161
|
+
* [P.isNumber, (id) => `Hello ID: ${id}`],
|
|
162
|
+
* (something) => `Hello something (${JSON.stringify(something)})`,
|
|
163
|
+
* ); //=> 'Hello ID: 3' (typed as `string`), won't throw.
|
|
100
164
|
* @dataFirst
|
|
101
165
|
* @category Function
|
|
102
166
|
*/
|
|
103
|
-
declare function conditional<T, Fn0 extends (x: T) => boolean,
|
|
167
|
+
declare function conditional<T, Fn0 extends (x: T) => boolean, Return0, Fallback = never>(data: T, case0: Case<T, Return0, Fn0>, fallback?: DefaultCase<T, Fallback>): Return0 | Fallback;
|
|
168
|
+
declare function conditional<T, Fn0 extends (x: T) => boolean, Fn1 extends (x: T) => boolean, Return0, Return1, Fallback = never>(data: T, case0: Case<T, Return0, Fn0>, case1: Case<T, Return1, Fn1>, fallback?: DefaultCase<T, Fallback>): Return0 | Return1 | Fallback;
|
|
169
|
+
declare function conditional<T, Fn0 extends (x: T) => boolean, Fn1 extends (x: T) => boolean, Fn2 extends (x: T) => boolean, Return0, Return1, Return2, Fallback = never>(data: T, case0: Case<T, Return0, Fn0>, case1: Case<T, Return1, Fn1>, case2: Case<T, Return2, Fn2>, fallback?: DefaultCase<T, Fallback>): Return0 | Return1 | Return2 | Fallback;
|
|
170
|
+
declare function conditional<T, Fn0 extends (x: T) => boolean, Fn1 extends (x: T) => boolean, Fn2 extends (x: T) => boolean, Fn3 extends (x: T) => boolean, Return0, Return1, Return2, Return3, Fallback = never>(data: T, case0: Case<T, Return0, Fn0>, case1: Case<T, Return1, Fn1>, case2: Case<T, Return2, Fn2>, case3: Case<T, Return3, Fn3>, fallback?: DefaultCase<T, Fallback>): Return0 | Return1 | Return2 | Return3 | Fallback;
|
|
171
|
+
declare function conditional<T, Fn0 extends (x: T) => boolean, Fn1 extends (x: T) => boolean, Fn2 extends (x: T) => boolean, Fn3 extends (x: T) => boolean, Fn4 extends (x: T) => boolean, Return0, Return1, Return2, Return3, Return4, Fallback = never>(data: T, case0: Case<T, Return0, Fn0>, case1: Case<T, Return1, Fn1>, case2: Case<T, Return2, Fn2>, case3: Case<T, Return3, Fn3>, case4: Case<T, Return4, Fn4>, fallback?: DefaultCase<T, Fallback>): Return0 | Return1 | Return2 | Return3 | Return4 | Fallback;
|
|
172
|
+
declare function conditional<T, Fn0 extends (x: T) => boolean, Fn1 extends (x: T) => boolean, Fn2 extends (x: T) => boolean, Fn3 extends (x: T) => boolean, Fn4 extends (x: T) => boolean, Fn5 extends (x: T) => boolean, Return0, Return1, Return2, Return3, Return4, Return5, Fallback = never>(data: T, case0: Case<T, Return0, Fn0>, case1: Case<T, Return1, Fn1>, case2: Case<T, Return2, Fn2>, case3: Case<T, Return3, Fn3>, case4: Case<T, Return4, Fn4>, case5: Case<T, Return5, Fn5>, fallback?: DefaultCase<T, Fallback>): Return0 | Return1 | Return2 | Return3 | Return4 | Return5 | Fallback;
|
|
173
|
+
declare function conditional<T, Fn0 extends (x: T) => boolean, Fn1 extends (x: T) => boolean, Fn2 extends (x: T) => boolean, Fn3 extends (x: T) => boolean, Fn4 extends (x: T) => boolean, Fn5 extends (x: T) => boolean, Fn6 extends (x: T) => boolean, Return0, Return1, Return2, Return3, Return4, Return5, Return6, Fallback = never>(data: T, case0: Case<T, Return0, Fn0>, case1: Case<T, Return1, Fn1>, case2: Case<T, Return2, Fn2>, case3: Case<T, Return3, Fn3>, case4: Case<T, Return4, Fn4>, case5: Case<T, Return5, Fn5>, case6: Case<T, Return6, Fn6>, fallback?: DefaultCase<T, Fallback>): Return0 | Return1 | Return2 | Return3 | Return4 | Return5 | Return6 | Fallback;
|
|
174
|
+
declare function conditional<T, Fn0 extends (x: T) => boolean, Fn1 extends (x: T) => boolean, Fn2 extends (x: T) => boolean, Fn3 extends (x: T) => boolean, Fn4 extends (x: T) => boolean, Fn5 extends (x: T) => boolean, Fn6 extends (x: T) => boolean, Fn7 extends (x: T) => boolean, Return0, Return1, Return2, Return3, Return4, Return5, Return6, Return7, Fallback = never>(data: T, case0: Case<T, Return0, Fn0>, case1: Case<T, Return1, Fn1>, case2: Case<T, Return2, Fn2>, case3: Case<T, Return3, Fn3>, case4: Case<T, Return4, Fn4>, case5: Case<T, Return5, Fn5>, case6: Case<T, Return6, Fn6>, case7: Case<T, Return7, Fn7>, fallback?: DefaultCase<T, Fallback>): Return0 | Return1 | Return2 | Return3 | Return4 | Return5 | Return6 | Return7 | Fallback;
|
|
175
|
+
declare function conditional<T, Fn0 extends (x: T) => boolean, Fn1 extends (x: T) => boolean, Fn2 extends (x: T) => boolean, Fn3 extends (x: T) => boolean, Fn4 extends (x: T) => boolean, Fn5 extends (x: T) => boolean, Fn6 extends (x: T) => boolean, Fn7 extends (x: T) => boolean, Fn8 extends (x: T) => boolean, Return0, Return1, Return2, Return3, Return4, Return5, Return6, Return7, Return8, Fallback = never>(data: T, case0: Case<T, Return0, Fn0>, case1: Case<T, Return1, Fn1>, case2: Case<T, Return2, Fn2>, case3: Case<T, Return3, Fn3>, case4: Case<T, Return4, Fn4>, case5: Case<T, Return5, Fn5>, case6: Case<T, Return6, Fn6>, case7: Case<T, Return7, Fn7>, case8: Case<T, Return8, Fn8>, fallback?: DefaultCase<T, Fallback>): Return0 | Return1 | Return2 | Return3 | Return4 | Return5 | Return6 | Return7 | Return8 | Fallback;
|
|
176
|
+
declare function conditional<T, Fn0 extends (x: T) => boolean, Fn1 extends (x: T) => boolean, Fn2 extends (x: T) => boolean, Fn3 extends (x: T) => boolean, Fn4 extends (x: T) => boolean, Fn5 extends (x: T) => boolean, Fn6 extends (x: T) => boolean, Fn7 extends (x: T) => boolean, Fn8 extends (x: T) => boolean, Fn9 extends (x: T) => boolean, Return0, Return1, Return2, Return3, Return4, Return5, Return6, Return7, Return8, Return9, Fallback = never>(data: T, case0: Case<T, Return0, Fn0>, case1: Case<T, Return1, Fn1>, case2: Case<T, Return2, Fn2>, case3: Case<T, Return3, Fn3>, case4: Case<T, Return4, Fn4>, case5: Case<T, Return5, Fn5>, case6: Case<T, Return6, Fn6>, case7: Case<T, Return7, Fn7>, case8: Case<T, Return8, Fn8>, case9: Case<T, Return9, Fn9>, fallback?: DefaultCase<T, Fallback>): Return0 | Return1 | Return2 | Return3 | Return4 | Return5 | Return6 | Return7 | Return8 | Return9 | Fallback;
|
|
177
|
+
/**
|
|
178
|
+
*! **DEPRECATED**: `conditional` now accepts a default, catch-all, callback directly and no longer needs this utility wrapper. Use `constant(undefined)` as your last case instead (see example).
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* const nameOrId = 3 as string | number;
|
|
182
|
+
* P.conditional(
|
|
183
|
+
* nameOrId,
|
|
184
|
+
* [P.isString, (name) => `Hello ${name}`],
|
|
185
|
+
* [P.isNumber, (id) => `Hello ID: ${id}`],
|
|
186
|
+
* // Was: `P.conditional.defaultCase(),`, Now:
|
|
187
|
+
* constant(undefined),
|
|
188
|
+
* ); //=> 'Hello ID: 3'
|
|
189
|
+
* @deprecated `conditional` now accepts a default, catch-all, callback
|
|
190
|
+
* directly and no longer needs this utility wrapper. Use `constant(undefined)`
|
|
191
|
+
* as your last case instead (see example).
|
|
192
|
+
*/
|
|
193
|
+
declare function defaultCase(): Case<unknown, undefined>;
|
|
104
194
|
/**
|
|
105
|
-
|
|
106
|
-
* prevent an exception from being thrown when none of the previous cases
|
|
107
|
-
* match.
|
|
108
|
-
* If this is not the last case it will short-circuit anything after it.
|
|
195
|
+
*! **DEPRECATED**: `conditional` now accepts a default, catch-all, callback directly and no longer needs this utility wrapper. Simply put your `then` callback as the last case (see example).
|
|
109
196
|
*
|
|
110
197
|
* @param then - You only need to provide the transformer, the predicate is
|
|
111
198
|
* implicit. @default () => undefined, which is how Lodash and Ramda handle
|
|
@@ -116,12 +203,15 @@ declare function conditional<T, Fn0 extends (x: T) => boolean, Fn1 extends (x: T
|
|
|
116
203
|
* nameOrId,
|
|
117
204
|
* [P.isString, (name) => `Hello ${name}`],
|
|
118
205
|
* [P.isNumber, (id) => `Hello ID: ${id}`],
|
|
119
|
-
* P.conditional.defaultCase(
|
|
120
|
-
*
|
|
121
|
-
* )
|
|
206
|
+
* // Was: `P.conditional.defaultCase(
|
|
207
|
+
* // (something) => `Hello something (${JSON.stringify(something)})`,
|
|
208
|
+
* //),`, Now:
|
|
209
|
+
* (something) => `Hello something (${JSON.stringify(something)})`
|
|
122
210
|
* ); //=> 'Hello ID: 3'
|
|
211
|
+
* @deprecated `conditional` now accepts a default, catch-all, callback
|
|
212
|
+
* directly and no longer needs this utility wrapper. Simply put your `then`
|
|
213
|
+
* callback as the last case.
|
|
123
214
|
*/
|
|
124
|
-
declare function defaultCase(): Case<unknown, undefined>;
|
|
125
215
|
declare function defaultCase<In, Then extends (param: In) => unknown>(then: Then): Case<In, ReturnType<Then>>;
|
|
126
216
|
|
|
127
217
|
export { conditionalPlus as conditional };
|
package/dist/conditional.d.ts
CHANGED
|
@@ -8,9 +8,12 @@
|
|
|
8
8
|
type GuardType<T, Fallback = never> = T extends (x: any, ...rest: any) => x is infer U ? U : Fallback;
|
|
9
9
|
|
|
10
10
|
type Case<In, Out, When extends (x: In) => boolean = (x: In) => boolean> = readonly [when: When, then: (x: GuardType<When, In> & In) => Out];
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
type DefaultCase<In, Out> = (x: In) => Out;
|
|
12
|
+
interface Utilities {
|
|
13
|
+
readonly defaultCase: typeof defaultCase;
|
|
14
|
+
}
|
|
15
|
+
type WithUtils<T> = T & Utilities;
|
|
16
|
+
declare const conditionalPlus: WithUtils<typeof conditional>;
|
|
14
17
|
|
|
15
18
|
/**
|
|
16
19
|
* Executes a transformer function based on the first matching predicate,
|
|
@@ -19,13 +22,18 @@ declare const conditionalPlus: typeof conditional & {
|
|
|
19
22
|
* corresponding transformer, and returns, ignoring any further cases, even if
|
|
20
23
|
* they would match.
|
|
21
24
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
25
|
+
* NOTE*: Some type-predicates may fail to narrow the param type of their
|
|
26
|
+
* transformer; in such cases wrap your type-predicate in an anonymous arrow
|
|
27
|
+
* function: e.g., instead of
|
|
28
|
+
* `conditional(..., [myTypePredicate, myTransformer], ...)`, use
|
|
29
|
+
* `conditional(..., [($) => myTypePredicate($), myTransformer], ...)`.
|
|
30
|
+
*
|
|
31
|
+
* To add a a default, catch-all, case you can provide a single callback
|
|
32
|
+
* function (instead of a 2-tuple) as the last case. This is equivalent to
|
|
33
|
+
* adding a case with a trivial always-true predicate as it's condition (see
|
|
34
|
+
* example).
|
|
35
|
+
*
|
|
36
|
+
* For simpler cases you should also consider using `when` instead.
|
|
29
37
|
*
|
|
30
38
|
* Due to TypeScript's inability to infer the result of negating a type-
|
|
31
39
|
* predicate we can't refine the types used in subsequent cases based on
|
|
@@ -33,30 +41,62 @@ declare const conditionalPlus: typeof conditional & {
|
|
|
33
41
|
* is recommended for more precise type control when such type narrowing is
|
|
34
42
|
* needed.
|
|
35
43
|
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
44
|
+
* !IMPORTANT! - Unlike similar implementations in Lodash and Ramda, this
|
|
45
|
+
* implementation **doesn't** implicitly return `undefined` as a fallback when
|
|
46
|
+
* when none of the cases match; and instead **throws** an exception in those
|
|
47
|
+
* cases! You have to explicitly provide a default case, and can use
|
|
48
|
+
* `constant(undefined)` as your last case to replicate that behavior.
|
|
49
|
+
*
|
|
50
|
+
* @param cases - A list of (up to 10) cases. Each case can be either:
|
|
51
|
+
* - A 2-tuple consisting of a predicate (or type-predicate) and a transformer
|
|
52
|
+
* function that processes the data if the predicate matches.
|
|
53
|
+
* - A single callback function that acts as a default fallback case.
|
|
39
54
|
* @returns The output of the matched transformer. If no cases match, an
|
|
40
55
|
* exception is thrown. The return type is a union of the return types of all
|
|
41
56
|
* provided transformers.
|
|
42
57
|
* @signature
|
|
43
58
|
* P.conditional(...cases)(data);
|
|
44
59
|
* @example
|
|
45
|
-
* const nameOrId = 3 as string | number;
|
|
60
|
+
* const nameOrId = 3 as string | number | boolean;
|
|
61
|
+
*
|
|
46
62
|
* P.pipe(
|
|
47
63
|
* nameOrId,
|
|
48
64
|
* P.conditional(
|
|
49
65
|
* [P.isString, (name) => `Hello ${name}`],
|
|
50
66
|
* [P.isNumber, (id) => `Hello ID: ${id}`],
|
|
51
|
-
* P.conditional.defaultCase(
|
|
52
|
-
* (something) => `Hello something (${JSON.stringify(something)})`,
|
|
53
|
-
* ),
|
|
54
67
|
* ),
|
|
55
|
-
* ); //=> 'Hello ID: 3'
|
|
68
|
+
* ); //=> 'Hello ID: 3' (typed as `string`), can throw!.
|
|
69
|
+
*
|
|
70
|
+
* P.pipe(
|
|
71
|
+
* nameOrId,
|
|
72
|
+
* P.conditional(
|
|
73
|
+
* [P.isString, (name) => `Hello ${name}`],
|
|
74
|
+
* [P.isNumber, (id) => `Hello ID: ${id}`],
|
|
75
|
+
* P.constant(undefined),
|
|
76
|
+
* ),
|
|
77
|
+
* ); //=> 'Hello ID: 3' (typed as `string | undefined`), won't throw.
|
|
78
|
+
*
|
|
79
|
+
* P.pipe(
|
|
80
|
+
* nameOrId,
|
|
81
|
+
* P.conditional(
|
|
82
|
+
* [P.isString, (name) => `Hello ${name}`],
|
|
83
|
+
* [P.isNumber, (id) => `Hello ID: ${id}`],
|
|
84
|
+
* (something) => `Hello something (${JSON.stringify(something)})`,
|
|
85
|
+
* ),
|
|
86
|
+
* ); //=> 'Hello ID: 3' (typed as `string`), won't throw.
|
|
56
87
|
* @dataLast
|
|
57
88
|
* @category Function
|
|
58
89
|
*/
|
|
59
|
-
declare function conditional<T, Fn0 extends (x: T) => boolean,
|
|
90
|
+
declare function conditional<T, Fn0 extends (x: T) => boolean, Return0, Fallback = never>(case0: Case<T, Return0, Fn0>, fallback?: DefaultCase<T, Fallback>): (data: T) => Return0 | Fallback;
|
|
91
|
+
declare function conditional<T, Fn0 extends (x: T) => boolean, Fn1 extends (x: T) => boolean, Return0, Return1, Fallback = never>(case0: Case<T, Return0, Fn0>, case1: Case<T, Return1, Fn1>, fallback?: DefaultCase<T, Fallback>): (data: T) => Return0 | Return1 | Fallback;
|
|
92
|
+
declare function conditional<T, Fn0 extends (x: T) => boolean, Fn1 extends (x: T) => boolean, Fn2 extends (x: T) => boolean, Return0, Return1, Return2, Fallback = never>(case0: Case<T, Return0, Fn0>, case1: Case<T, Return1, Fn1>, case2: Case<T, Return2, Fn2>, fallback?: DefaultCase<T, Fallback>): (data: T) => Return0 | Return1 | Return2 | Fallback;
|
|
93
|
+
declare function conditional<T, Fn0 extends (x: T) => boolean, Fn1 extends (x: T) => boolean, Fn2 extends (x: T) => boolean, Fn3 extends (x: T) => boolean, Return0, Return1, Return2, Return3, Fallback = never>(case0: Case<T, Return0, Fn0>, case1: Case<T, Return1, Fn1>, case2: Case<T, Return2, Fn2>, case3: Case<T, Return3, Fn3>, fallback?: DefaultCase<T, Fallback>): (data: T) => Return0 | Return1 | Return2 | Return3 | Fallback;
|
|
94
|
+
declare function conditional<T, Fn0 extends (x: T) => boolean, Fn1 extends (x: T) => boolean, Fn2 extends (x: T) => boolean, Fn3 extends (x: T) => boolean, Fn4 extends (x: T) => boolean, Return0, Return1, Return2, Return3, Return4, Fallback = never>(case0: Case<T, Return0, Fn0>, case1: Case<T, Return1, Fn1>, case2: Case<T, Return2, Fn2>, case3: Case<T, Return3, Fn3>, case4: Case<T, Return4, Fn4>, fallback?: DefaultCase<T, Fallback>): (data: T) => Return0 | Return1 | Return2 | Return3 | Return4 | Fallback;
|
|
95
|
+
declare function conditional<T, Fn0 extends (x: T) => boolean, Fn1 extends (x: T) => boolean, Fn2 extends (x: T) => boolean, Fn3 extends (x: T) => boolean, Fn4 extends (x: T) => boolean, Fn5 extends (x: T) => boolean, Return0, Return1, Return2, Return3, Return4, Return5, Fallback = never>(case0: Case<T, Return0, Fn0>, case1: Case<T, Return1, Fn1>, case2: Case<T, Return2, Fn2>, case3: Case<T, Return3, Fn3>, case4: Case<T, Return4, Fn4>, case5: Case<T, Return5, Fn5>, fallback?: DefaultCase<T, Fallback>): (data: T) => Return0 | Return1 | Return2 | Return3 | Return4 | Return5 | Fallback;
|
|
96
|
+
declare function conditional<T, Fn0 extends (x: T) => boolean, Fn1 extends (x: T) => boolean, Fn2 extends (x: T) => boolean, Fn3 extends (x: T) => boolean, Fn4 extends (x: T) => boolean, Fn5 extends (x: T) => boolean, Fn6 extends (x: T) => boolean, Return0, Return1, Return2, Return3, Return4, Return5, Return6, Fallback = never>(case0: Case<T, Return0, Fn0>, case1: Case<T, Return1, Fn1>, case2: Case<T, Return2, Fn2>, case3: Case<T, Return3, Fn3>, case4: Case<T, Return4, Fn4>, case5: Case<T, Return5, Fn5>, case6: Case<T, Return6, Fn6>, fallback?: DefaultCase<T, Fallback>): (data: T) => Return0 | Return1 | Return2 | Return3 | Return4 | Return5 | Return6 | Fallback;
|
|
97
|
+
declare function conditional<T, Fn0 extends (x: T) => boolean, Fn1 extends (x: T) => boolean, Fn2 extends (x: T) => boolean, Fn3 extends (x: T) => boolean, Fn4 extends (x: T) => boolean, Fn5 extends (x: T) => boolean, Fn6 extends (x: T) => boolean, Fn7 extends (x: T) => boolean, Return0, Return1, Return2, Return3, Return4, Return5, Return6, Return7, Fallback = never>(case0: Case<T, Return0, Fn0>, case1: Case<T, Return1, Fn1>, case2: Case<T, Return2, Fn2>, case3: Case<T, Return3, Fn3>, case4: Case<T, Return4, Fn4>, case5: Case<T, Return5, Fn5>, case6: Case<T, Return6, Fn6>, case7: Case<T, Return7, Fn7>, fallback?: DefaultCase<T, Fallback>): (data: T) => Return0 | Return1 | Return2 | Return3 | Return4 | Return5 | Return6 | Return7 | Fallback;
|
|
98
|
+
declare function conditional<T, Fn0 extends (x: T) => boolean, Fn1 extends (x: T) => boolean, Fn2 extends (x: T) => boolean, Fn3 extends (x: T) => boolean, Fn4 extends (x: T) => boolean, Fn5 extends (x: T) => boolean, Fn6 extends (x: T) => boolean, Fn7 extends (x: T) => boolean, Fn8 extends (x: T) => boolean, Return0, Return1, Return2, Return3, Return4, Return5, Return6, Return7, Return8, Fallback = never>(case0: Case<T, Return0, Fn0>, case1: Case<T, Return1, Fn1>, case2: Case<T, Return2, Fn2>, case3: Case<T, Return3, Fn3>, case4: Case<T, Return4, Fn4>, case5: Case<T, Return5, Fn5>, case6: Case<T, Return6, Fn6>, case7: Case<T, Return7, Fn7>, case8: Case<T, Return8, Fn8>, fallback?: DefaultCase<T, Fallback>): (data: T) => Return0 | Return1 | Return2 | Return3 | Return4 | Return5 | Return6 | Return7 | Return8 | Fallback;
|
|
99
|
+
declare function conditional<T, Fn0 extends (x: T) => boolean, Fn1 extends (x: T) => boolean, Fn2 extends (x: T) => boolean, Fn3 extends (x: T) => boolean, Fn4 extends (x: T) => boolean, Fn5 extends (x: T) => boolean, Fn6 extends (x: T) => boolean, Fn7 extends (x: T) => boolean, Fn8 extends (x: T) => boolean, Fn9 extends (x: T) => boolean, Return0, Return1, Return2, Return3, Return4, Return5, Return6, Return7, Return8, Return9, Fallback = never>(case0: Case<T, Return0, Fn0>, case1: Case<T, Return1, Fn1>, case2: Case<T, Return2, Fn2>, case3: Case<T, Return3, Fn3>, case4: Case<T, Return4, Fn4>, case5: Case<T, Return5, Fn5>, case6: Case<T, Return6, Fn6>, case7: Case<T, Return7, Fn7>, case8: Case<T, Return8, Fn8>, case9: Case<T, Return9, Fn9>, fallback?: DefaultCase<T, Fallback>): (data: T) => Return0 | Return1 | Return2 | Return3 | Return4 | Return5 | Return6 | Return7 | Return8 | Return9 | Fallback;
|
|
60
100
|
/**
|
|
61
101
|
* Executes a transformer function based on the first matching predicate,
|
|
62
102
|
* functioning like a series of `if...else if...` statements. It sequentially
|
|
@@ -64,13 +104,18 @@ declare function conditional<T, Fn0 extends (x: T) => boolean, Fn1 extends (x: T
|
|
|
64
104
|
* corresponding transformer, and returns, ignoring any further cases, even if
|
|
65
105
|
* they would match.
|
|
66
106
|
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
107
|
+
* NOTE*: Some type-predicates may fail to narrow the param type of their
|
|
108
|
+
* transformer; in such cases wrap your type-predicate in an anonymous arrow
|
|
109
|
+
* function: e.g., instead of
|
|
110
|
+
* `conditional(..., [myTypePredicate, myTransformer], ...)`, use
|
|
111
|
+
* `conditional(..., [($) => myTypePredicate($), myTransformer], ...)`.
|
|
112
|
+
*
|
|
113
|
+
* To add a a default, catch-all, case you can provide a single callback
|
|
114
|
+
* function (instead of a 2-tuple) as the last case. This is equivalent to
|
|
115
|
+
* adding a case with a trivial always-true predicate as it's condition (see
|
|
116
|
+
* example).
|
|
117
|
+
*
|
|
118
|
+
* For simpler cases you should also consider using `when` instead.
|
|
74
119
|
*
|
|
75
120
|
* Due to TypeScript's inability to infer the result of negating a type-
|
|
76
121
|
* predicate we can't refine the types used in subsequent cases based on
|
|
@@ -78,34 +123,76 @@ declare function conditional<T, Fn0 extends (x: T) => boolean, Fn1 extends (x: T
|
|
|
78
123
|
* is recommended for more precise type control when such type narrowing is
|
|
79
124
|
* needed.
|
|
80
125
|
*
|
|
126
|
+
* !IMPORTANT! - Unlike similar implementations in Lodash and Ramda, this
|
|
127
|
+
* implementation **doesn't** implicitly return `undefined` as a fallback when
|
|
128
|
+
* when none of the cases match; and instead **throws** an exception in those
|
|
129
|
+
* cases! You have to explicitly provide a default case, and can use
|
|
130
|
+
* `constant(undefined)` as your last case to replicate that behavior.
|
|
131
|
+
*
|
|
81
132
|
* @param data - The input data to be evaluated against the provided cases.
|
|
82
|
-
* @param cases - A list of (up to 10)
|
|
83
|
-
*
|
|
84
|
-
* processes the data if
|
|
133
|
+
* @param cases - A list of (up to 10) cases. Each case can be either:
|
|
134
|
+
* - A 2-tuple consisting of a predicate (or type-predicate) and a transformer
|
|
135
|
+
* function that processes the data if the predicate matches.
|
|
136
|
+
* - A single callback function that acts as a default fallback case.
|
|
85
137
|
* @returns The output of the matched transformer. If no cases match, an
|
|
86
138
|
* exception is thrown. The return type is a union of the return types of all
|
|
87
139
|
* provided transformers.
|
|
88
140
|
* @signature
|
|
89
141
|
* P.conditional(data, ...cases);
|
|
90
142
|
* @example
|
|
91
|
-
* const nameOrId = 3 as string | number;
|
|
143
|
+
* const nameOrId = 3 as string | number | boolean;
|
|
144
|
+
*
|
|
92
145
|
* P.conditional(
|
|
93
146
|
* nameOrId,
|
|
94
147
|
* [P.isString, (name) => `Hello ${name}`],
|
|
95
148
|
* [P.isNumber, (id) => `Hello ID: ${id}`],
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
149
|
+
* ); //=> 'Hello ID: 3' (typed as `string`), can throw!.
|
|
150
|
+
*
|
|
151
|
+
* P.conditional(
|
|
152
|
+
* nameOrId,
|
|
153
|
+
* [P.isString, (name) => `Hello ${name}`],
|
|
154
|
+
* [P.isNumber, (id) => `Hello ID: ${id}`],
|
|
155
|
+
* P.constant(undefined),
|
|
156
|
+
* ); //=> 'Hello ID: 3' (typed as `string | undefined`), won't throw.
|
|
157
|
+
*
|
|
158
|
+
* P.conditional(
|
|
159
|
+
* nameOrId,
|
|
160
|
+
* [P.isString, (name) => `Hello ${name}`],
|
|
161
|
+
* [P.isNumber, (id) => `Hello ID: ${id}`],
|
|
162
|
+
* (something) => `Hello something (${JSON.stringify(something)})`,
|
|
163
|
+
* ); //=> 'Hello ID: 3' (typed as `string`), won't throw.
|
|
100
164
|
* @dataFirst
|
|
101
165
|
* @category Function
|
|
102
166
|
*/
|
|
103
|
-
declare function conditional<T, Fn0 extends (x: T) => boolean,
|
|
167
|
+
declare function conditional<T, Fn0 extends (x: T) => boolean, Return0, Fallback = never>(data: T, case0: Case<T, Return0, Fn0>, fallback?: DefaultCase<T, Fallback>): Return0 | Fallback;
|
|
168
|
+
declare function conditional<T, Fn0 extends (x: T) => boolean, Fn1 extends (x: T) => boolean, Return0, Return1, Fallback = never>(data: T, case0: Case<T, Return0, Fn0>, case1: Case<T, Return1, Fn1>, fallback?: DefaultCase<T, Fallback>): Return0 | Return1 | Fallback;
|
|
169
|
+
declare function conditional<T, Fn0 extends (x: T) => boolean, Fn1 extends (x: T) => boolean, Fn2 extends (x: T) => boolean, Return0, Return1, Return2, Fallback = never>(data: T, case0: Case<T, Return0, Fn0>, case1: Case<T, Return1, Fn1>, case2: Case<T, Return2, Fn2>, fallback?: DefaultCase<T, Fallback>): Return0 | Return1 | Return2 | Fallback;
|
|
170
|
+
declare function conditional<T, Fn0 extends (x: T) => boolean, Fn1 extends (x: T) => boolean, Fn2 extends (x: T) => boolean, Fn3 extends (x: T) => boolean, Return0, Return1, Return2, Return3, Fallback = never>(data: T, case0: Case<T, Return0, Fn0>, case1: Case<T, Return1, Fn1>, case2: Case<T, Return2, Fn2>, case3: Case<T, Return3, Fn3>, fallback?: DefaultCase<T, Fallback>): Return0 | Return1 | Return2 | Return3 | Fallback;
|
|
171
|
+
declare function conditional<T, Fn0 extends (x: T) => boolean, Fn1 extends (x: T) => boolean, Fn2 extends (x: T) => boolean, Fn3 extends (x: T) => boolean, Fn4 extends (x: T) => boolean, Return0, Return1, Return2, Return3, Return4, Fallback = never>(data: T, case0: Case<T, Return0, Fn0>, case1: Case<T, Return1, Fn1>, case2: Case<T, Return2, Fn2>, case3: Case<T, Return3, Fn3>, case4: Case<T, Return4, Fn4>, fallback?: DefaultCase<T, Fallback>): Return0 | Return1 | Return2 | Return3 | Return4 | Fallback;
|
|
172
|
+
declare function conditional<T, Fn0 extends (x: T) => boolean, Fn1 extends (x: T) => boolean, Fn2 extends (x: T) => boolean, Fn3 extends (x: T) => boolean, Fn4 extends (x: T) => boolean, Fn5 extends (x: T) => boolean, Return0, Return1, Return2, Return3, Return4, Return5, Fallback = never>(data: T, case0: Case<T, Return0, Fn0>, case1: Case<T, Return1, Fn1>, case2: Case<T, Return2, Fn2>, case3: Case<T, Return3, Fn3>, case4: Case<T, Return4, Fn4>, case5: Case<T, Return5, Fn5>, fallback?: DefaultCase<T, Fallback>): Return0 | Return1 | Return2 | Return3 | Return4 | Return5 | Fallback;
|
|
173
|
+
declare function conditional<T, Fn0 extends (x: T) => boolean, Fn1 extends (x: T) => boolean, Fn2 extends (x: T) => boolean, Fn3 extends (x: T) => boolean, Fn4 extends (x: T) => boolean, Fn5 extends (x: T) => boolean, Fn6 extends (x: T) => boolean, Return0, Return1, Return2, Return3, Return4, Return5, Return6, Fallback = never>(data: T, case0: Case<T, Return0, Fn0>, case1: Case<T, Return1, Fn1>, case2: Case<T, Return2, Fn2>, case3: Case<T, Return3, Fn3>, case4: Case<T, Return4, Fn4>, case5: Case<T, Return5, Fn5>, case6: Case<T, Return6, Fn6>, fallback?: DefaultCase<T, Fallback>): Return0 | Return1 | Return2 | Return3 | Return4 | Return5 | Return6 | Fallback;
|
|
174
|
+
declare function conditional<T, Fn0 extends (x: T) => boolean, Fn1 extends (x: T) => boolean, Fn2 extends (x: T) => boolean, Fn3 extends (x: T) => boolean, Fn4 extends (x: T) => boolean, Fn5 extends (x: T) => boolean, Fn6 extends (x: T) => boolean, Fn7 extends (x: T) => boolean, Return0, Return1, Return2, Return3, Return4, Return5, Return6, Return7, Fallback = never>(data: T, case0: Case<T, Return0, Fn0>, case1: Case<T, Return1, Fn1>, case2: Case<T, Return2, Fn2>, case3: Case<T, Return3, Fn3>, case4: Case<T, Return4, Fn4>, case5: Case<T, Return5, Fn5>, case6: Case<T, Return6, Fn6>, case7: Case<T, Return7, Fn7>, fallback?: DefaultCase<T, Fallback>): Return0 | Return1 | Return2 | Return3 | Return4 | Return5 | Return6 | Return7 | Fallback;
|
|
175
|
+
declare function conditional<T, Fn0 extends (x: T) => boolean, Fn1 extends (x: T) => boolean, Fn2 extends (x: T) => boolean, Fn3 extends (x: T) => boolean, Fn4 extends (x: T) => boolean, Fn5 extends (x: T) => boolean, Fn6 extends (x: T) => boolean, Fn7 extends (x: T) => boolean, Fn8 extends (x: T) => boolean, Return0, Return1, Return2, Return3, Return4, Return5, Return6, Return7, Return8, Fallback = never>(data: T, case0: Case<T, Return0, Fn0>, case1: Case<T, Return1, Fn1>, case2: Case<T, Return2, Fn2>, case3: Case<T, Return3, Fn3>, case4: Case<T, Return4, Fn4>, case5: Case<T, Return5, Fn5>, case6: Case<T, Return6, Fn6>, case7: Case<T, Return7, Fn7>, case8: Case<T, Return8, Fn8>, fallback?: DefaultCase<T, Fallback>): Return0 | Return1 | Return2 | Return3 | Return4 | Return5 | Return6 | Return7 | Return8 | Fallback;
|
|
176
|
+
declare function conditional<T, Fn0 extends (x: T) => boolean, Fn1 extends (x: T) => boolean, Fn2 extends (x: T) => boolean, Fn3 extends (x: T) => boolean, Fn4 extends (x: T) => boolean, Fn5 extends (x: T) => boolean, Fn6 extends (x: T) => boolean, Fn7 extends (x: T) => boolean, Fn8 extends (x: T) => boolean, Fn9 extends (x: T) => boolean, Return0, Return1, Return2, Return3, Return4, Return5, Return6, Return7, Return8, Return9, Fallback = never>(data: T, case0: Case<T, Return0, Fn0>, case1: Case<T, Return1, Fn1>, case2: Case<T, Return2, Fn2>, case3: Case<T, Return3, Fn3>, case4: Case<T, Return4, Fn4>, case5: Case<T, Return5, Fn5>, case6: Case<T, Return6, Fn6>, case7: Case<T, Return7, Fn7>, case8: Case<T, Return8, Fn8>, case9: Case<T, Return9, Fn9>, fallback?: DefaultCase<T, Fallback>): Return0 | Return1 | Return2 | Return3 | Return4 | Return5 | Return6 | Return7 | Return8 | Return9 | Fallback;
|
|
177
|
+
/**
|
|
178
|
+
*! **DEPRECATED**: `conditional` now accepts a default, catch-all, callback directly and no longer needs this utility wrapper. Use `constant(undefined)` as your last case instead (see example).
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* const nameOrId = 3 as string | number;
|
|
182
|
+
* P.conditional(
|
|
183
|
+
* nameOrId,
|
|
184
|
+
* [P.isString, (name) => `Hello ${name}`],
|
|
185
|
+
* [P.isNumber, (id) => `Hello ID: ${id}`],
|
|
186
|
+
* // Was: `P.conditional.defaultCase(),`, Now:
|
|
187
|
+
* constant(undefined),
|
|
188
|
+
* ); //=> 'Hello ID: 3'
|
|
189
|
+
* @deprecated `conditional` now accepts a default, catch-all, callback
|
|
190
|
+
* directly and no longer needs this utility wrapper. Use `constant(undefined)`
|
|
191
|
+
* as your last case instead (see example).
|
|
192
|
+
*/
|
|
193
|
+
declare function defaultCase(): Case<unknown, undefined>;
|
|
104
194
|
/**
|
|
105
|
-
|
|
106
|
-
* prevent an exception from being thrown when none of the previous cases
|
|
107
|
-
* match.
|
|
108
|
-
* If this is not the last case it will short-circuit anything after it.
|
|
195
|
+
*! **DEPRECATED**: `conditional` now accepts a default, catch-all, callback directly and no longer needs this utility wrapper. Simply put your `then` callback as the last case (see example).
|
|
109
196
|
*
|
|
110
197
|
* @param then - You only need to provide the transformer, the predicate is
|
|
111
198
|
* implicit. @default () => undefined, which is how Lodash and Ramda handle
|
|
@@ -116,12 +203,15 @@ declare function conditional<T, Fn0 extends (x: T) => boolean, Fn1 extends (x: T
|
|
|
116
203
|
* nameOrId,
|
|
117
204
|
* [P.isString, (name) => `Hello ${name}`],
|
|
118
205
|
* [P.isNumber, (id) => `Hello ID: ${id}`],
|
|
119
|
-
* P.conditional.defaultCase(
|
|
120
|
-
*
|
|
121
|
-
* )
|
|
206
|
+
* // Was: `P.conditional.defaultCase(
|
|
207
|
+
* // (something) => `Hello something (${JSON.stringify(something)})`,
|
|
208
|
+
* //),`, Now:
|
|
209
|
+
* (something) => `Hello something (${JSON.stringify(something)})`
|
|
122
210
|
* ); //=> 'Hello ID: 3'
|
|
211
|
+
* @deprecated `conditional` now accepts a default, catch-all, callback
|
|
212
|
+
* directly and no longer needs this utility wrapper. Simply put your `then`
|
|
213
|
+
* callback as the last case.
|
|
123
214
|
*/
|
|
124
|
-
declare function defaultCase(): Case<unknown, undefined>;
|
|
125
215
|
declare function defaultCase<In, Then extends (param: In) => unknown>(then: Then): Case<In, ReturnType<Then>>;
|
|
126
216
|
|
|
127
217
|
export { conditionalPlus as conditional };
|
package/dist/conditional.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"./chunk-
|
|
1
|
+
import{a}from"./chunk-4Y6KJJOW.js";import"./chunk-EK7ODJWE.js";export{a as conditional};
|
package/dist/constant.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkWLNQOMKLcjs = require('./chunk-WLNQOMKL.cjs');exports.constant = _chunkWLNQOMKLcjs.a;
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkWLNQOMKLcjs = require('./chunk-WLNQOMKL.cjs');require('./chunk-MBGSSEZN.cjs');exports.constant = _chunkWLNQOMKLcjs.a;
|
package/dist/constant.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"./chunk-T5XG33UI.js";export{a as constant};
|
|
1
|
+
import{a}from"./chunk-T5XG33UI.js";import"./chunk-EK7ODJWE.js";export{a as constant};
|
package/dist/count-by.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunk22AQJBPWcjs = require('./chunk-22AQJBPW.cjs');require('./chunk-XR72I63W.cjs');require('./chunk-GZJMERDJ.cjs');require('./chunk-MBGSSEZN.cjs');exports.countBy = _chunk22AQJBPWcjs.a;
|
package/dist/count-by.d.cts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import './if-
|
|
1
|
+
import { B as BoundedPartial } from './bounded-partial-BqwRN49U.cjs';
|
|
2
|
+
import './if-D4QIikQ1.cjs';
|
|
3
3
|
import 'type-fest';
|
|
4
|
+
import './is-bounded-record-C9WAwfA8.cjs';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Categorize and count elements in an array using a defined callback function.
|
|
@@ -19,7 +20,7 @@ import 'type-fest';
|
|
|
19
20
|
* @dataFirst
|
|
20
21
|
* @category Array
|
|
21
22
|
*/
|
|
22
|
-
declare function countBy<T, K extends PropertyKey>(data: ReadonlyArray<T>, categorizationFn: (value: T, index: number, data: ReadonlyArray<T>) => K | undefined):
|
|
23
|
+
declare function countBy<T, K extends PropertyKey>(data: ReadonlyArray<T>, categorizationFn: (value: T, index: number, data: ReadonlyArray<T>) => K | undefined): BoundedPartial<Record<K, number>>;
|
|
23
24
|
/**
|
|
24
25
|
* Categorize and count elements in an array using a defined callback function.
|
|
25
26
|
* The callback function is applied to each element in the array to determine
|
|
@@ -36,6 +37,6 @@ declare function countBy<T, K extends PropertyKey>(data: ReadonlyArray<T>, categ
|
|
|
36
37
|
* @dataLast
|
|
37
38
|
* @category Array
|
|
38
39
|
*/
|
|
39
|
-
declare function countBy<T, K extends PropertyKey>(categorizationFn: (value: T, index: number, data: ReadonlyArray<T>) => K | undefined): (data: ReadonlyArray<T>) =>
|
|
40
|
+
declare function countBy<T, K extends PropertyKey>(categorizationFn: (value: T, index: number, data: ReadonlyArray<T>) => K | undefined): (data: ReadonlyArray<T>) => BoundedPartial<Record<K, number>>;
|
|
40
41
|
|
|
41
42
|
export { countBy };
|
package/dist/count-by.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import './if-
|
|
1
|
+
import { B as BoundedPartial } from './bounded-partial-BzynYDVs.js';
|
|
2
|
+
import './if-D4QIikQ1.js';
|
|
3
3
|
import 'type-fest';
|
|
4
|
+
import './is-bounded-record-C9WAwfA8.js';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Categorize and count elements in an array using a defined callback function.
|
|
@@ -19,7 +20,7 @@ import 'type-fest';
|
|
|
19
20
|
* @dataFirst
|
|
20
21
|
* @category Array
|
|
21
22
|
*/
|
|
22
|
-
declare function countBy<T, K extends PropertyKey>(data: ReadonlyArray<T>, categorizationFn: (value: T, index: number, data: ReadonlyArray<T>) => K | undefined):
|
|
23
|
+
declare function countBy<T, K extends PropertyKey>(data: ReadonlyArray<T>, categorizationFn: (value: T, index: number, data: ReadonlyArray<T>) => K | undefined): BoundedPartial<Record<K, number>>;
|
|
23
24
|
/**
|
|
24
25
|
* Categorize and count elements in an array using a defined callback function.
|
|
25
26
|
* The callback function is applied to each element in the array to determine
|
|
@@ -36,6 +37,6 @@ declare function countBy<T, K extends PropertyKey>(data: ReadonlyArray<T>, categ
|
|
|
36
37
|
* @dataLast
|
|
37
38
|
* @category Array
|
|
38
39
|
*/
|
|
39
|
-
declare function countBy<T, K extends PropertyKey>(categorizationFn: (value: T, index: number, data: ReadonlyArray<T>) => K | undefined): (data: ReadonlyArray<T>) =>
|
|
40
|
+
declare function countBy<T, K extends PropertyKey>(categorizationFn: (value: T, index: number, data: ReadonlyArray<T>) => K | undefined): (data: ReadonlyArray<T>) => BoundedPartial<Record<K, number>>;
|
|
40
41
|
|
|
41
42
|
export { countBy };
|
package/dist/count-by.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"./chunk-
|
|
1
|
+
import{a}from"./chunk-CTGIT5TY.js";import"./chunk-J6WPJH72.js";import"./chunk-KGPDVVVV.js";import"./chunk-EK7ODJWE.js";export{a as countBy};
|