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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "type-plus",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.5.0",
|
|
4
4
|
"description": "Provides additional types for TypeScript.",
|
|
5
5
|
"homepage": "https://github.com/unional/type-plus/tree/main/type-plus#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -19,14 +19,18 @@
|
|
|
19
19
|
"sideEffects": false,
|
|
20
20
|
"type": "module",
|
|
21
21
|
"exports": {
|
|
22
|
-
"
|
|
23
|
-
"
|
|
22
|
+
".": {
|
|
23
|
+
"import": {
|
|
24
|
+
"types": "./esm/index.d.ts",
|
|
25
|
+
"default": "./esm/index.js"
|
|
26
|
+
},
|
|
27
|
+
"require": {
|
|
28
|
+
"types": "./cjs/index.d.ts",
|
|
29
|
+
"default": "./cjs/index.js"
|
|
30
|
+
},
|
|
24
31
|
"default": "./esm/index.js"
|
|
25
32
|
},
|
|
26
|
-
"
|
|
27
|
-
"types": "./cjs/index.d.ts",
|
|
28
|
-
"default": "./cjs/index.js"
|
|
29
|
-
}
|
|
33
|
+
"./package.json": "./package.json"
|
|
30
34
|
},
|
|
31
35
|
"main": "./cjs/index.js",
|
|
32
36
|
"module": "./esm/index.js",
|
|
@@ -64,8 +68,7 @@
|
|
|
64
68
|
"satisfier": "^5.2.2",
|
|
65
69
|
"size-limit": "^8.2.4",
|
|
66
70
|
"ts-jest": "^29.1.0",
|
|
67
|
-
"tslib": "^2.4.0"
|
|
68
|
-
"typescript": "^5.0.4"
|
|
71
|
+
"tslib": "^2.4.0"
|
|
69
72
|
},
|
|
70
73
|
"scripts": {
|
|
71
74
|
"build": "run-p build:cjs build:esm build:tslib",
|
package/ts/any/any_type.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
2
1
|
/**
|
|
3
|
-
*
|
|
2
|
+
* 🌪️ *filter*
|
|
4
3
|
*
|
|
5
|
-
*
|
|
4
|
+
* Filter `T` to ensure it is exactly `any`.
|
|
6
5
|
*
|
|
7
6
|
* @example
|
|
8
7
|
* ```ts
|
|
@@ -16,10 +15,10 @@
|
|
|
16
15
|
export type AnyType<T, Then = T, Else = never> = 0 extends 1 & T ? Then : Else
|
|
17
16
|
|
|
18
17
|
/**
|
|
19
|
-
* Validate if `T` is exactly `any`.
|
|
20
|
-
*
|
|
21
18
|
* 🎭 *validate*
|
|
22
19
|
*
|
|
20
|
+
* Validate if `T` is exactly `any`.
|
|
21
|
+
*
|
|
23
22
|
* @example
|
|
24
23
|
* ```ts
|
|
25
24
|
* type R = IsAny<any> // true
|
|
@@ -32,9 +31,9 @@ export type AnyType<T, Then = T, Else = never> = 0 extends 1 & T ? Then : Else
|
|
|
32
31
|
export type IsAny<T, Then = true, Else = false> = AnyType<T, Then, Else>
|
|
33
32
|
|
|
34
33
|
/**
|
|
35
|
-
*
|
|
34
|
+
* 🌪️ *filter*
|
|
36
35
|
*
|
|
37
|
-
*
|
|
36
|
+
* Filter `T` to ensure it is not exactly `any`.
|
|
38
37
|
*
|
|
39
38
|
* @example
|
|
40
39
|
* ```ts
|
|
@@ -48,10 +47,10 @@ export type IsAny<T, Then = true, Else = false> = AnyType<T, Then, Else>
|
|
|
48
47
|
export type NotAnyType<T, Then = T, Else = never> = AnyType<T, Else, Then>
|
|
49
48
|
|
|
50
49
|
/**
|
|
51
|
-
* Validate if `T` is not exactly `any`.
|
|
52
|
-
*
|
|
53
50
|
* 🎭 *validate*
|
|
54
51
|
*
|
|
52
|
+
* Validate if `T` is not exactly `any`.
|
|
53
|
+
*
|
|
55
54
|
* @example
|
|
56
55
|
* ```ts
|
|
57
56
|
* import type { IsNotAny } from 'type-plus'
|
package/ts/any/readme.md
CHANGED
|
@@ -12,10 +12,77 @@ They are strict type checks, meaning they match only the type `any`.
|
|
|
12
12
|
Union and intersections are not a factor here they are resolved to `any`,
|
|
13
13
|
except `any & never` which is `never`.
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
### [AnyType](./any.spec.ts#15)
|
|
16
|
+
|
|
17
|
+
`AnyType<T, Then = T, Else = never>`
|
|
18
|
+
|
|
19
|
+
🌪️ *filter*
|
|
20
|
+
|
|
21
|
+
Filter `T` to ensure it is exactly `any`.
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import type { AnyType } from 'type-plus'
|
|
25
|
+
|
|
26
|
+
type R = AnyType<any> // any
|
|
27
|
+
|
|
28
|
+
type R = AnyType<never> // never
|
|
29
|
+
type R = AnyType<unknown> // never
|
|
30
|
+
type R = AnyType<string | boolean> // never
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### [IsAny](./any.spec.ts#31)
|
|
34
|
+
|
|
35
|
+
`IsAny<T, Then = true, Else = false>`
|
|
36
|
+
|
|
37
|
+
🎭 *validate*
|
|
38
|
+
|
|
39
|
+
Validate if `T` is exactly `any`.
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
import type { IsAny } from 'type-plus'
|
|
43
|
+
|
|
44
|
+
type R = IsAny<any> // true
|
|
45
|
+
|
|
46
|
+
type R = IsAny<never> // false
|
|
47
|
+
type R = IsAny<unknown> // false
|
|
48
|
+
type R = IsAny<string | boolean> // false
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### [NotAnyType](./any.spec.ts#47)
|
|
52
|
+
|
|
53
|
+
`NotAnyType<T, Then = T, Else = never>`
|
|
54
|
+
|
|
55
|
+
🌪️ *filter*
|
|
56
|
+
|
|
57
|
+
Filter `T` to ensure it is not exactly `any`.
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
import type { NotAnyType } from 'type-plus'
|
|
61
|
+
|
|
62
|
+
type R = NotAnyType<any> // never
|
|
63
|
+
|
|
64
|
+
type R = NotAnyType<never> // never
|
|
65
|
+
type R = NotAnyType<unknown> // never
|
|
66
|
+
type R = NotAnyType<string | boolean> // string | boolean
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### [IsNotAny](./any.spec.ts#65)
|
|
70
|
+
|
|
71
|
+
`IsNotAny<T, Then = true, Else = false>`
|
|
72
|
+
|
|
73
|
+
🎭 *validate*
|
|
74
|
+
|
|
75
|
+
Validate if `T` is not exactly `any`.
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
import type { IsNotAny } from 'type-plus'
|
|
79
|
+
|
|
80
|
+
type R = IsNotAny<any> // false
|
|
81
|
+
|
|
82
|
+
type R = IsNotAny<never> // true
|
|
83
|
+
type R = IsNotAny<unknown> // true
|
|
84
|
+
type R = IsNotAny<string | boolean> // true
|
|
85
|
+
```
|
|
19
86
|
|
|
20
87
|
## Trivia
|
|
21
88
|
|
package/ts/array/array.at.ts
CHANGED
|
@@ -3,7 +3,9 @@ import type { TupleType } from '../tuple/tuple_type.js'
|
|
|
3
3
|
import type { IndexAt } from './array_index.js'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* 🦴 *utilities*
|
|
7
|
+
*
|
|
8
|
+
* Gets the type of the array or tuple at positive or negative index `N`.
|
|
7
9
|
*
|
|
8
10
|
* Like `Array.at()`, this type supports negative numbers.
|
|
9
11
|
*
|
|
@@ -13,12 +13,14 @@ import type { IsTuple } from '../tuple/tuple_type.js'
|
|
|
13
13
|
*/
|
|
14
14
|
export type Entries<A extends unknown[]> = IsTuple<
|
|
15
15
|
A,
|
|
16
|
-
Device<A, []>,
|
|
16
|
+
Entries.Device<A, []>,
|
|
17
17
|
A extends Array<infer T> ? Array<[number, T]> : never
|
|
18
18
|
>
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
export namespace Entries {
|
|
21
|
+
export type Device<A extends unknown[], R extends unknown[]> = A['length'] extends 0
|
|
21
22
|
? R
|
|
22
23
|
: A extends [...infer F, infer N]
|
|
23
24
|
? Device<F, [[F['length'], N], ...R]>
|
|
24
25
|
: never
|
|
26
|
+
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { TupleType } from '../tuple/tuple_type.js'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* 🦴 *utilities*
|
|
5
|
+
*
|
|
6
|
+
* Gets the last type in the array or tuple that matches the `Criteria`.
|
|
5
7
|
*
|
|
6
8
|
* If the `Criteria` is not met, it will return `never'.
|
|
7
9
|
*
|
package/ts/array/array.some.ts
CHANGED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { NeverType } from '../never/never_type.js'
|
|
2
|
+
import type { KeyTypes } from '../object/KeyTypes.js'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* ⚗️ *transform*
|
|
6
|
+
* 🔢 *customization*
|
|
7
|
+
*
|
|
8
|
+
* Gets the common keys of the record types in the array `A`.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { type ArrayPlus } from 'type-plus'
|
|
13
|
+
*
|
|
14
|
+
* type R = ArrayPlus.CommonPropKeys<Array<{ a: 1 }>> // 'a'
|
|
15
|
+
* type R = ArrayPlus.CommonPropKeys<Array<{ a: 1, b: 1 } | { a: 1, c: 1 }>> // 'a'
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @typeParam Options['caseNever'] Return type when `T` is `never`.
|
|
19
|
+
* Default to `never`.
|
|
20
|
+
*/
|
|
21
|
+
export type CommonPropKeys<
|
|
22
|
+
A extends Record<KeyTypes, unknown>[],
|
|
23
|
+
Options extends CommonPropKeys.Options = CommonPropKeys.DefaultOptions
|
|
24
|
+
> = NeverType<A,
|
|
25
|
+
Options['caseNever'],
|
|
26
|
+
A extends Array<infer R extends Record<KeyTypes, unknown>> ? keyof R : never
|
|
27
|
+
>
|
|
28
|
+
|
|
29
|
+
export namespace CommonPropKeys {
|
|
30
|
+
export interface Options extends NeverType.Options {
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface DefaultOptions extends NeverType.DefaultOptions {
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { NonNull } from '../utils/NonNull.js'
|
|
2
|
+
import type { NonUndefined } from '../utils/NonUndefined.js'
|
|
3
|
+
|
|
4
|
+
export type DropMatch<A extends Readonly<Array<unknown>>, Criteria> = A[0] extends Criteria
|
|
5
|
+
? never[]
|
|
6
|
+
: (undefined extends Criteria
|
|
7
|
+
? (null extends Criteria
|
|
8
|
+
? Array<NonNullable<A[0]>>
|
|
9
|
+
: Array<NonUndefined<A[0]>>)
|
|
10
|
+
: (null extends Criteria
|
|
11
|
+
? Array<NonNull<A[0]>>
|
|
12
|
+
: (Criteria extends A[0]
|
|
13
|
+
? Array<Exclude<A[0], Criteria>>
|
|
14
|
+
: (A[0] extends Criteria
|
|
15
|
+
? A
|
|
16
|
+
: Array<Exclude<A[0], Criteria>>))))
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { IsNever } from '../never/never_type.js'
|
|
2
|
+
import type { IsUnion } from '../union/union.js'
|
|
3
|
+
import type { MergeOptions } from '../utils/options.js'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 🦴 *utilities*
|
|
7
|
+
* 🔢 *customizable*
|
|
8
|
+
*
|
|
9
|
+
* Filter the element `T` in an array or tuple to match `Criteria`.
|
|
10
|
+
*
|
|
11
|
+
* @typeParam Options['widen'] Allow using narrow type to match widen type.
|
|
12
|
+
* e.g. `number, 1` -> `1 | undefined`.
|
|
13
|
+
* Default to `true`.
|
|
14
|
+
*
|
|
15
|
+
* @typeParam Options['caseNotMatch'] Return value when `T` does not match `Criteria`.
|
|
16
|
+
* Default to `never`.
|
|
17
|
+
*
|
|
18
|
+
* @typeParam Options['caseWiden'] Return value when `widen` is true.
|
|
19
|
+
* Default to `Criteria | undefined`.
|
|
20
|
+
*
|
|
21
|
+
* @typeParam Options['caseUnionNotMatch'] Return value when a branch of the union `T` does not match `Criteria`.
|
|
22
|
+
* Default to `never`.
|
|
23
|
+
*
|
|
24
|
+
* If you want the type to behave more like JavaScript,
|
|
25
|
+
* you can override it to return `undefined`.
|
|
26
|
+
*
|
|
27
|
+
* Since it is a union, the result will be joined to the matched branch as union.
|
|
28
|
+
* e.g. `ElementMatch<1 | 2, 1>` -> `1 | undefined`
|
|
29
|
+
*/
|
|
30
|
+
export type ElementMatch<
|
|
31
|
+
T,
|
|
32
|
+
Criteria,
|
|
33
|
+
Options extends ElementMatch.Options = ElementMatch.DefaultOptions<Criteria>
|
|
34
|
+
> = [T] extends [Criteria]
|
|
35
|
+
? T
|
|
36
|
+
: (MergeOptions<Options, ElementMatch.DefaultOptions<Criteria>> extends infer C extends Record<keyof ElementMatch.Options, unknown>
|
|
37
|
+
? ((T extends Criteria
|
|
38
|
+
? T
|
|
39
|
+
: (C['widen'] extends true
|
|
40
|
+
? (Criteria extends T
|
|
41
|
+
? C['caseWiden']
|
|
42
|
+
: C['caseNotMatch'])
|
|
43
|
+
: C['caseNotMatch'])) extends infer R
|
|
44
|
+
? IsUnion<T, IsNever<R, R, R | C['caseUnionNotMatch']>, R>
|
|
45
|
+
: C['caseNotMatch'])
|
|
46
|
+
: never)
|
|
47
|
+
|
|
48
|
+
export namespace ElementMatch {
|
|
49
|
+
export interface Options {
|
|
50
|
+
widen?: boolean | undefined,
|
|
51
|
+
caseNotMatch?: unknown,
|
|
52
|
+
caseWiden?: unknown,
|
|
53
|
+
caseUnionNotMatch?: unknown
|
|
54
|
+
}
|
|
55
|
+
export interface DefaultOptions<Criteria> {
|
|
56
|
+
widen: true,
|
|
57
|
+
caseNotMatch: never,
|
|
58
|
+
caseWiden: Criteria | undefined,
|
|
59
|
+
caseUnionNotMatch: never
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { NeverType } from '../never/never_type.js'
|
|
2
|
+
import type { TupleType } from '../tuple/tuple_type.js'
|
|
3
|
+
import type { MergeOptions } from '../utils/options.js'
|
|
4
|
+
import type { ElementMatch } from './array_plus.element_match.js'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 🦴 *utilities*
|
|
8
|
+
* 🔢 *customizable*
|
|
9
|
+
*
|
|
10
|
+
* Finds the type in array `A` that matches `Criteria`.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* type R = ArrayPlus.Find<Array<string>, string> // string
|
|
15
|
+
* type R = ArrayPlus.Find<Array<1 | 2 | 'x'>, number> // 1 | 2 | undefined
|
|
16
|
+
* type R = ArrayPlus.Find<Array<string | number>, number | string> // string | number
|
|
17
|
+
* type R = ArrayPlus.Find<Array<number>, 1> // widen: 1 | undefined
|
|
18
|
+
* type R = ArrayPlus.Find<Array<string | number>, number> // unionMiss: number | undefined
|
|
19
|
+
*
|
|
20
|
+
* type R = ArrayPlus.Find<string[], number> // never
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @typeParam Options['widen'] performs widen match.
|
|
24
|
+
* Default to `true`.
|
|
25
|
+
* With widen match, a narrowed type will match its widen type.
|
|
26
|
+
* e.g. matching `1` against `number` yields `1 | undefined`
|
|
27
|
+
*
|
|
28
|
+
* The widen behavior can be customized by `Options['caseWiden']`
|
|
29
|
+
*
|
|
30
|
+
* @typeParam Options['caseNever'] return type when `A` is `never`. Default to `never`.
|
|
31
|
+
*
|
|
32
|
+
* @typeParam Options['caseNotMatch'] Return value when `T` does not match `Criteria`.
|
|
33
|
+
* Default to `never`.
|
|
34
|
+
*
|
|
35
|
+
* @typeParam Options['caseTuple'] return type when `A` is a tuple. Default to `not supported` message.
|
|
36
|
+
*
|
|
37
|
+
* @typeParam Options['caseWiden'] return type when `T` in `A` is a widen type of `Criteria`.
|
|
38
|
+
* Default to `Criteria | undefined`.
|
|
39
|
+
* Set it to `never` for a more type-centric behavior
|
|
40
|
+
*
|
|
41
|
+
* @typeParam Options['caseUnionNotMatch'] Return value when a branch of the union `T` does not match `Criteria`.
|
|
42
|
+
* Default to `never`.
|
|
43
|
+
*
|
|
44
|
+
* If you want the type to behave more like JavaScript,
|
|
45
|
+
* you can override it to return `undefined`.
|
|
46
|
+
*
|
|
47
|
+
* Since it is a union, the result will be joined to the matched branch as union.
|
|
48
|
+
*/
|
|
49
|
+
export type Find<
|
|
50
|
+
A extends unknown[],
|
|
51
|
+
Criteria,
|
|
52
|
+
Options extends Find.Options = Find.DefaultOptions<Criteria>
|
|
53
|
+
> =
|
|
54
|
+
MergeOptions<Options, Find.DefaultOptions<Criteria>> extends infer O extends Find.Options
|
|
55
|
+
? TupleType<
|
|
56
|
+
A,
|
|
57
|
+
O['caseTuple'],
|
|
58
|
+
A extends Array<infer T> ? ElementMatch<T, Criteria, O> : never,
|
|
59
|
+
O
|
|
60
|
+
>
|
|
61
|
+
: never
|
|
62
|
+
|
|
63
|
+
export namespace Find {
|
|
64
|
+
export interface Options extends ElementMatch.Options, NeverType.Options {
|
|
65
|
+
caseTuple?: unknown,
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface DefaultOptions<Criteria> extends ElementMatch.DefaultOptions<Criteria>, NeverType.DefaultOptions {
|
|
69
|
+
caseTuple: 'does not support tuple. Please use `FindFirst` or `TuplePlus.Find` instead.',
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { CanAssign } from '../index.js'
|
|
2
|
+
import type { CreateTuple } from '../tuple/create_tuple.js'
|
|
3
|
+
import type { UnionOfValues } from './union_of_values.js'
|
|
4
|
+
|
|
5
|
+
export type PadStart<
|
|
6
|
+
A extends unknown[],
|
|
7
|
+
MaxLength extends number,
|
|
8
|
+
PadWith = unknown
|
|
9
|
+
> = MaxLength extends 0
|
|
10
|
+
? A
|
|
11
|
+
: CanAssign<PadWith, UnionOfValues<A>> extends true
|
|
12
|
+
? A
|
|
13
|
+
: PadStart<[...CreateTuple<MaxLength, PadWith>, ...A], MaxLength, PadWith>
|
package/ts/array/array_plus.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
export type { At } from './array.at.js'
|
|
2
|
-
export type { Concat } from './array.concat.js'
|
|
3
2
|
export type { Entries } from './array.entries.js'
|
|
4
|
-
export type { FindFirst as Find } from './array.find.js'
|
|
5
3
|
export type { FindLast } from './array.find_last.js'
|
|
6
4
|
export type { Reverse } from './array.reverse.js'
|
|
7
5
|
export type { Some } from './array.some.js'
|
|
8
6
|
export type { IndexAt, IsIndexOutOfBound } from './array_index.js'
|
|
7
|
+
export type { CommonPropKeys } from './array_plus.common_prop_keys.js'
|
|
8
|
+
export type { Concat } from './array_plus.concat.js'
|
|
9
|
+
export type { DropMatch } from './array_plus.drop_match.js'
|
|
10
|
+
export type { ElementMatch } from './array_plus.element_match.js'
|
|
11
|
+
export type { Filter } from './array_plus.filter.js'
|
|
12
|
+
export type { Find } from './array_plus.find.js'
|
|
13
|
+
export type { PadStart } from './array_plus.pad_start.js'
|
|
9
14
|
export type { SplitAt } from './array_plus.split_at.js'
|
|
10
|
-
export type { PadStart } from './pad_start.js'
|
package/ts/array/array_type.ts
CHANGED
|
@@ -2,12 +2,17 @@ import type { IsNever } from '../never/never_type.js'
|
|
|
2
2
|
import type { StrictNumberType } from '../number/strict_number_type.js'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* 🌪️ *filter*
|
|
6
6
|
*
|
|
7
|
+
* Filter `T` to ensure it is an array, excluding tuple.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
7
10
|
* ```ts
|
|
8
11
|
* type R = ArrayType<number[]> // number[]
|
|
9
12
|
*
|
|
10
13
|
* type R = ArrayType<[1]> // never
|
|
14
|
+
* type R = ArrayType<number[] | 1> // never
|
|
15
|
+
* type R = ArrayType<number[] & { a: 1 }> // never
|
|
11
16
|
* ```
|
|
12
17
|
*/
|
|
13
18
|
export type ArrayType<T, Then = T, Else = never> = IsNever<
|
|
@@ -17,32 +22,45 @@ export type ArrayType<T, Then = T, Else = never> = IsNever<
|
|
|
17
22
|
>
|
|
18
23
|
|
|
19
24
|
/**
|
|
20
|
-
*
|
|
25
|
+
* 🎭 *validate*
|
|
26
|
+
*
|
|
27
|
+
* Validate that `T` is an array, excluding tuple.
|
|
21
28
|
*
|
|
29
|
+
* @example
|
|
22
30
|
* ```ts
|
|
23
|
-
* type R =
|
|
31
|
+
* type R = IsArray<number[]> // true
|
|
24
32
|
*
|
|
25
|
-
* type R =
|
|
26
|
-
* type R =
|
|
33
|
+
* type R = IsArray<number> // false
|
|
34
|
+
* type R = IsArray<[1]> // false
|
|
27
35
|
* ```
|
|
28
36
|
*/
|
|
29
|
-
export type
|
|
37
|
+
export type IsArray<T, Then = true, Else = false> = ArrayType<T, Then, Else>
|
|
30
38
|
|
|
31
39
|
/**
|
|
32
|
-
*
|
|
40
|
+
* 🌪️ *filter*
|
|
41
|
+
*
|
|
42
|
+
* Filter `T` to ensure it is not an array, excluding tuple.
|
|
33
43
|
*
|
|
44
|
+
* i.e. *tuple* will pass through this filter.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
34
47
|
* ```ts
|
|
35
|
-
* type R =
|
|
48
|
+
* type R = NotArrayType<number[]> // never
|
|
36
49
|
*
|
|
37
|
-
* type R =
|
|
38
|
-
* type R =
|
|
50
|
+
* type R = NotArrayType<number> // number
|
|
51
|
+
* type R = NotArrayType<[1]> // [1]
|
|
39
52
|
* ```
|
|
40
53
|
*/
|
|
41
|
-
export type
|
|
54
|
+
export type NotArrayType<T, Then = T, Else = never> = ArrayType<T, Else, Then>
|
|
42
55
|
|
|
43
56
|
/**
|
|
44
|
-
*
|
|
57
|
+
* 🎭 *validate*
|
|
58
|
+
*
|
|
59
|
+
* Validate that `T` is not an array, excluding tuple.
|
|
60
|
+
*
|
|
61
|
+
* i.e. *tuple* will pass through this filter.
|
|
45
62
|
*
|
|
63
|
+
* @example
|
|
46
64
|
* ```ts
|
|
47
65
|
* type R = IsNotArray<number[]> // false
|
|
48
66
|
*
|
package/ts/array/filter.ts
CHANGED
|
@@ -1,27 +1,32 @@
|
|
|
1
|
+
import type { Filter as FilterTuple } from '../tuple/tuple_plus.filter.js'
|
|
2
|
+
import type { Filter as FilterArray } from './array_plus.filter.js'
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
|
-
*
|
|
5
|
+
* ⚗️ *transform*
|
|
6
|
+
*
|
|
7
|
+
* Filter the array or tuple `A`, keeping entries satisfying `Criteria`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* type R = Filter<[1, 2, '3'], number> // [1, 2]
|
|
12
|
+
* type R = Filter<Array<string | undefined>, string> // string[]
|
|
13
|
+
* ```
|
|
3
14
|
*/
|
|
4
|
-
export type Filter<A extends
|
|
5
|
-
?
|
|
6
|
-
|
|
7
|
-
? A
|
|
8
|
-
: Criteria extends A[0]
|
|
9
|
-
? Array<Criteria>
|
|
10
|
-
: never[]
|
|
11
|
-
: // tuple
|
|
12
|
-
A['length'] extends 0
|
|
13
|
-
? never
|
|
14
|
-
: A extends [infer Head, ...infer Tail]
|
|
15
|
-
? Tail['length'] extends 0
|
|
16
|
-
? Head extends Criteria
|
|
17
|
-
? [Head]
|
|
18
|
-
: never[]
|
|
19
|
-
: Head extends Criteria
|
|
20
|
-
? [Head, ...Filter<Tail, Criteria>]
|
|
21
|
-
: Filter<Tail, Criteria>
|
|
22
|
-
: never
|
|
15
|
+
export type Filter<A extends unknown[], Criteria> = number extends A['length']
|
|
16
|
+
? FilterArray<A, Criteria>
|
|
17
|
+
: FilterTuple<A, Criteria>
|
|
23
18
|
|
|
24
19
|
/**
|
|
25
|
-
*
|
|
20
|
+
* ⚗️ *transform*
|
|
21
|
+
* 👽 *alias*
|
|
22
|
+
*
|
|
23
|
+
* Keeps entries satisfying `Criteria` in array or tuple `A`.
|
|
24
|
+
*
|
|
25
|
+
* @alias of [Filter](./filter.ts)
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* type R = KeepMatch<[1, 2, 3], number> // [1, 2]
|
|
29
|
+
* type R = KeepMatch<Array<string|undefined>, string> // string[]
|
|
30
|
+
* ```
|
|
26
31
|
*/
|
|
27
|
-
export type KeepMatch<A extends
|
|
32
|
+
export type KeepMatch<A extends unknown[], Criteria> = Filter<A, Criteria>
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { TupleType } from '../tuple/tuple_type.js'
|
|
2
|
+
import type { Find as TupleFind } from '../tuple/tuple_plus.find.js'
|
|
3
|
+
import type { Find as ArrayFind } from './array_plus.find.js'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 🦴 *utilities*
|
|
7
|
+
* 🔢 *customizable*
|
|
8
|
+
*
|
|
9
|
+
* Find the first type in the array or tuple `A` that matches `Criteria`.
|
|
10
|
+
*
|
|
11
|
+
* If the `Criteria` is not met, it will return `never'.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* type R = FindFirst<[true, 1, 'x', 3], string> // 'x'
|
|
16
|
+
* type R = FindFirst<[true, 1, 'x', 3], number> // 1
|
|
17
|
+
* type R = FindFirst<[string, number, 1], 1> // widen: 1 | undefined
|
|
18
|
+
* type R = FindFirst<[true, number | string], string> // unionMiss: string | undefined
|
|
19
|
+
* type R = FindFirst<Array<string>, string> // string
|
|
20
|
+
* type R = FindFirst<Array<1 | 2 | 'x'>, number> // 1 | 2 | undefined
|
|
21
|
+
* type R = FindFirst<Array<string | number>, number | string> // string | number
|
|
22
|
+
* type R = FindFirst<Array<number>, 1> // widen: 1 | undefined
|
|
23
|
+
* type R = FindFirst<Array<string | number>, number> // unionMiss: number | undefined
|
|
24
|
+
*
|
|
25
|
+
* type R = FindFirst<[true, 1, 'x'], 2> // never
|
|
26
|
+
* type R = FindFirst<string[], number> // never
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @typeParam Options['widen'] performs widen match.
|
|
30
|
+
* Default to `true`.
|
|
31
|
+
* With widen match, a narrowed type will match its widen type.
|
|
32
|
+
* e.g. matching `1` against `number` yields `1 | undefined`
|
|
33
|
+
*
|
|
34
|
+
* The widen behavior can be customized by `Options['caseWiden']`
|
|
35
|
+
*
|
|
36
|
+
* @typeParam Options['caseEmptyTuple'] return type when `A` is an empty tuple.
|
|
37
|
+
* Default to `never`.
|
|
38
|
+
*
|
|
39
|
+
* @typeParam Options['caseNever'] return type when `A` is `never`. Default to `never`.
|
|
40
|
+
*
|
|
41
|
+
* @typeParam Options['caseNoMatch'] Return value when `T` does not match `Criteria`.
|
|
42
|
+
* Default to `never`.
|
|
43
|
+
*
|
|
44
|
+
* @typeParam Options['caseWiden'] return type when `T` in `A` is a widen type of `Criteria`.
|
|
45
|
+
* Default to `Criteria | undefined`.
|
|
46
|
+
* Set it to `never` for a more type-centric behavior
|
|
47
|
+
*
|
|
48
|
+
* @typeParam Options['caseUnionMiss'] Return value when a branch of the union `T` does not match `Criteria`.
|
|
49
|
+
* Default to `undefined`.
|
|
50
|
+
* Since it is a union, the result will be join to the matched branch as union.
|
|
51
|
+
*/
|
|
52
|
+
export type FindFirst<
|
|
53
|
+
A extends unknown[],
|
|
54
|
+
Criteria, Options extends FindFirst.Options = FindFirst.DefaultOptions<Criteria>
|
|
55
|
+
> = TupleType<
|
|
56
|
+
A,
|
|
57
|
+
TupleFind<A, Criteria, Options>,
|
|
58
|
+
ArrayFind<A, Criteria, Options>
|
|
59
|
+
>
|
|
60
|
+
|
|
61
|
+
export namespace FindFirst {
|
|
62
|
+
export interface Options extends ArrayFind.Options, TupleFind.Options { }
|
|
63
|
+
export interface DefaultOptions<Criteria>
|
|
64
|
+
extends ArrayFind.DefaultOptions<Criteria>, TupleFind.DefaultOptions<Criteria> { }
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* @deprecated use FindFirst
|
|
70
|
+
*/
|
|
71
|
+
export type First<A extends any[], Criteria> = FindFirst<A, Criteria>
|