type-plus 7.3.1 → 7.5.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/README.md +146 -183
- package/cjs/any/any_type.d.ts +8 -8
- package/cjs/any/any_type.d.ts.map +1 -1
- package/cjs/array/array.at.d.ts +3 -1
- package/cjs/array/array.at.d.ts.map +1 -1
- package/cjs/array/array.entries.d.ts +4 -3
- package/cjs/array/array.entries.d.ts.map +1 -1
- package/cjs/array/array.find_last.d.ts +3 -1
- package/cjs/array/array.find_last.d.ts.map +1 -1
- package/cjs/array/array.some.d.ts +1 -1
- package/cjs/array/array.some.d.ts.map +1 -1
- package/cjs/array/array_plus.common_prop_keys.d.ts +27 -0
- package/cjs/array/array_plus.common_prop_keys.d.ts.map +1 -0
- package/cjs/array/array_plus.common_prop_keys.js +3 -0
- package/cjs/array/array_plus.common_prop_keys.js.map +1 -0
- package/cjs/array/{array.concat.d.ts → array_plus.concat.d.ts} +4 -1
- package/cjs/array/array_plus.concat.d.ts.map +1 -0
- package/cjs/array/array_plus.concat.js +3 -0
- package/cjs/array/array_plus.concat.js.map +1 -0
- package/cjs/array/array_plus.d.ts +7 -3
- package/cjs/array/array_plus.d.ts.map +1 -1
- package/cjs/array/array_plus.drop_match.d.ts +4 -0
- package/cjs/array/array_plus.drop_match.d.ts.map +1 -0
- package/cjs/array/array_plus.drop_match.js +3 -0
- package/cjs/array/array_plus.drop_match.js.map +1 -0
- package/cjs/array/array_plus.element_match.d.ts +44 -0
- package/cjs/array/array_plus.element_match.d.ts.map +1 -0
- package/cjs/array/array_plus.element_match.js +3 -0
- package/cjs/array/array_plus.element_match.js.map +1 -0
- package/cjs/array/array_plus.filter.d.ts +2 -0
- package/cjs/array/array_plus.filter.d.ts.map +1 -0
- package/cjs/array/array_plus.filter.js +3 -0
- package/cjs/array/array_plus.filter.js.map +1 -0
- package/cjs/array/array_plus.find.d.ts +57 -0
- package/cjs/array/array_plus.find.d.ts.map +1 -0
- package/cjs/array/array_plus.find.js +3 -0
- package/cjs/array/array_plus.find.js.map +1 -0
- package/cjs/array/array_plus.pad_start.d.ts +5 -0
- package/cjs/array/array_plus.pad_start.d.ts.map +1 -0
- package/cjs/array/array_plus.pad_start.js +3 -0
- package/cjs/array/array_plus.pad_start.js.map +1 -0
- package/cjs/array/array_type.d.ts +30 -12
- package/cjs/array/array_type.d.ts.map +1 -1
- package/cjs/array/filter.d.ts +24 -4
- package/cjs/array/filter.d.ts.map +1 -1
- package/cjs/array/find_first.d.ts +62 -0
- package/cjs/array/find_first.d.ts.map +1 -0
- package/cjs/array/{array.find.js → find_first.js} +1 -1
- package/cjs/array/find_first.js.map +1 -0
- package/cjs/array/head.d.ts +30 -1
- package/cjs/array/head.d.ts.map +1 -1
- package/cjs/array/intersect_of_props.d.ts +5 -3
- package/cjs/array/intersect_of_props.d.ts.map +1 -1
- package/cjs/array/last.d.ts +27 -2
- package/cjs/array/last.d.ts.map +1 -1
- package/cjs/array/literal_array.d.ts +5 -0
- package/cjs/array/literal_array.d.ts.map +1 -1
- package/cjs/array/literal_array.js +5 -0
- package/cjs/array/literal_array.js.map +1 -1
- package/cjs/array/pad_start.d.ts +5 -5
- package/cjs/array/pad_start.d.ts.map +1 -1
- package/cjs/array/reduce_while.d.ts +6 -0
- package/cjs/array/reduce_while.d.ts.map +1 -1
- package/cjs/array/reduce_while.js +6 -0
- package/cjs/array/reduce_while.js.map +1 -1
- package/cjs/array/reverse.d.ts +5 -0
- package/cjs/array/reverse.d.ts.map +1 -1
- package/cjs/array/union_of_props.d.ts +1 -1
- package/cjs/array/union_of_props.d.ts.map +1 -1
- package/cjs/assertion/assert_type.d.ts +4 -1
- package/cjs/assertion/assert_type.d.ts.map +1 -1
- package/cjs/assertion/assert_type.js.map +1 -1
- package/cjs/functional/compose.d.ts +2 -1
- package/cjs/functional/compose.d.ts.map +1 -1
- package/cjs/functional/compose.js.map +1 -1
- package/cjs/functional/context.d.ts.map +1 -1
- package/cjs/index.d.ts +22 -3
- package/cjs/index.d.ts.map +1 -1
- package/cjs/index.js +9 -3
- package/cjs/index.js.map +1 -1
- package/cjs/math/numeric_struct.d.ts +1 -1
- package/cjs/math/numeric_struct.d.ts.map +1 -1
- package/cjs/mix_types/any_or_never_type.d.ts +1 -1
- package/cjs/never/never_type.d.ts +11 -0
- package/cjs/never/never_type.d.ts.map +1 -1
- package/cjs/nodejs/isNodeError.d.ts.map +1 -1
- package/cjs/nominal/brand.d.ts.map +1 -1
- package/cjs/nominal/flavor.d.ts.map +1 -1
- package/cjs/object/index.d.ts +0 -1
- package/cjs/object/index.d.ts.map +1 -1
- package/cjs/object/index.js.map +1 -1
- package/cjs/testing/test_type.d.ts +277 -233
- package/cjs/testing/test_type.d.ts.map +1 -1
- package/cjs/testing/test_type.js.map +1 -1
- package/cjs/tuple/common_prop_keys.d.ts +34 -0
- package/cjs/tuple/common_prop_keys.d.ts.map +1 -0
- package/cjs/tuple/common_prop_keys.js.map +1 -0
- package/cjs/tuple/create_tuple.d.ts.map +1 -1
- package/cjs/tuple/drop.d.ts +91 -0
- package/cjs/tuple/drop.d.ts.map +1 -0
- package/cjs/{array → tuple}/drop.js +3 -1
- package/cjs/tuple/drop.js.map +1 -0
- package/{esm/array → cjs/tuple}/tail.d.ts +1 -1
- package/cjs/{array → tuple}/tail.d.ts.map +1 -1
- package/cjs/{array → tuple}/tail.js.map +1 -1
- package/cjs/tuple/tuple_plus.common_prop_keys.d.ts +28 -0
- package/cjs/tuple/tuple_plus.common_prop_keys.d.ts.map +1 -0
- package/cjs/tuple/tuple_plus.common_prop_keys.js +3 -0
- package/cjs/tuple/tuple_plus.common_prop_keys.js.map +1 -0
- package/cjs/tuple/tuple_plus.d.ts +5 -1
- package/cjs/tuple/tuple_plus.d.ts.map +1 -1
- package/cjs/tuple/tuple_plus.drop_match.d.ts +6 -0
- package/cjs/tuple/tuple_plus.drop_match.d.ts.map +1 -0
- package/cjs/tuple/tuple_plus.drop_match.js +3 -0
- package/cjs/tuple/tuple_plus.drop_match.js.map +1 -0
- package/cjs/tuple/tuple_plus.filter.d.ts +13 -0
- package/cjs/tuple/tuple_plus.filter.d.ts.map +1 -0
- package/cjs/tuple/tuple_plus.filter.js +3 -0
- package/cjs/tuple/tuple_plus.filter.js.map +1 -0
- package/cjs/tuple/tuple_plus.find.d.ts +64 -0
- package/cjs/tuple/tuple_plus.find.d.ts.map +1 -0
- package/cjs/tuple/tuple_plus.find.js +3 -0
- package/cjs/tuple/tuple_plus.find.js.map +1 -0
- package/cjs/tuple/tuple_plus.js +0 -15
- package/cjs/tuple/tuple_plus.js.map +1 -1
- package/cjs/tuple/tuple_plus.pad_start.d.ts +11 -5
- package/cjs/tuple/tuple_plus.pad_start.d.ts.map +1 -1
- package/cjs/tuple/tuple_type.d.ts +41 -23
- package/cjs/tuple/tuple_type.d.ts.map +1 -1
- package/cjs/union/union.d.ts +33 -0
- package/cjs/union/union.d.ts.map +1 -0
- package/cjs/{array/array.concat.js → union/union.js} +1 -1
- package/cjs/union/union.js.map +1 -0
- package/cjs/unknown/unknown_type.d.ts +12 -0
- package/cjs/unknown/unknown_type.d.ts.map +1 -1
- package/cjs/utils/options.d.ts +10 -0
- package/cjs/utils/options.d.ts.map +1 -0
- package/cjs/utils/options.js +3 -0
- package/cjs/utils/options.js.map +1 -0
- package/esm/any/any_type.d.ts +8 -8
- package/esm/any/any_type.d.ts.map +1 -1
- package/esm/array/array.at.d.ts +3 -1
- package/esm/array/array.at.d.ts.map +1 -1
- package/esm/array/array.entries.d.ts +4 -3
- package/esm/array/array.entries.d.ts.map +1 -1
- package/esm/array/array.find_last.d.ts +3 -1
- package/esm/array/array.find_last.d.ts.map +1 -1
- package/esm/array/array.some.d.ts +1 -1
- package/esm/array/array.some.d.ts.map +1 -1
- package/esm/array/array_plus.common_prop_keys.d.ts +27 -0
- package/esm/array/array_plus.common_prop_keys.d.ts.map +1 -0
- package/esm/array/array_plus.common_prop_keys.js +2 -0
- package/esm/array/array_plus.common_prop_keys.js.map +1 -0
- package/esm/array/{array.concat.d.ts → array_plus.concat.d.ts} +4 -1
- package/esm/array/array_plus.concat.d.ts.map +1 -0
- package/esm/array/array_plus.concat.js +2 -0
- package/esm/array/array_plus.concat.js.map +1 -0
- package/esm/array/array_plus.d.ts +7 -3
- package/esm/array/array_plus.d.ts.map +1 -1
- package/esm/array/array_plus.drop_match.d.ts +4 -0
- package/esm/array/array_plus.drop_match.d.ts.map +1 -0
- package/esm/array/array_plus.drop_match.js +2 -0
- package/esm/array/array_plus.drop_match.js.map +1 -0
- package/esm/array/array_plus.element_match.d.ts +44 -0
- package/esm/array/array_plus.element_match.d.ts.map +1 -0
- package/esm/array/array_plus.element_match.js +2 -0
- package/esm/array/array_plus.element_match.js.map +1 -0
- package/esm/array/array_plus.filter.d.ts +2 -0
- package/esm/array/array_plus.filter.d.ts.map +1 -0
- package/esm/array/array_plus.filter.js +2 -0
- package/esm/array/array_plus.filter.js.map +1 -0
- package/esm/array/array_plus.find.d.ts +57 -0
- package/esm/array/array_plus.find.d.ts.map +1 -0
- package/esm/array/array_plus.find.js +2 -0
- package/esm/array/array_plus.find.js.map +1 -0
- package/esm/array/array_plus.pad_start.d.ts +5 -0
- package/esm/array/array_plus.pad_start.d.ts.map +1 -0
- package/esm/array/array_plus.pad_start.js +2 -0
- package/esm/array/array_plus.pad_start.js.map +1 -0
- package/esm/array/array_type.d.ts +30 -12
- package/esm/array/array_type.d.ts.map +1 -1
- package/esm/array/filter.d.ts +24 -4
- package/esm/array/filter.d.ts.map +1 -1
- package/esm/array/find_first.d.ts +62 -0
- package/esm/array/find_first.d.ts.map +1 -0
- package/esm/array/find_first.js +2 -0
- package/esm/array/find_first.js.map +1 -0
- package/esm/array/head.d.ts +30 -1
- package/esm/array/head.d.ts.map +1 -1
- package/esm/array/intersect_of_props.d.ts +5 -3
- package/esm/array/intersect_of_props.d.ts.map +1 -1
- package/esm/array/last.d.ts +27 -2
- package/esm/array/last.d.ts.map +1 -1
- package/esm/array/literal_array.d.ts +5 -0
- package/esm/array/literal_array.d.ts.map +1 -1
- package/esm/array/literal_array.js +5 -0
- package/esm/array/literal_array.js.map +1 -1
- package/esm/array/pad_start.d.ts +5 -5
- package/esm/array/pad_start.d.ts.map +1 -1
- package/esm/array/reduce_while.d.ts +6 -0
- package/esm/array/reduce_while.d.ts.map +1 -1
- package/esm/array/reduce_while.js +6 -0
- package/esm/array/reduce_while.js.map +1 -1
- package/esm/array/reverse.d.ts +5 -0
- package/esm/array/reverse.d.ts.map +1 -1
- package/esm/array/union_of_props.d.ts +1 -1
- package/esm/array/union_of_props.d.ts.map +1 -1
- package/esm/assertion/assert_type.d.ts +4 -1
- package/esm/assertion/assert_type.d.ts.map +1 -1
- package/esm/assertion/assert_type.js.map +1 -1
- package/esm/functional/compose.d.ts +2 -1
- package/esm/functional/compose.d.ts.map +1 -1
- package/esm/functional/compose.js.map +1 -1
- package/esm/functional/context.d.ts.map +1 -1
- package/esm/index.d.ts +22 -3
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +4 -2
- package/esm/index.js.map +1 -1
- package/esm/math/numeric_struct.d.ts +1 -1
- package/esm/math/numeric_struct.d.ts.map +1 -1
- package/esm/mix_types/any_or_never_type.d.ts +1 -1
- package/esm/never/never_type.d.ts +11 -0
- package/esm/never/never_type.d.ts.map +1 -1
- package/esm/nodejs/isNodeError.d.ts.map +1 -1
- package/esm/nominal/brand.d.ts.map +1 -1
- package/esm/nominal/flavor.d.ts.map +1 -1
- package/esm/object/index.d.ts +0 -1
- package/esm/object/index.d.ts.map +1 -1
- package/esm/object/index.js.map +1 -1
- package/esm/testing/test_type.d.ts +277 -233
- package/esm/testing/test_type.d.ts.map +1 -1
- package/esm/testing/test_type.js.map +1 -1
- package/esm/tuple/common_prop_keys.d.ts +34 -0
- package/esm/tuple/common_prop_keys.d.ts.map +1 -0
- package/esm/tuple/common_prop_keys.js.map +1 -0
- package/esm/tuple/create_tuple.d.ts.map +1 -1
- package/esm/tuple/drop.d.ts +91 -0
- package/esm/tuple/drop.d.ts.map +1 -0
- package/esm/tuple/drop.js +9 -0
- package/esm/tuple/drop.js.map +1 -0
- package/{cjs/array → esm/tuple}/tail.d.ts +1 -1
- package/esm/{array → tuple}/tail.d.ts.map +1 -1
- package/esm/{array → tuple}/tail.js.map +1 -1
- package/esm/tuple/tuple_plus.common_prop_keys.d.ts +28 -0
- package/esm/tuple/tuple_plus.common_prop_keys.d.ts.map +1 -0
- package/esm/tuple/tuple_plus.common_prop_keys.js +2 -0
- package/esm/tuple/tuple_plus.common_prop_keys.js.map +1 -0
- package/esm/tuple/tuple_plus.d.ts +5 -1
- package/esm/tuple/tuple_plus.d.ts.map +1 -1
- package/esm/tuple/tuple_plus.drop_match.d.ts +6 -0
- package/esm/tuple/tuple_plus.drop_match.d.ts.map +1 -0
- package/esm/tuple/tuple_plus.drop_match.js +2 -0
- package/esm/tuple/tuple_plus.drop_match.js.map +1 -0
- package/esm/tuple/tuple_plus.filter.d.ts +13 -0
- package/esm/tuple/tuple_plus.filter.d.ts.map +1 -0
- package/esm/tuple/tuple_plus.filter.js +2 -0
- package/esm/tuple/tuple_plus.filter.js.map +1 -0
- package/esm/tuple/tuple_plus.find.d.ts +64 -0
- package/esm/tuple/tuple_plus.find.d.ts.map +1 -0
- package/esm/tuple/tuple_plus.find.js +2 -0
- package/esm/tuple/tuple_plus.find.js.map +1 -0
- package/esm/tuple/tuple_plus.js +1 -1
- package/esm/tuple/tuple_plus.js.map +1 -1
- package/esm/tuple/tuple_plus.pad_start.d.ts +11 -5
- package/esm/tuple/tuple_plus.pad_start.d.ts.map +1 -1
- package/esm/tuple/tuple_type.d.ts +41 -23
- package/esm/tuple/tuple_type.d.ts.map +1 -1
- package/esm/union/union.d.ts +33 -0
- package/esm/union/union.d.ts.map +1 -0
- package/esm/union/union.js +2 -0
- package/esm/union/union.js.map +1 -0
- package/esm/unknown/unknown_type.d.ts +12 -0
- package/esm/unknown/unknown_type.d.ts.map +1 -1
- package/esm/utils/options.d.ts +10 -0
- package/esm/utils/options.d.ts.map +1 -0
- package/esm/utils/options.js +2 -0
- package/esm/utils/options.js.map +1 -0
- package/package.json +12 -9
- package/ts/any/any_type.ts +8 -9
- package/ts/any/readme.md +71 -4
- package/ts/array/array.at.ts +3 -1
- package/ts/array/array.entries.ts +4 -2
- package/ts/array/array.find_last.ts +3 -1
- package/ts/array/array.some.ts +1 -1
- package/ts/array/array_plus.common_prop_keys.ts +35 -0
- package/ts/array/{array.concat.ts → array_plus.concat.ts} +3 -0
- package/ts/array/array_plus.drop_match.ts +16 -0
- package/ts/array/array_plus.element_match.ts +61 -0
- package/ts/array/array_plus.filter.ts +5 -0
- package/ts/array/array_plus.find.ts +71 -0
- package/ts/array/array_plus.pad_start.ts +13 -0
- package/ts/array/array_plus.ts +7 -3
- package/ts/array/array_type.ts +30 -12
- package/ts/array/filter.ts +27 -22
- package/ts/array/find_first.ts +71 -0
- package/ts/array/head.ts +40 -1
- package/ts/array/intersect_of_props.ts +7 -3
- package/ts/array/last.ts +36 -2
- package/ts/array/literal_array.ts +5 -0
- package/ts/array/pad_start.ts +6 -10
- package/ts/array/readme.md +297 -32
- package/ts/array/reduce_while.ts +6 -0
- package/ts/array/reverse.ts +5 -0
- package/ts/array/union_of_props.ts +1 -1
- package/ts/assertion/assert_type.ts +4 -1
- package/ts/assertion/readme.md +4 -3
- package/ts/functional/compose.ts +2 -1
- package/ts/functional/context.ts +1 -1
- package/ts/index.ts +22 -3
- package/ts/math/numeric_struct.ts +9 -9
- package/ts/mix_types/any_or_never_type.ts +1 -1
- package/ts/mix_types/readme.md +7 -1
- package/ts/never/never_type.ts +13 -0
- package/ts/nodejs/isNodeError.ts +13 -13
- package/ts/nominal/brand.ts +1 -1
- package/ts/nominal/flavor.ts +1 -1
- package/ts/object/index.ts +0 -1
- package/ts/testing/readme.md +30 -0
- package/ts/testing/test_type.ts +279 -234
- package/ts/tuple/common_prop_keys.ts +41 -0
- package/ts/tuple/create_tuple.ts +9 -9
- package/ts/tuple/drop.ts +125 -0
- package/ts/tuple/readme.md +263 -9
- package/ts/{array → tuple}/tail.ts +1 -1
- package/ts/tuple/tuple_plus.common_prop_keys.ts +47 -0
- package/ts/tuple/tuple_plus.drop_match.ts +20 -0
- package/ts/tuple/tuple_plus.filter.ts +29 -0
- package/ts/tuple/tuple_plus.find.ts +88 -0
- package/ts/tuple/tuple_plus.pad_start.ts +37 -21
- package/ts/tuple/tuple_plus.ts +5 -1
- package/ts/tuple/tuple_type.ts +67 -25
- package/ts/union/readme.md +81 -0
- package/ts/union/union.ts +37 -0
- package/ts/unknown/unknown_type.ts +13 -0
- package/ts/utils/options.ts +10 -0
- package/cjs/array/array.concat.d.ts.map +0 -1
- package/cjs/array/array.concat.js.map +0 -1
- package/cjs/array/array.find.d.ts +0 -21
- package/cjs/array/array.find.d.ts.map +0 -1
- package/cjs/array/array.find.js.map +0 -1
- package/cjs/array/common_prop_keys.d.ts +0 -11
- package/cjs/array/common_prop_keys.d.ts.map +0 -1
- package/cjs/array/common_prop_keys.js.map +0 -1
- package/cjs/array/drop.d.ts +0 -19
- package/cjs/array/drop.d.ts.map +0 -1
- package/cjs/array/drop.js.map +0 -1
- package/cjs/array/index.d.ts +0 -17
- package/cjs/array/index.d.ts.map +0 -1
- package/cjs/array/index.js +0 -33
- package/cjs/array/index.js.map +0 -1
- package/esm/array/array.concat.d.ts.map +0 -1
- package/esm/array/array.concat.js +0 -2
- package/esm/array/array.concat.js.map +0 -1
- package/esm/array/array.find.d.ts +0 -21
- package/esm/array/array.find.d.ts.map +0 -1
- package/esm/array/array.find.js +0 -2
- package/esm/array/array.find.js.map +0 -1
- package/esm/array/common_prop_keys.d.ts +0 -11
- package/esm/array/common_prop_keys.d.ts.map +0 -1
- package/esm/array/common_prop_keys.js.map +0 -1
- package/esm/array/drop.d.ts +0 -19
- package/esm/array/drop.d.ts.map +0 -1
- package/esm/array/drop.js +0 -7
- package/esm/array/drop.js.map +0 -1
- package/esm/array/index.d.ts +0 -17
- package/esm/array/index.d.ts.map +0 -1
- package/esm/array/index.js +0 -17
- package/esm/array/index.js.map +0 -1
- package/ts/array/array.find.ts +0 -32
- package/ts/array/common_prop_keys.ts +0 -18
- package/ts/array/drop.ts +0 -71
- package/ts/array/index.ts +0 -16
- /package/cjs/{array → tuple}/common_prop_keys.js +0 -0
- /package/cjs/{array → tuple}/tail.js +0 -0
- /package/esm/{array → tuple}/common_prop_keys.js +0 -0
- /package/esm/{array → tuple}/tail.js +0 -0
package/ts/array/head.ts
CHANGED
|
@@ -1 +1,40 @@
|
|
|
1
|
-
|
|
1
|
+
import type { NeverType } from '../never/never_type.js'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 🦴 *utilities*
|
|
5
|
+
* 🔢 *customizable*
|
|
6
|
+
*
|
|
7
|
+
* Gets the first entry in the tuple or the type of array `T`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* type R = Head<[1, 2, 3]> // 1
|
|
12
|
+
* type R = Head<string[]> // string
|
|
13
|
+
*
|
|
14
|
+
* type R = Head<[]> // never
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @typeParam Options['caseNever'] Return type when `T` is `never`.
|
|
18
|
+
* Default to `never`.
|
|
19
|
+
*
|
|
20
|
+
* @typeParam Options['caseEmptyTuple'] Return type when `T` is `[]`.
|
|
21
|
+
* Default to `never`.
|
|
22
|
+
*/
|
|
23
|
+
export type Head<
|
|
24
|
+
T extends unknown[],
|
|
25
|
+
Options extends Head.Options = Head.DefaultOptions
|
|
26
|
+
> = NeverType<
|
|
27
|
+
T,
|
|
28
|
+
Options['caseNever'],
|
|
29
|
+
T['length'] extends 0 ? Options['caseEmptyTuple'] : T[0]
|
|
30
|
+
>
|
|
31
|
+
|
|
32
|
+
export namespace Head {
|
|
33
|
+
export interface Options extends NeverType.Options {
|
|
34
|
+
caseEmptyTuple?: unknown
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface DefaultOptions extends NeverType.DefaultOptions {
|
|
38
|
+
caseEmptyTuple: never
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import type { KeyTypes } from '../object/index.js'
|
|
2
|
-
import type { Tail } from '
|
|
2
|
+
import type { Tail } from '../tuple/tail.js'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* 🦴 *utilities*
|
|
6
|
+
*
|
|
7
|
+
* Gets the intersect of properties of the elements in `A`.
|
|
6
8
|
*/
|
|
7
|
-
export type IntersectOfProps<A extends Record<any, unknown>[], P extends KeyTypes> = A['length']
|
|
9
|
+
export type IntersectOfProps<A extends Record<any, unknown>[], P extends KeyTypes> = number extends A['length']
|
|
10
|
+
? A[0][P]
|
|
11
|
+
: A['length'] extends 0
|
|
8
12
|
? never
|
|
9
13
|
: A['length'] extends 1
|
|
10
14
|
? A[0][P]
|
package/ts/array/last.ts
CHANGED
|
@@ -1,4 +1,38 @@
|
|
|
1
|
+
import type { NeverType } from '../never/never_type.js'
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
|
-
*
|
|
4
|
+
* 🦴 *utilities*
|
|
5
|
+
*
|
|
6
|
+
* Gets the last entry in the tuple or the type of array `T`.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* type R = Last<[1, 2, 3]> // 3
|
|
11
|
+
* type R = Last<string[]> // string
|
|
12
|
+
*
|
|
13
|
+
* type R = Last<[]> // never
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @typeParam Options['caseNever'] Return type when `T` is `never`.
|
|
17
|
+
* Default to `never`.
|
|
18
|
+
*
|
|
19
|
+
* @typeParam Options['caseEmptyTuple'] Return type when `T` is `[]`.
|
|
20
|
+
* Default to `never`.
|
|
3
21
|
*/
|
|
4
|
-
export type Last<
|
|
22
|
+
export type Last<
|
|
23
|
+
T extends unknown[],
|
|
24
|
+
Options extends Last.Options = Last.DefaultOptions
|
|
25
|
+
> = NeverType<T,
|
|
26
|
+
Options['caseNever'],
|
|
27
|
+
T['length'] extends 0 ? Options['caseEmptyTuple'] : T extends [...unknown[], infer R] ? R : T[0]
|
|
28
|
+
>
|
|
29
|
+
|
|
30
|
+
export namespace Last {
|
|
31
|
+
export interface Options extends NeverType.Options {
|
|
32
|
+
caseEmptyTuple?: unknown
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface DefaultOptions extends NeverType.DefaultOptions {
|
|
36
|
+
caseEmptyTuple: never
|
|
37
|
+
}
|
|
38
|
+
}
|
package/ts/array/pad_start.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type { PadStart as TuplePadStart } from '../tuple/tuple_plus.pad_start.js'
|
|
4
|
-
import type { UnionOfValues } from './union_of_values.js'
|
|
1
|
+
import type { PadStart as PadStartTuple } from '../tuple/tuple_plus.pad_start.js'
|
|
2
|
+
import type { PadStart as PadStartArray } from './array_plus.pad_start.js'
|
|
5
3
|
|
|
6
4
|
/**
|
|
7
5
|
* Pads the start of an array or tuple with `PadWith`.
|
|
8
6
|
*
|
|
7
|
+
* ⚗️ *transform*
|
|
8
|
+
*
|
|
9
9
|
* @example
|
|
10
10
|
* ```ts
|
|
11
11
|
* // Padding array
|
|
@@ -30,12 +30,8 @@ export type PadStart<
|
|
|
30
30
|
MaxLength extends number,
|
|
31
31
|
PadWith = unknown
|
|
32
32
|
> = number extends A['length']
|
|
33
|
-
? MaxLength
|
|
34
|
-
|
|
35
|
-
: CanAssign<PadWith, UnionOfValues<A>> extends true
|
|
36
|
-
? A
|
|
37
|
-
: PadStart<[...CreateTuple<MaxLength, PadWith>, ...A], MaxLength, PadWith>
|
|
38
|
-
: TuplePadStart<A, MaxLength, PadWith>
|
|
33
|
+
? PadStartArray<A, MaxLength, PadWith>
|
|
34
|
+
: PadStartTuple<A, MaxLength, PadWith>
|
|
39
35
|
|
|
40
36
|
/**
|
|
41
37
|
* @deprecated use PadStart instead
|
package/ts/array/readme.md
CHANGED
|
@@ -1,13 +1,26 @@
|
|
|
1
1
|
# Array
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
In TypeScript, the type of an JavaScript array can be an [array](#array) or a [tuple](../tuple/readme.md).
|
|
4
|
+
|
|
5
|
+
`Array<T>` or `T[]` is a type that represents an array of `T`
|
|
6
|
+
|
|
7
|
+
There is no length limitation to an `Array`,
|
|
8
|
+
and each element has the same type `T`.
|
|
4
9
|
|
|
5
10
|
## Type Checking
|
|
6
11
|
|
|
7
12
|
The `ArrayType<T>` and friends are used to check if a type is exactly `Array<T>` or not.
|
|
8
13
|
|
|
9
14
|
They are strict type checks, meaning they match only the type `Array<T>`,
|
|
10
|
-
and not [tuple], union, or intersection types.
|
|
15
|
+
and not [tuple], [union], or intersection types.
|
|
16
|
+
|
|
17
|
+
### [ArrayType](./array_type.ts#18)
|
|
18
|
+
|
|
19
|
+
`ArrayType<T, Then = T, Else = never>`
|
|
20
|
+
|
|
21
|
+
🌪️ *filter*
|
|
22
|
+
|
|
23
|
+
Filter `T` to ensure it is an array, excluding tuple.
|
|
11
24
|
|
|
12
25
|
```ts
|
|
13
26
|
import type { ArrayType } from 'type-plus'
|
|
@@ -19,25 +32,64 @@ type R = ArrayType<number[] | 1> // never
|
|
|
19
32
|
type R = ArrayType<number[] & { a: 1 }> // never
|
|
20
33
|
```
|
|
21
34
|
|
|
22
|
-
|
|
23
|
-
- [`IsArray<T, Then = true, Else = false`](array_type.ts#L33): is `T` an array and not a tuple.
|
|
24
|
-
- [`NotArrayType<T, Then = T, Else = never>`](array_type.ts#L47): check if `T` is not an array (can be a tuple).
|
|
25
|
-
- [`IsNotArray<T, Then = true, Else = false>`](array_type.ts#L61): is `T` not an array (can be a tuple).
|
|
35
|
+
### [IsArray](./array_type.ts#37)
|
|
26
36
|
|
|
27
|
-
|
|
37
|
+
`IsArray<T, Then = true, Else = false>`
|
|
28
38
|
|
|
29
|
-
|
|
30
|
-
Whenever possible, these types and type utilities also work with *tuples*,
|
|
31
|
-
as *tuples* is a subset of array.
|
|
39
|
+
🎭 *validate*
|
|
32
40
|
|
|
33
|
-
|
|
34
|
-
please check [`TuplePlus`](../tuple/readme.md#TuplePlus).
|
|
41
|
+
Validate that `T` is an array, excluding tuple.
|
|
35
42
|
|
|
36
|
-
|
|
43
|
+
```ts
|
|
44
|
+
import type { IsArray } from 'type-plus'
|
|
45
|
+
|
|
46
|
+
type R = IsArray<number[]> // true
|
|
47
|
+
|
|
48
|
+
type R = IsArray<number> // false
|
|
49
|
+
type R = IsArray<[1]> // false
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### [NotArrayType](./array_type.ts#54)
|
|
53
|
+
|
|
54
|
+
`NotArrayType<T, Then = T, Else = never>`
|
|
55
|
+
|
|
56
|
+
🌪️ *filter*
|
|
57
|
+
|
|
58
|
+
Filter `T` to ensure it is not an array, excluding tuple.
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
import type { NotArrayType } from 'type-plus'
|
|
62
|
+
|
|
63
|
+
type R = NotArrayType<number[]> // never
|
|
37
64
|
|
|
38
|
-
|
|
65
|
+
type R = NotArrayType<number> // number
|
|
66
|
+
type R = NotArrayType<[1]> // [1]
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### [IsNotArrayType](./array_type.ts#71)
|
|
70
|
+
|
|
71
|
+
`IsNotArrayType<T, Then = true, Else = false>`
|
|
72
|
+
|
|
73
|
+
🎭 *validate*
|
|
39
74
|
|
|
40
|
-
|
|
75
|
+
Validate that `T` is not an array, excluding tuple.
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
import type { IsNotArrayType } from 'type-plus'
|
|
79
|
+
|
|
80
|
+
type R = IsNotArrayType<number[]> // false
|
|
81
|
+
|
|
82
|
+
type R = IsNotArrayType<number> // true
|
|
83
|
+
type R = IsNotArrayType<[1]> // true
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## [At](./array.at.ts#l20)
|
|
87
|
+
|
|
88
|
+
`At<A, N, Fail = never>`
|
|
89
|
+
|
|
90
|
+
🦴 *utilities*
|
|
91
|
+
|
|
92
|
+
Gets the type of the array or tuple at positive or negative index `N`.
|
|
41
93
|
|
|
42
94
|
For array, it will return the union of the type of the array value and `undefined`,
|
|
43
95
|
as there is no way to guarantee the array has value at `N`.
|
|
@@ -45,7 +97,7 @@ as there is no way to guarantee the array has value at `N`.
|
|
|
45
97
|
```ts
|
|
46
98
|
type A = Array<string | number>
|
|
47
99
|
|
|
48
|
-
ArrayPlus.At<A, 0> // string | number | undefined
|
|
100
|
+
type R = ArrayPlus.At<A, 0> // string | number | undefined
|
|
49
101
|
```
|
|
50
102
|
|
|
51
103
|
For tuple, it will return the type of the tuple value at index `N`.
|
|
@@ -53,17 +105,20 @@ For tuple, it will return the type of the tuple value at index `N`.
|
|
|
53
105
|
```ts
|
|
54
106
|
type T = [number, string, 1, 2, 3]
|
|
55
107
|
|
|
56
|
-
ArrayPlus.At<T, 0> // number
|
|
57
|
-
ArrayPlus.At<T, -1> // 3
|
|
108
|
+
type R = ArrayPlus.At<T, 0> // number
|
|
109
|
+
type R = ArrayPlus.At<T, -1> // 3
|
|
58
110
|
```
|
|
59
111
|
|
|
60
112
|
If the `N` is out of bound,
|
|
61
113
|
or `N` is not a valid index,
|
|
62
114
|
`ArrayPlus.At` will return the `Fail` case, which defaults to `never`.
|
|
63
115
|
|
|
64
|
-
|
|
116
|
+
## [`Concat`](./array.concat.ts#L12)
|
|
117
|
+
|
|
118
|
+
`Concat<A, B>`
|
|
65
119
|
|
|
66
|
-
|
|
120
|
+
🦴 *utilities*
|
|
121
|
+
💀 *deprecated* Will be available only as `ArrayPlus.Concat` in the next version
|
|
67
122
|
|
|
68
123
|
Concats two arrays or tuples.
|
|
69
124
|
|
|
@@ -72,6 +127,202 @@ It is added for completeness.
|
|
|
72
127
|
|
|
73
128
|
You are encouraged to use `[...A, ...B]` directly.
|
|
74
129
|
|
|
130
|
+
## [`FindFirst`](./find_first.ts#l52)
|
|
131
|
+
|
|
132
|
+
`FindFirst<A, Criteria, Options = { widen, caseEmptyTuple, caseNever, caseNoMatch, caseWiden, caseUnionMiss }>`
|
|
133
|
+
|
|
134
|
+
🦴 *utilities*
|
|
135
|
+
🔢 *customizable*
|
|
136
|
+
|
|
137
|
+
Find the first type in the array or tuple `A` that matches `Criteria`.
|
|
138
|
+
|
|
139
|
+
```ts
|
|
140
|
+
import type { FindFirst } from 'type-plus'
|
|
141
|
+
|
|
142
|
+
type R = FindFirst<[true, 1, 'x', 3], string> // 'x'
|
|
143
|
+
type R = FindFirst<[true, 1, 'x', 3], number> // 1
|
|
144
|
+
type R = FindFirst<[string, number, 1], 1> // widen: 1 | undefined
|
|
145
|
+
type R = FindFirst<[true, number | string], string> // unionNotMatch: string
|
|
146
|
+
type R = FindFirst<Array<string>, string> // string
|
|
147
|
+
type R = FindFirst<Array<1 | 2 | 'x'>, number> // 1 | 2 | undefined
|
|
148
|
+
type R = FindFirst<Array<string | number>, number | string> // string | number
|
|
149
|
+
type R = FindFirst<Array<number>, 1> // widen: 1 | undefined
|
|
150
|
+
type R = FindFirst<Array<string | number>, number> // unionNotMatch: number
|
|
151
|
+
|
|
152
|
+
type R = FindFirst<[true, 1, 'x'], 2> // never
|
|
153
|
+
type R = FindFirst<string[], number> // never
|
|
154
|
+
|
|
155
|
+
// customization
|
|
156
|
+
type R = FindFirst<[number], 1, { widen: false }> // never
|
|
157
|
+
type R = FindFirst<[number], 1, { caseWiden: never }> // never
|
|
158
|
+
type R = FindFirst<[], 1, { caseEmptyTuple: 2 }> // 2
|
|
159
|
+
type R = FindFirst<never, 1, { caseNever: 2 }> // 2
|
|
160
|
+
type R = FindFirst<[string], number, { caseNotMatch: 2 }> // 2
|
|
161
|
+
type R = FindFirst<[string | number], number, { caseUnionNotMatch: undefined }> // number | undefined
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## [`FindLast`](./array.find_last.ts)
|
|
165
|
+
|
|
166
|
+
## [`Some`](./array.some.ts)
|
|
167
|
+
|
|
168
|
+
## [`Filter`](./filter.ts#l17)
|
|
169
|
+
|
|
170
|
+
`Filter<A, Criteria>`
|
|
171
|
+
|
|
172
|
+
⚗️ *transform*
|
|
173
|
+
|
|
174
|
+
Filter the array or tuple `A`, keeping entries satisfying `Criteria`.
|
|
175
|
+
|
|
176
|
+
```ts
|
|
177
|
+
import type { Filter } from 'type-plus'
|
|
178
|
+
|
|
179
|
+
type R = Filter<[1, 2, '3'], number> // [1, 2]
|
|
180
|
+
type R = Filter<Array<string | undefined>, string> // string[]
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## [`KeepMatch`](./filter.ts)
|
|
184
|
+
|
|
185
|
+
`KeepMatch<A, Criteria>`
|
|
186
|
+
|
|
187
|
+
⚗️ *transform*
|
|
188
|
+
👽 *alias* of [`Filter`](#filter)
|
|
189
|
+
|
|
190
|
+
Keeps entries satisfying `Criteria` in array or tuple `A`.
|
|
191
|
+
|
|
192
|
+
```ts
|
|
193
|
+
import type { KeepMatch } from 'type-plus'
|
|
194
|
+
|
|
195
|
+
type R = KeepMatch<[1, 2, '3'], number> // [1, 2]
|
|
196
|
+
type R = KeepMatch<Array<string | undefined>, string> // string[]
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
## [`Head`](./head.ts#l23)
|
|
200
|
+
|
|
201
|
+
`Head<T, Options = { caseNever, caseEmptyTuple }>`
|
|
202
|
+
|
|
203
|
+
🦴 *utilities*
|
|
204
|
+
🔢 *customizable*
|
|
205
|
+
|
|
206
|
+
Gets the first entry in the tuple or the type of array `T`.
|
|
207
|
+
|
|
208
|
+
```ts
|
|
209
|
+
import type { Head } from 'type-plus'
|
|
210
|
+
|
|
211
|
+
type R = Head<[1, 2, 3]> // 1
|
|
212
|
+
type R = Head<string[]> // string
|
|
213
|
+
type R = Head<never> // caseNever: never
|
|
214
|
+
type R = Head<[]> // caseEmptyTuple: never
|
|
215
|
+
|
|
216
|
+
// customization
|
|
217
|
+
type R = Head<never, { caseNever: 1 }> // 1
|
|
218
|
+
type R = Head<[], { caseEmptyTuple: undefined }> // undefined
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
## [`IntersectOfProps`](./intersect_of_props.ts)
|
|
222
|
+
|
|
223
|
+
## [`MapToProp`](./intersect_of_props.ts)
|
|
224
|
+
|
|
225
|
+
## [`Last`](./last.ts#l23)
|
|
226
|
+
|
|
227
|
+
`Last<T, Options = { caseNever, caseEmptyTuple }>`
|
|
228
|
+
|
|
229
|
+
🦴 *utilities*
|
|
230
|
+
🔢 *customizable*
|
|
231
|
+
|
|
232
|
+
Gets the last entry in the tuple or the type of array `T`.
|
|
233
|
+
|
|
234
|
+
```ts
|
|
235
|
+
import type { Last } from 'type-plus'
|
|
236
|
+
|
|
237
|
+
type R = Last<[1, 2, 3]> // 3
|
|
238
|
+
type R = Last<string[]> // string
|
|
239
|
+
type R = Last<never> // caseNever: never
|
|
240
|
+
type R = Last<[]> // caseEmptyTuple: never
|
|
241
|
+
|
|
242
|
+
// customization
|
|
243
|
+
type R = Last<never, { caseNever: 1 }> // 1
|
|
244
|
+
type R = Last<[], { caseEmptyTuple: undefined }> // undefined
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
## [`literalArray`](./literal_array.ts)
|
|
248
|
+
|
|
249
|
+
## [`PadStart`](./pad_start.ts)
|
|
250
|
+
|
|
251
|
+
## [`reduceWhile`](./reduce_while.ts)
|
|
252
|
+
|
|
253
|
+
## [`Reverse`](./reverse.ts)
|
|
254
|
+
|
|
255
|
+
## [`PropUnion`](./union_of_props.ts)
|
|
256
|
+
|
|
257
|
+
## [`UnionOfProps`](./union_of_props.ts)
|
|
258
|
+
|
|
259
|
+
## [`UnionOfValues`](./union_of_values.ts)
|
|
260
|
+
|
|
261
|
+
## ArrayPlus
|
|
262
|
+
|
|
263
|
+
`ArrayPlus` contains all types and type utilities related to array.
|
|
264
|
+
Whenever possible, these types and type utilities also work with *tuples*,
|
|
265
|
+
as *tuples* is a subset of array.
|
|
266
|
+
|
|
267
|
+
For *tuple* specific types and type utilities,
|
|
268
|
+
please check [`TuplePlus`](../tuple/readme.md#TuplePlus).
|
|
269
|
+
|
|
270
|
+
### [`ArrayPlus.At`](./array.at.ts#L18)
|
|
271
|
+
|
|
272
|
+
`ArrayPlus.At<A, N, Fail = never>`
|
|
273
|
+
|
|
274
|
+
Alias of [At](#at).
|
|
275
|
+
|
|
276
|
+
## [ArrayPlus.CommonPropKeys](./array_plus.common_prop_keys.ts#l21)
|
|
277
|
+
|
|
278
|
+
`ArrayPlus.CommonPropKeys<T extends Record[], Options = { caseNever }>`
|
|
279
|
+
|
|
280
|
+
⚗️ *transform*
|
|
281
|
+
🔢 *customizable*
|
|
282
|
+
|
|
283
|
+
Gets the common property keys of the elements in array `A`.
|
|
284
|
+
|
|
285
|
+
```ts
|
|
286
|
+
import { type ArrayPlus } from 'type-plus'
|
|
287
|
+
|
|
288
|
+
type R = ArrayPlus.CommonPropKeys<Array<{ a: 1 }>> // 'a'
|
|
289
|
+
type R = ArrayPlus.CommonPropKeys<Array<{ a: 1, b: 1 } | { a: 1, c: 1 }>> // 'a'
|
|
290
|
+
|
|
291
|
+
// customization
|
|
292
|
+
type R = ArrayPlus.CommonPropKeys<never, { caseNever: 1 }> // 1
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
### [`ArrayPlus.Concat`](./array.concat.ts#l12)
|
|
296
|
+
|
|
297
|
+
`ArrayPlus.Concat<A, B>`
|
|
298
|
+
|
|
299
|
+
Alias of [Concat](#concat).
|
|
300
|
+
|
|
301
|
+
### [`ArrayPlus.ElementMatch`](./array_plus.element_match.ts#l30)
|
|
302
|
+
|
|
303
|
+
`ArrayPlus.ElementMatch<T, Criteria, Options = { widen, caseNotMatch, caseWiden, caseUnionNotMatch }>`
|
|
304
|
+
|
|
305
|
+
🌪️ *filter*
|
|
306
|
+
🔢 *customizable*
|
|
307
|
+
|
|
308
|
+
Filter the element `T` in an array or tuple to match `Criteria`.
|
|
309
|
+
|
|
310
|
+
```ts
|
|
311
|
+
import type { ArrayPlus } from 'type-plus'
|
|
312
|
+
|
|
313
|
+
type R = ArrayPlus.ElementMatch<number, number> // number
|
|
314
|
+
type R = ArrayPlus.ElementMatch<1, number> // 1
|
|
315
|
+
type R = ArrayPlus.ElementMatch<number, string> // notMatch: never
|
|
316
|
+
type R = ArrayPlus.ElementMatch<number, 1> // widen: 1
|
|
317
|
+
type R = ArrayPlus.ElementMatch<number | string, number> // unionNotMatch: number
|
|
318
|
+
|
|
319
|
+
// customization
|
|
320
|
+
type R = ArrayPlus.ElementMatch<number, string, { caseNotMatch: 1 }> // 1
|
|
321
|
+
type R = ArrayPlus.ElementMatch<number, 1, { widen: false }> // never
|
|
322
|
+
type R = ArrayPlus.ElementMatch<number, 1, { caseWiden: never }> // never
|
|
323
|
+
type R = ArrayPlus.ElementMatch<number | string, number, { caseUnionNotMatch: undefined }> // number | undefined
|
|
324
|
+
```
|
|
325
|
+
|
|
75
326
|
### [`ArrayPlus.Entries`](./array.entries.ts#L14)
|
|
76
327
|
|
|
77
328
|
> `ArrayPlus.Entries<A>`
|
|
@@ -82,24 +333,37 @@ Note that this is not the same as `Array.entries(A)`,
|
|
|
82
333
|
which returns an iterable interator.
|
|
83
334
|
|
|
84
335
|
```ts
|
|
85
|
-
ArrayPlus.Entries<Array<string | number>> // Array<[number, string | number]>
|
|
86
|
-
ArrayPlus.Entries<[1, 2, 3]> // [[0, 1], [1, 2], [2, 3]]
|
|
336
|
+
type R = ArrayPlus.Entries<Array<string | number>> // Array<[number, string | number]>
|
|
337
|
+
type R = ArrayPlus.Entries<[1, 2, 3]> // [[0, 1], [1, 2], [2, 3]]
|
|
87
338
|
```
|
|
88
339
|
|
|
89
|
-
### [`ArrayPlus.Find`](./
|
|
340
|
+
### [`ArrayPlus.Find`](./array_plus.find.ts#l49)
|
|
90
341
|
|
|
91
|
-
|
|
342
|
+
`ArrayPlus.Find<A, Criteria, Options { widen, caseNever, caseNotMatch, caseTuple, caseWiden, caseUnionNotMatch }>`
|
|
92
343
|
|
|
93
|
-
|
|
344
|
+
🦴 *utilities*
|
|
345
|
+
🔢 *customizable*
|
|
94
346
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
For `Array<T>`, it will return `T | undefined` if `T` satisfies `Criteria`.
|
|
347
|
+
Finds the type in array `A` that matches `Criteria`.
|
|
98
348
|
|
|
99
349
|
```ts
|
|
100
|
-
ArrayPlus
|
|
101
|
-
|
|
102
|
-
ArrayPlus.Find<
|
|
350
|
+
import type { ArrayPlus } from 'type-plus'
|
|
351
|
+
|
|
352
|
+
type R = ArrayPlus.Find<Array<string>, string> // string
|
|
353
|
+
type R = ArrayPlus.Find<Array<1 | 2 | 'x'>, number> // 1 | 2 | undefined
|
|
354
|
+
type R = ArrayPlus.Find<Array<string | number>, number | string> // string | number
|
|
355
|
+
type R = ArrayPlus.Find<number[], 1> // widen: 1 | undefined
|
|
356
|
+
type R = ArrayPlus.Find<Array<string | number>, number> // unionNotMatch: number
|
|
357
|
+
|
|
358
|
+
type R = ArrayPlus.Find<string[], number> // never
|
|
359
|
+
|
|
360
|
+
// customization
|
|
361
|
+
type R = ArrayPlus.Find<number[], 1, { widen: false }> // never
|
|
362
|
+
type R = ArrayPlus.Find<number[], 1, { caseWiden: never }> // never
|
|
363
|
+
type R = ArrayPlus.Find<never, 1, { caseNever: 2 }> // 2
|
|
364
|
+
type R = ArrayPlus.Find<string[], number, { caseNotMatch: 2 }> // 2
|
|
365
|
+
type R = ArrayPlus.Find<[], 1, { caseTuple: 2 }> // 2
|
|
366
|
+
type R = ArrayPlus.Find<Array<string | number>, number, { caseUnionNotMatch: undefined }> // number | undefined
|
|
103
367
|
```
|
|
104
368
|
|
|
105
369
|
### [`ArrayPlus.FindLast`](./array.find_last.ts#L17)
|
|
@@ -174,7 +438,7 @@ or with reduced capability.
|
|
|
174
438
|
They are exposed under the `ArrayPlus` namespace,
|
|
175
439
|
while some common ones are exposed at top-level.
|
|
176
440
|
|
|
177
|
-
Here are the list of array methods and their corresponding type-level functions, if
|
|
441
|
+
Here are the list of array methods and their corresponding type-level functions, if available.
|
|
178
442
|
|
|
179
443
|
- ✅ `at`: [`ArrayPlus.At`](#arrayplusat)
|
|
180
444
|
- ✅ `concat`: [`Concat` | `ArrayPlus.Concat`](#arrayplusconcat) (`[...A, ...B]`)
|
|
@@ -210,3 +474,4 @@ Here are the list of array methods and their corresponding type-level functions,
|
|
|
210
474
|
|
|
211
475
|
[handbook]: https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#arrays
|
|
212
476
|
[tuple]: ../tuple/readme.md
|
|
477
|
+
[union]: ../union/readme.md
|
package/ts/array/reduce_while.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 🦴 *utilities*
|
|
3
|
+
*
|
|
4
|
+
* `reduce()` with predicate for early termination.
|
|
5
|
+
* A simple version of the same function in the `ramda` package.
|
|
6
|
+
*/
|
|
1
7
|
export function reduceWhile<T, R>(
|
|
2
8
|
predicate: (acc: R, currentValue: T) => boolean,
|
|
3
9
|
callbackfn: (previousValue: R, currentValue: T, currentIndex: number, array: T[]) => R,
|
package/ts/array/reverse.ts
CHANGED
|
@@ -3,7 +3,10 @@ import { isConstructor, type AnyConstructor } from '../class/index.js'
|
|
|
3
3
|
import { type AnyFunction } from '../function/any_function.js'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* 💥 *immediate*
|
|
7
|
+
* 🚦 *assertion*
|
|
8
|
+
*
|
|
9
|
+
* Assert the subject satisfies the specified type T
|
|
7
10
|
* @type T the type to check against.
|
|
8
11
|
*/
|
|
9
12
|
export function assertType<T>(subject: T): asserts subject is T
|
package/ts/assertion/readme.md
CHANGED
|
@@ -9,11 +9,12 @@ They throw an error if the condition is not met, and return nothing otherwise.
|
|
|
9
9
|
These assertion functions are typically used in runtime,
|
|
10
10
|
so that that type of the value can be narrowed down.
|
|
11
11
|
|
|
12
|
-
## assertType
|
|
12
|
+
## [assertType](./assert_type.ts#l10)
|
|
13
13
|
|
|
14
|
-
`assertType<T>(subject)
|
|
14
|
+
`assertType<T>(subject)`
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
💥 *immediate*
|
|
17
|
+
🚦 *assertion*
|
|
17
18
|
|
|
18
19
|
It ensures `subject` satisfies `T`.
|
|
19
20
|
It is similar to `const x: T = subject` without introducing an unused variable.
|
package/ts/functional/compose.ts
CHANGED
package/ts/functional/context.ts
CHANGED
|
@@ -27,7 +27,7 @@ export type ContextBuilder<Init extends ContextBaseShape, Ctx extends ContextBas
|
|
|
27
27
|
*/
|
|
28
28
|
extend<Additional extends ContextBaseShape = ContextBaseShape>(
|
|
29
29
|
extender: ContextExtender<Ctx, Additional>
|
|
30
|
-
): ContextBuilder<Init, LeftJoin<Ctx, Additional
|
|
30
|
+
): ContextBuilder<Init, LeftJoin<Ctx, Additional>>,
|
|
31
31
|
/**
|
|
32
32
|
* Build and return the context.
|
|
33
33
|
*/
|