type-plus 6.8.0 → 7.0.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 +1053 -356
- package/cjs/array/{array.d.ts → array.at.d.ts} +4 -14
- package/cjs/array/array.at.d.ts.map +1 -0
- package/cjs/array/{pad_left.js → array.at.js} +1 -1
- package/cjs/array/array.at.js.map +1 -0
- package/cjs/array/array.concat.d.ts +13 -0
- package/cjs/array/array.concat.d.ts.map +1 -0
- package/cjs/array/array.concat.js +3 -0
- package/cjs/array/array.concat.js.map +1 -0
- package/cjs/array/array.entries.d.ts +17 -0
- package/cjs/array/array.entries.d.ts.map +1 -0
- package/cjs/array/array.entries.js +3 -0
- package/cjs/array/array.entries.js.map +1 -0
- package/cjs/array/array.find.d.ts +21 -0
- package/cjs/array/array.find.d.ts.map +1 -0
- package/cjs/array/{find_first.js → array.find.js} +1 -1
- package/cjs/array/array.find.js.map +1 -0
- package/cjs/array/array.find_last.d.ts +17 -0
- package/cjs/array/array.find_last.d.ts.map +1 -0
- package/cjs/array/array.find_last.js +3 -0
- package/cjs/array/array.find_last.js.map +1 -0
- package/cjs/array/array.reverse.d.ts +2 -0
- package/cjs/array/array.reverse.d.ts.map +1 -0
- package/cjs/array/array.reverse.js +3 -0
- package/cjs/array/array.reverse.js.map +1 -0
- package/cjs/array/array.some.d.ts +29 -0
- package/cjs/array/array.some.d.ts.map +1 -0
- package/cjs/array/array.some.js +3 -0
- package/cjs/array/array.some.js.map +1 -0
- package/cjs/array/array_index.d.ts +8 -8
- package/cjs/array/array_index.d.ts.map +1 -1
- package/cjs/array/array_plus.d.ts +9 -1
- package/cjs/array/array_plus.d.ts.map +1 -1
- package/cjs/array/array_plus.split_at.d.ts +30 -0
- package/cjs/array/array_plus.split_at.d.ts.map +1 -0
- package/cjs/array/array_plus.split_at.js +3 -0
- package/cjs/array/array_plus.split_at.js.map +1 -0
- package/cjs/array/drop.d.ts +2 -2
- package/cjs/array/drop.d.ts.map +1 -1
- package/cjs/array/index.d.ts +4 -5
- package/cjs/array/index.d.ts.map +1 -1
- package/cjs/array/index.js +4 -5
- package/cjs/array/index.js.map +1 -1
- package/cjs/array/pad_start.d.ts +32 -0
- package/cjs/array/pad_start.d.ts.map +1 -0
- package/cjs/array/{find_last.js → pad_start.js} +1 -1
- package/cjs/array/pad_start.js.map +1 -0
- package/cjs/assertion/assert_type.d.ts +3 -0
- package/cjs/assertion/assert_type.d.ts.map +1 -1
- package/cjs/assertion/assert_type.js +3 -0
- package/cjs/assertion/assert_type.js.map +1 -1
- package/cjs/bigint/cast.d.ts +10 -0
- package/cjs/bigint/cast.d.ts.map +1 -0
- package/cjs/{array/some.js → bigint/cast.js} +1 -1
- package/cjs/bigint/cast.js.map +1 -0
- package/cjs/equal/equal.d.ts +51 -3
- package/cjs/equal/equal.d.ts.map +1 -1
- package/cjs/functional/Maybe.d.ts +2 -2
- package/cjs/functional/Maybe.d.ts.map +1 -1
- package/cjs/index.d.ts +16 -7
- package/cjs/index.d.ts.map +1 -1
- package/cjs/index.js +6 -1
- package/cjs/index.js.map +1 -1
- package/cjs/math/abs.d.ts +6 -0
- package/cjs/math/abs.d.ts.map +1 -0
- package/cjs/math/{Add.js → abs.js} +1 -1
- package/cjs/math/abs.js.map +1 -0
- package/cjs/math/add.d.ts +7 -0
- package/cjs/math/add.d.ts.map +1 -0
- package/cjs/math/{Max.js → add.js} +1 -1
- package/cjs/math/add.js.map +1 -0
- package/cjs/math/greater_than.d.ts +4 -0
- package/cjs/math/greater_than.d.ts.map +1 -0
- package/cjs/math/greater_than.js +3 -0
- package/cjs/math/greater_than.js.map +1 -0
- package/cjs/math/index.d.ts +6 -6
- package/cjs/math/index.d.ts.map +1 -1
- package/cjs/math/math_plus.d.ts +5 -0
- package/cjs/math/math_plus.d.ts.map +1 -0
- package/cjs/math/math_plus.js +3 -0
- package/cjs/math/math_plus.js.map +1 -0
- package/cjs/math/math_plus.to_negative.d.ts +13 -0
- package/cjs/math/math_plus.to_negative.d.ts.map +1 -0
- package/cjs/math/math_plus.to_negative.js +3 -0
- package/cjs/math/math_plus.to_negative.js.map +1 -0
- package/cjs/math/max.d.ts +4 -0
- package/cjs/math/max.d.ts.map +1 -0
- package/cjs/math/{Abs.js → max.js} +1 -1
- package/cjs/math/max.js.map +1 -0
- package/cjs/math/multiply.d.ts +6 -0
- package/cjs/math/multiply.d.ts.map +1 -0
- package/cjs/{array/array.js → math/multiply.js} +1 -1
- package/cjs/math/multiply.js.map +1 -0
- package/cjs/math/numeric_struct.d.ts +1469 -0
- package/cjs/math/numeric_struct.d.ts.map +1 -0
- package/cjs/math/numeric_struct.js +3 -0
- package/cjs/math/numeric_struct.js.map +1 -0
- package/cjs/math/subtract.d.ts +7 -0
- package/cjs/math/subtract.d.ts.map +1 -0
- package/cjs/math/subtract.js +3 -0
- package/cjs/math/subtract.js.map +1 -0
- package/cjs/nominal/brand.js +2 -2
- package/cjs/nominal/brand.js.map +1 -1
- package/cjs/nominal/flavor.js +2 -2
- package/cjs/nominal/flavor.js.map +1 -1
- package/cjs/number/cast.d.ts +10 -0
- package/cjs/number/cast.d.ts.map +1 -0
- package/cjs/number/cast.js +3 -0
- package/cjs/number/cast.js.map +1 -0
- package/cjs/number/number_array.d.ts +0 -2
- package/cjs/number/number_array.d.ts.map +1 -1
- package/cjs/number/number_array.js +14 -1
- package/cjs/number/number_array.js.map +1 -1
- package/cjs/number/number_plus.d.ts +4 -5
- package/cjs/number/number_plus.d.ts.map +1 -1
- package/cjs/number/strict_number_type.d.ts +12 -0
- package/cjs/number/strict_number_type.d.ts.map +1 -1
- package/cjs/numeric/cast.d.ts +27 -0
- package/cjs/numeric/cast.d.ts.map +1 -0
- package/cjs/numeric/cast.js +3 -0
- package/cjs/numeric/cast.js.map +1 -0
- package/{esm/number → cjs/numeric}/integer.d.ts +2 -0
- package/cjs/numeric/integer.d.ts.map +1 -0
- package/cjs/{number → numeric}/integer.js.map +1 -1
- package/cjs/numeric/negative.d.ts.map +1 -0
- package/cjs/{number → numeric}/negative.js.map +1 -1
- package/cjs/numeric/numeric_plus.d.ts +5 -0
- package/cjs/numeric/numeric_plus.d.ts.map +1 -0
- package/cjs/numeric/numeric_plus.js +3 -0
- package/cjs/numeric/numeric_plus.js.map +1 -0
- package/cjs/numeric/numeric_type.d.ts.map +1 -0
- package/cjs/{number → numeric}/numeric_type.js.map +1 -1
- package/cjs/{number → numeric}/positive.d.ts +2 -2
- package/cjs/numeric/positive.d.ts.map +1 -0
- package/cjs/{number → numeric}/positive.js.map +1 -1
- package/cjs/object/ANotB.d.ts +3 -3
- package/cjs/object/ANotB.d.ts.map +1 -1
- package/cjs/object/Partial.d.ts +6 -0
- package/cjs/object/Partial.d.ts.map +1 -1
- package/cjs/object/Required.d.ts +4 -0
- package/cjs/object/Required.d.ts.map +1 -1
- package/cjs/object/index.d.ts +1 -1
- package/cjs/object/index.d.ts.map +1 -1
- package/cjs/object/object_type.d.ts +1 -1
- package/cjs/object/split.d.ts +3 -1
- package/cjs/object/split.d.ts.map +1 -1
- package/cjs/object/split.js.map +1 -1
- package/cjs/predicates/CanAssign.d.ts +35 -0
- package/cjs/predicates/CanAssign.d.ts.map +1 -1
- package/cjs/predicates/CanAssign.js.map +1 -1
- package/cjs/predicates/Extends.d.ts +2 -2
- package/cjs/predicates/Extends.d.ts.map +1 -1
- package/cjs/predicates/index.d.ts +0 -1
- package/cjs/predicates/index.d.ts.map +1 -1
- package/cjs/predicates/index.js +0 -1
- package/cjs/predicates/index.js.map +1 -1
- package/cjs/testing/stub.d.ts.map +1 -1
- package/cjs/testing/stub.js +4 -3
- package/cjs/testing/stub.js.map +1 -1
- package/cjs/testing/test_type.d.ts +125 -50
- package/cjs/testing/test_type.d.ts.map +1 -1
- package/cjs/testing/test_type.js +4 -141
- package/cjs/testing/test_type.js.map +1 -1
- package/cjs/tuple/create_tuple.d.ts +28 -0
- package/cjs/tuple/create_tuple.d.ts.map +1 -0
- package/cjs/{array → tuple}/create_tuple.js.map +1 -1
- package/cjs/tuple/tuple_plus.d.ts +2 -0
- package/cjs/tuple/tuple_plus.d.ts.map +1 -0
- package/cjs/tuple/tuple_plus.js +18 -0
- package/cjs/tuple/tuple_plus.js.map +1 -0
- package/cjs/tuple/tuple_plus.pad_start.d.ts +22 -0
- package/cjs/tuple/tuple_plus.pad_start.d.ts.map +1 -0
- package/cjs/tuple/tuple_plus.pad_start.js +3 -0
- package/cjs/tuple/tuple_plus.pad_start.js.map +1 -0
- package/cjs/{predicates/isType.d.ts → type-guard/is_type.d.ts} +5 -3
- package/cjs/type-guard/is_type.d.ts.map +1 -0
- package/cjs/{predicates/isType.js → type-guard/is_type.js} +8 -2
- package/cjs/type-guard/is_type.js.map +1 -0
- package/esm/array/{array.d.ts → array.at.d.ts} +4 -14
- package/esm/array/array.at.d.ts.map +1 -0
- package/esm/array/array.at.js +2 -0
- package/esm/array/array.at.js.map +1 -0
- package/esm/array/array.concat.d.ts +13 -0
- package/esm/array/array.concat.d.ts.map +1 -0
- package/esm/array/array.concat.js +2 -0
- package/esm/array/array.concat.js.map +1 -0
- package/esm/array/array.entries.d.ts +17 -0
- package/esm/array/array.entries.d.ts.map +1 -0
- package/esm/array/array.entries.js +2 -0
- package/esm/array/array.entries.js.map +1 -0
- package/esm/array/array.find.d.ts +21 -0
- package/esm/array/array.find.d.ts.map +1 -0
- package/esm/array/array.find.js +2 -0
- package/esm/array/array.find.js.map +1 -0
- package/esm/array/array.find_last.d.ts +17 -0
- package/esm/array/array.find_last.d.ts.map +1 -0
- package/esm/array/array.find_last.js +2 -0
- package/esm/array/array.find_last.js.map +1 -0
- package/esm/array/array.reverse.d.ts +2 -0
- package/esm/array/array.reverse.d.ts.map +1 -0
- package/esm/array/array.reverse.js +2 -0
- package/esm/array/array.reverse.js.map +1 -0
- package/esm/array/array.some.d.ts +29 -0
- package/esm/array/array.some.d.ts.map +1 -0
- package/esm/array/array.some.js +2 -0
- package/esm/array/array.some.js.map +1 -0
- package/esm/array/array_index.d.ts +8 -8
- package/esm/array/array_index.d.ts.map +1 -1
- package/esm/array/array_plus.d.ts +9 -1
- package/esm/array/array_plus.d.ts.map +1 -1
- package/esm/array/array_plus.split_at.d.ts +30 -0
- package/esm/array/array_plus.split_at.d.ts.map +1 -0
- package/esm/array/array_plus.split_at.js +2 -0
- package/esm/array/array_plus.split_at.js.map +1 -0
- package/esm/array/drop.d.ts +2 -2
- package/esm/array/drop.d.ts.map +1 -1
- package/esm/array/index.d.ts +4 -5
- package/esm/array/index.d.ts.map +1 -1
- package/esm/array/index.js +4 -5
- package/esm/array/index.js.map +1 -1
- package/esm/array/pad_start.d.ts +32 -0
- package/esm/array/pad_start.d.ts.map +1 -0
- package/esm/array/pad_start.js +2 -0
- package/esm/array/pad_start.js.map +1 -0
- package/esm/assertion/assert_type.d.ts +3 -0
- package/esm/assertion/assert_type.d.ts.map +1 -1
- package/esm/assertion/assert_type.js +3 -0
- package/esm/assertion/assert_type.js.map +1 -1
- package/esm/bigint/cast.d.ts +10 -0
- package/esm/bigint/cast.d.ts.map +1 -0
- package/esm/bigint/cast.js +2 -0
- package/esm/bigint/cast.js.map +1 -0
- package/esm/equal/equal.d.ts +51 -3
- package/esm/equal/equal.d.ts.map +1 -1
- package/esm/functional/Maybe.d.ts +2 -2
- package/esm/functional/Maybe.d.ts.map +1 -1
- package/esm/index.d.ts +16 -7
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +5 -0
- package/esm/index.js.map +1 -1
- package/esm/math/abs.d.ts +6 -0
- package/esm/math/abs.d.ts.map +1 -0
- package/esm/math/abs.js +2 -0
- package/esm/math/abs.js.map +1 -0
- package/esm/math/add.d.ts +7 -0
- package/esm/math/add.d.ts.map +1 -0
- package/esm/math/add.js +2 -0
- package/esm/math/add.js.map +1 -0
- package/esm/math/greater_than.d.ts +4 -0
- package/esm/math/greater_than.d.ts.map +1 -0
- package/esm/math/greater_than.js +2 -0
- package/esm/math/greater_than.js.map +1 -0
- package/esm/math/index.d.ts +6 -6
- package/esm/math/index.d.ts.map +1 -1
- package/esm/math/math_plus.d.ts +5 -0
- package/esm/math/math_plus.d.ts.map +1 -0
- package/esm/math/math_plus.js +2 -0
- package/esm/math/math_plus.js.map +1 -0
- package/esm/math/math_plus.to_negative.d.ts +13 -0
- package/esm/math/math_plus.to_negative.d.ts.map +1 -0
- package/esm/math/math_plus.to_negative.js +2 -0
- package/esm/math/math_plus.to_negative.js.map +1 -0
- package/esm/math/max.d.ts +4 -0
- package/esm/math/max.d.ts.map +1 -0
- package/esm/math/max.js +2 -0
- package/esm/math/max.js.map +1 -0
- package/esm/math/multiply.d.ts +6 -0
- package/esm/math/multiply.d.ts.map +1 -0
- package/esm/math/multiply.js +2 -0
- package/esm/math/multiply.js.map +1 -0
- package/esm/math/numeric_struct.d.ts +1469 -0
- package/esm/math/numeric_struct.d.ts.map +1 -0
- package/esm/math/numeric_struct.js +2 -0
- package/esm/math/numeric_struct.js.map +1 -0
- package/esm/math/subtract.d.ts +7 -0
- package/esm/math/subtract.d.ts.map +1 -0
- package/esm/math/subtract.js +2 -0
- package/esm/math/subtract.js.map +1 -0
- package/esm/nominal/brand.js +1 -1
- package/esm/nominal/brand.js.map +1 -1
- package/esm/nominal/flavor.js +1 -1
- package/esm/nominal/flavor.js.map +1 -1
- package/esm/number/cast.d.ts +10 -0
- package/esm/number/cast.d.ts.map +1 -0
- package/esm/number/cast.js +2 -0
- package/esm/number/cast.js.map +1 -0
- package/esm/number/number_array.d.ts +1 -2
- package/esm/number/number_array.d.ts.map +1 -1
- package/esm/number/number_array.js +14 -0
- package/esm/number/number_array.js.map +1 -1
- package/esm/number/number_plus.d.ts +4 -5
- package/esm/number/number_plus.d.ts.map +1 -1
- package/esm/number/strict_number_type.d.ts +12 -0
- package/esm/number/strict_number_type.d.ts.map +1 -1
- package/esm/numeric/cast.d.ts +27 -0
- package/esm/numeric/cast.d.ts.map +1 -0
- package/esm/numeric/cast.js +2 -0
- package/esm/numeric/cast.js.map +1 -0
- package/{cjs/number → esm/numeric}/integer.d.ts +2 -0
- package/esm/numeric/integer.d.ts.map +1 -0
- package/esm/{number → numeric}/integer.js.map +1 -1
- package/esm/numeric/negative.d.ts.map +1 -0
- package/esm/{number → numeric}/negative.js.map +1 -1
- package/esm/numeric/numeric_plus.d.ts +5 -0
- package/esm/numeric/numeric_plus.d.ts.map +1 -0
- package/esm/numeric/numeric_plus.js +2 -0
- package/esm/numeric/numeric_plus.js.map +1 -0
- package/esm/numeric/numeric_type.d.ts.map +1 -0
- package/esm/{number → numeric}/numeric_type.js.map +1 -1
- package/esm/{number → numeric}/positive.d.ts +2 -2
- package/esm/numeric/positive.d.ts.map +1 -0
- package/esm/{number → numeric}/positive.js.map +1 -1
- package/esm/object/ANotB.d.ts +3 -3
- package/esm/object/ANotB.d.ts.map +1 -1
- package/esm/object/Partial.d.ts +6 -0
- package/esm/object/Partial.d.ts.map +1 -1
- package/esm/object/Required.d.ts +4 -0
- package/esm/object/Required.d.ts.map +1 -1
- package/esm/object/index.d.ts +1 -1
- package/esm/object/index.d.ts.map +1 -1
- package/esm/object/object_type.d.ts +1 -1
- package/esm/object/split.d.ts +3 -1
- package/esm/object/split.d.ts.map +1 -1
- package/esm/object/split.js.map +1 -1
- package/esm/predicates/CanAssign.d.ts +35 -0
- package/esm/predicates/CanAssign.d.ts.map +1 -1
- package/esm/predicates/CanAssign.js.map +1 -1
- package/esm/predicates/Extends.d.ts +2 -2
- package/esm/predicates/Extends.d.ts.map +1 -1
- package/esm/predicates/index.d.ts +0 -1
- package/esm/predicates/index.d.ts.map +1 -1
- package/esm/predicates/index.js +0 -1
- package/esm/predicates/index.js.map +1 -1
- package/esm/testing/stub.d.ts.map +1 -1
- package/esm/testing/stub.js +4 -3
- package/esm/testing/stub.js.map +1 -1
- package/esm/testing/test_type.d.ts +125 -50
- package/esm/testing/test_type.d.ts.map +1 -1
- package/esm/testing/test_type.js +4 -141
- package/esm/testing/test_type.js.map +1 -1
- package/esm/tuple/create_tuple.d.ts +28 -0
- package/esm/tuple/create_tuple.d.ts.map +1 -0
- package/esm/{array → tuple}/create_tuple.js.map +1 -1
- package/esm/tuple/tuple_plus.d.ts +2 -0
- package/esm/tuple/tuple_plus.d.ts.map +1 -0
- package/esm/tuple/tuple_plus.js +2 -0
- package/esm/tuple/tuple_plus.js.map +1 -0
- package/esm/tuple/tuple_plus.pad_start.d.ts +22 -0
- package/esm/tuple/tuple_plus.pad_start.d.ts.map +1 -0
- package/esm/tuple/tuple_plus.pad_start.js +2 -0
- package/esm/tuple/tuple_plus.pad_start.js.map +1 -0
- package/esm/{predicates/isType.d.ts → type-guard/is_type.d.ts} +5 -3
- package/esm/type-guard/is_type.d.ts.map +1 -0
- package/esm/{predicates/isType.js → type-guard/is_type.js} +8 -2
- package/esm/type-guard/is_type.js.map +1 -0
- package/package.json +3 -3
- package/ts/array/{array.ts → array.at.ts} +10 -15
- package/ts/array/array.concat.ts +12 -0
- package/ts/array/array.entries.ts +24 -0
- package/ts/array/array.find.ts +32 -0
- package/ts/array/array.find_last.ts +27 -0
- package/ts/array/array.reverse.ts +16 -0
- package/ts/array/array.some.ts +53 -0
- package/ts/array/array_index.ts +16 -10
- package/ts/array/array_plus.split_at.ts +47 -0
- package/ts/array/array_plus.ts +9 -1
- package/ts/array/drop.ts +2 -2
- package/ts/array/index.ts +4 -5
- package/ts/array/pad_start.ts +43 -0
- package/ts/array/readme.md +184 -4
- package/ts/assertion/assert_type.ts +6 -0
- package/ts/assertion/readme.md +132 -1
- package/ts/bigint/cast.ts +13 -0
- package/ts/bigint/readme.md +17 -17
- package/ts/equal/equal.ts +53 -3
- package/ts/equal/readme.md +30 -16
- package/ts/functional/Maybe.ts +2 -2
- package/ts/index.ts +22 -24
- package/ts/math/README.md +97 -7
- package/ts/math/abs.ts +18 -0
- package/ts/math/add.ts +14 -0
- package/ts/math/greater_than.ts +12 -0
- package/ts/math/index.ts +7 -6
- package/ts/math/math_plus.to_negative.ts +22 -0
- package/ts/math/math_plus.ts +4 -0
- package/ts/math/max.ts +13 -0
- package/ts/math/multiply.ts +12 -0
- package/ts/math/numeric_struct.ts +658 -0
- package/ts/math/subtract.ts +14 -0
- package/ts/nominal/brand.ts +1 -1
- package/ts/nominal/flavor.ts +1 -1
- package/ts/number/cast.ts +17 -0
- package/ts/number/number_array.ts +14 -14
- package/ts/number/number_plus.ts +6 -6
- package/ts/number/readme.md +0 -108
- package/ts/number/strict_number_type.ts +12 -0
- package/ts/numeric/cast.ts +28 -0
- package/ts/{number → numeric}/integer.ts +2 -0
- package/ts/numeric/numeric_plus.ts +12 -0
- package/ts/{number → numeric}/positive.ts +2 -2
- package/ts/numeric/readme.md +115 -0
- package/ts/object/ANotB.ts +3 -3
- package/ts/object/Partial.ts +5 -0
- package/ts/object/Required.ts +4 -0
- package/ts/object/index.ts +1 -1
- package/ts/object/object_type.ts +1 -1
- package/ts/object/split.ts +3 -1
- package/ts/predicates/CanAssign.ts +46 -0
- package/ts/predicates/Extends.ts +2 -2
- package/ts/predicates/index.ts +0 -1
- package/ts/testing/stub.ts +7 -4
- package/ts/testing/test_type.ts +131 -88
- package/ts/tuple/create_tuple.ts +42 -0
- package/ts/tuple/readme.md +11 -10
- package/ts/tuple/tuple_plus.pad_start.ts +42 -0
- package/ts/tuple/tuple_plus.ts +1 -0
- package/ts/{predicates/isType.ts → type-guard/is_type.ts} +11 -3
- package/ts/type-guard/readme.md +37 -0
- package/cjs/array/array.d.ts.map +0 -1
- package/cjs/array/array.js.map +0 -1
- package/cjs/array/create_tuple.d.ts +0 -11
- package/cjs/array/create_tuple.d.ts.map +0 -1
- package/cjs/array/find_first.d.ts +0 -6
- package/cjs/array/find_first.d.ts.map +0 -1
- package/cjs/array/find_first.js.map +0 -1
- package/cjs/array/find_last.d.ts +0 -2
- package/cjs/array/find_last.d.ts.map +0 -1
- package/cjs/array/find_last.js.map +0 -1
- package/cjs/array/pad_left.d.ts +0 -6
- package/cjs/array/pad_left.d.ts.map +0 -1
- package/cjs/array/pad_left.js.map +0 -1
- package/cjs/array/some.d.ts +0 -8
- package/cjs/array/some.d.ts.map +0 -1
- package/cjs/array/some.js.map +0 -1
- package/cjs/math/Abs.d.ts +0 -3
- package/cjs/math/Abs.d.ts.map +0 -1
- package/cjs/math/Abs.js.map +0 -1
- package/cjs/math/Add.d.ts +0 -19
- package/cjs/math/Add.d.ts.map +0 -1
- package/cjs/math/Add.js.map +0 -1
- package/cjs/math/Digit.d.ts +0 -100
- package/cjs/math/Digit.d.ts.map +0 -1
- package/cjs/math/Digit.js +0 -3
- package/cjs/math/Digit.js.map +0 -1
- package/cjs/math/GreaterThan.d.ts +0 -13
- package/cjs/math/GreaterThan.d.ts.map +0 -1
- package/cjs/math/GreaterThan.js +0 -3
- package/cjs/math/GreaterThan.js.map +0 -1
- package/cjs/math/Max.d.ts +0 -4
- package/cjs/math/Max.d.ts.map +0 -1
- package/cjs/math/Max.js.map +0 -1
- package/cjs/math/Subtract.d.ts +0 -19
- package/cjs/math/Subtract.d.ts.map +0 -1
- package/cjs/math/Subtract.js +0 -3
- package/cjs/math/Subtract.js.map +0 -1
- package/cjs/number/integer.d.ts.map +0 -1
- package/cjs/number/negative.d.ts.map +0 -1
- package/cjs/number/numeric_type.d.ts.map +0 -1
- package/cjs/number/positive.d.ts.map +0 -1
- package/cjs/predicates/isType.d.ts.map +0 -1
- package/cjs/predicates/isType.js.map +0 -1
- package/esm/array/array.d.ts.map +0 -1
- package/esm/array/array.js +0 -2
- package/esm/array/array.js.map +0 -1
- package/esm/array/create_tuple.d.ts +0 -11
- package/esm/array/create_tuple.d.ts.map +0 -1
- package/esm/array/find_first.d.ts +0 -6
- package/esm/array/find_first.d.ts.map +0 -1
- package/esm/array/find_first.js +0 -2
- package/esm/array/find_first.js.map +0 -1
- package/esm/array/find_last.d.ts +0 -2
- package/esm/array/find_last.d.ts.map +0 -1
- package/esm/array/find_last.js +0 -2
- package/esm/array/find_last.js.map +0 -1
- package/esm/array/pad_left.d.ts +0 -6
- package/esm/array/pad_left.d.ts.map +0 -1
- package/esm/array/pad_left.js +0 -2
- package/esm/array/pad_left.js.map +0 -1
- package/esm/array/some.d.ts +0 -8
- package/esm/array/some.d.ts.map +0 -1
- package/esm/array/some.js +0 -2
- package/esm/array/some.js.map +0 -1
- package/esm/math/Abs.d.ts +0 -3
- package/esm/math/Abs.d.ts.map +0 -1
- package/esm/math/Abs.js +0 -2
- package/esm/math/Abs.js.map +0 -1
- package/esm/math/Add.d.ts +0 -19
- package/esm/math/Add.d.ts.map +0 -1
- package/esm/math/Add.js +0 -2
- package/esm/math/Add.js.map +0 -1
- package/esm/math/Digit.d.ts +0 -100
- package/esm/math/Digit.d.ts.map +0 -1
- package/esm/math/Digit.js +0 -2
- package/esm/math/Digit.js.map +0 -1
- package/esm/math/GreaterThan.d.ts +0 -13
- package/esm/math/GreaterThan.d.ts.map +0 -1
- package/esm/math/GreaterThan.js +0 -2
- package/esm/math/GreaterThan.js.map +0 -1
- package/esm/math/Max.d.ts +0 -4
- package/esm/math/Max.d.ts.map +0 -1
- package/esm/math/Max.js +0 -2
- package/esm/math/Max.js.map +0 -1
- package/esm/math/Subtract.d.ts +0 -19
- package/esm/math/Subtract.d.ts.map +0 -1
- package/esm/math/Subtract.js +0 -2
- package/esm/math/Subtract.js.map +0 -1
- package/esm/number/integer.d.ts.map +0 -1
- package/esm/number/negative.d.ts.map +0 -1
- package/esm/number/numeric_type.d.ts.map +0 -1
- package/esm/number/positive.d.ts.map +0 -1
- package/esm/predicates/isType.d.ts.map +0 -1
- package/esm/predicates/isType.js.map +0 -1
- package/ts/array/create_tuple.ts +0 -17
- package/ts/array/find_first.ts +0 -16
- package/ts/array/find_last.ts +0 -11
- package/ts/array/pad_left.ts +0 -16
- package/ts/array/some.ts +0 -33
- package/ts/math/Abs.ts +0 -7
- package/ts/math/Add.ts +0 -58
- package/ts/math/Digit.ts +0 -152
- package/ts/math/GreaterThan.ts +0 -55
- package/ts/math/Max.ts +0 -10
- package/ts/math/Subtract.ts +0 -57
- /package/cjs/{number → numeric}/integer.js +0 -0
- /package/cjs/{number → numeric}/negative.d.ts +0 -0
- /package/cjs/{number → numeric}/negative.js +0 -0
- /package/cjs/{number → numeric}/numeric_type.d.ts +0 -0
- /package/cjs/{number → numeric}/numeric_type.js +0 -0
- /package/cjs/{number → numeric}/positive.js +0 -0
- /package/cjs/{array → tuple}/create_tuple.js +0 -0
- /package/esm/{number → numeric}/integer.js +0 -0
- /package/esm/{number → numeric}/negative.d.ts +0 -0
- /package/esm/{number → numeric}/negative.js +0 -0
- /package/esm/{number → numeric}/numeric_type.d.ts +0 -0
- /package/esm/{number → numeric}/numeric_type.js +0 -0
- /package/esm/{number → numeric}/positive.js +0 -0
- /package/esm/{array → tuple}/create_tuple.js +0 -0
- /package/ts/{number → numeric}/negative.ts +0 -0
- /package/ts/{number → numeric}/numeric_type.ts +0 -0
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
export function isType(subject, validator) {
|
|
2
2
|
return validator ? !!validator(subject) : true;
|
|
3
3
|
}
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated use `isType<T>()` or `testType.true<T>()` instead
|
|
6
|
+
*/
|
|
4
7
|
isType.t = function (subject) {
|
|
5
8
|
return subject === undefined || subject === true;
|
|
6
9
|
};
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated use `isType<T>()` or `testType.false<T>()` instead
|
|
12
|
+
*/
|
|
7
13
|
isType.f = function (subject) {
|
|
8
14
|
return subject === undefined || subject === false;
|
|
9
15
|
};
|
|
@@ -16,7 +22,7 @@ isType.never = isNever;
|
|
|
16
22
|
* Easier to use than `isType.t<>()` and `isType.f<>()`,
|
|
17
23
|
* when doing type level only equality comparison as you don't have to import `Equal<>`.
|
|
18
24
|
*
|
|
19
|
-
* @deprecated use `
|
|
25
|
+
* @deprecated use `testType.equal()` instead
|
|
20
26
|
*/
|
|
21
27
|
isType.equal = function () { };
|
|
22
|
-
//# sourceMappingURL=
|
|
28
|
+
//# sourceMappingURL=is_type.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is_type.js","sourceRoot":"","sources":["../../ts/type-guard/is_type.ts"],"names":[],"mappings":"AAUA,MAAM,UAAU,MAAM,CAAC,OAAgB,EAAE,SAAmC;IAC3E,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;AAC/C,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,CAAC,GAAG,UAA0B,OAAW;IAC/C,OAAO,OAAO,KAAK,SAAS,IAAI,OAAO,KAAK,IAAI,CAAA;AACjD,CAAC,CAAA;AAED;;GAEG;AACH,MAAM,CAAC,CAAC,GAAG,UAA2B,OAAW;IAChD,OAAO,OAAO,KAAK,SAAS,IAAI,OAAO,KAAK,KAAK,CAAA;AAClD,CAAC,CAAA;AAYD,SAAS,OAAO,CAAC,OAAiB;IACjC,OAAO,IAAI,CAAA;AACZ,CAAC;AAED,MAAM,CAAC,KAAK,GAAG,OAAO,CAAA;AAEtB;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,GAAG,cAA4C,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "type-plus",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0",
|
|
4
4
|
"description": "Provides additional types for TypeScript.",
|
|
5
5
|
"homepage": "https://github.com/unional/type-plus",
|
|
6
6
|
"bugs": {
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
"test:watch": "cross-env NODE_OPTIONS=--experimental-vm-modules NODE_NO_WARNINGS=1 jest --watch",
|
|
92
92
|
"verify": "npm-run-all clean -p build depcheck lint coverage -p size",
|
|
93
93
|
"version": "changeset version",
|
|
94
|
-
"watch": "jest --watch",
|
|
95
|
-
"w": "jest --watch"
|
|
94
|
+
"watch": "cross-env NODE_OPTIONS=--experimental-vm-modules NODE_NO_WARNINGS=1 jest --watch",
|
|
95
|
+
"w": "cross-env NODE_OPTIONS=--experimental-vm-modules NODE_NO_WARNINGS=1 jest --watch"
|
|
96
96
|
}
|
|
97
97
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { IsStrictNumber } from '../number/strict_number_type.js'
|
|
2
|
+
import type { TupleType } from '../tuple/tuple_type.js'
|
|
1
3
|
import type { IndexAt } from './array_index.js'
|
|
2
4
|
|
|
3
5
|
/**
|
|
@@ -13,21 +15,14 @@ import type { IndexAt } from './array_index.js'
|
|
|
13
15
|
* type R = At<[1, 2, 3], -1> // 3
|
|
14
16
|
* ```
|
|
15
17
|
*/
|
|
16
|
-
export type At<A extends unknown[], N extends number, Fail = never> = IndexAt<
|
|
18
|
+
export type At<A extends unknown[], N extends number, Fail = never> = IndexAt<
|
|
19
|
+
A,
|
|
20
|
+
N,
|
|
21
|
+
Fail,
|
|
22
|
+
Fail,
|
|
23
|
+
Fail
|
|
24
|
+
> extends infer I
|
|
17
25
|
? I extends number
|
|
18
|
-
? A[I]
|
|
26
|
+
? TupleType<A, IsStrictNumber<I, A[I] | undefined, A[I]>, A[I] | undefined>
|
|
19
27
|
: Fail
|
|
20
28
|
: never
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Concats two arrays.
|
|
24
|
-
*
|
|
25
|
-
* alias of: `[...A, ...B]`
|
|
26
|
-
*
|
|
27
|
-
* @alias ArrayPlus.Concat
|
|
28
|
-
*
|
|
29
|
-
* ```ts
|
|
30
|
-
* type R = Concat<[1], [2, 3]> // [1, 2, 3]
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
export type Concat<A extends unknown[], B extends unknown[]> = [...A, ...B]
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { IsTuple } from '../tuple/tuple_type.js'
|
|
2
|
+
/**
|
|
3
|
+
* Returns an array of key-value pairs for every entry in the array or tuple.
|
|
4
|
+
*
|
|
5
|
+
* Note that this is not the same as `Array.entries(A)`,
|
|
6
|
+
* which returns an iterable interator.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* ArrayPlus.Entries<Array<string | number>> // Array<[number, string | number]>
|
|
11
|
+
* ArrayPlus.Entries<[1, 2, 3]> // [[0, 1], [1, 2], [2, 3]]
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export type Entries<A extends unknown[]> = IsTuple<
|
|
15
|
+
A,
|
|
16
|
+
Device<A, []>,
|
|
17
|
+
A extends Array<infer T> ? Array<[number, T]> : never
|
|
18
|
+
>
|
|
19
|
+
|
|
20
|
+
type Device<A extends unknown[], R extends unknown[]> = A['length'] extends 0
|
|
21
|
+
? R
|
|
22
|
+
: A extends [...infer F, infer N]
|
|
23
|
+
? Device<F, [[F['length'], N], ...R]>
|
|
24
|
+
: never
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { TupleType } from '../tuple/tuple_type.js'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns the first type in the array or tuple that matches the `Criteria`.
|
|
5
|
+
*
|
|
6
|
+
* If the `Criteria` is not met, it will return `never'.
|
|
7
|
+
*
|
|
8
|
+
* For `Array<T>`, it will return `T | undefined` if `T` satisfies `Criteria`.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* ArrayPlus.Find<Array<1 | 2 | 'x'>, number> // 1 | 2 | undefined
|
|
13
|
+
*
|
|
14
|
+
* ArrayPlus.Find<[true, 1, 'x', 3], string> // 'x'
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export type FindFirst<A extends unknown[], Criteria> = TupleType<
|
|
18
|
+
A,
|
|
19
|
+
A['length'] extends 0
|
|
20
|
+
? never
|
|
21
|
+
: A extends [infer Head, ...infer Tail]
|
|
22
|
+
? Head extends Criteria
|
|
23
|
+
? Head
|
|
24
|
+
: FindFirst<Tail, Criteria>
|
|
25
|
+
: never,
|
|
26
|
+
A extends Array<infer T> ? (T extends Criteria ? T | undefined : never) : never
|
|
27
|
+
>
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @deprecated use FindFirst
|
|
31
|
+
*/
|
|
32
|
+
export type First<A extends any[], Criteria> = FindFirst<A, Criteria>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { TupleType } from '../tuple/tuple_type.js'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns the last type in the array or tuple that matches the `Criteria`.
|
|
5
|
+
*
|
|
6
|
+
* If the `Criteria` is not met, it will return `never'.
|
|
7
|
+
*
|
|
8
|
+
* For `Array<T>`, it will return `T | undefined` if `T` satisfies `Criteria`.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* ArrayPlus.Find<Array<1 | 2 | 'x'>, number> // 1 | 2 | undefined
|
|
13
|
+
*
|
|
14
|
+
* ArrayPlus.Find<[true, 123, 'x', 321], number> // 321
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export type FindLast<A extends Array<any>, Criteria> = TupleType<
|
|
18
|
+
A,
|
|
19
|
+
A['length'] extends 0
|
|
20
|
+
? never
|
|
21
|
+
: A extends [...infer Heads, infer Last]
|
|
22
|
+
? Last extends Criteria
|
|
23
|
+
? Last
|
|
24
|
+
: FindLast<Heads, Criteria>
|
|
25
|
+
: never,
|
|
26
|
+
A extends Array<infer T> ? (T extends Criteria ? T | undefined : never) : never
|
|
27
|
+
>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Reverses the order of elements in the array or tuple.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* Reverse<Array<string | number>> // Array<string | number>
|
|
7
|
+
*
|
|
8
|
+
* Reverse<[1, 2, 3]> // [3, 2, 1]
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* @param T The array type to reverse.
|
|
12
|
+
* @returns The reversed array type.
|
|
13
|
+
*/
|
|
14
|
+
export type Reverse<A extends unknown[]> = A extends [infer First, ...infer Rest]
|
|
15
|
+
? [...Reverse<Rest>, First]
|
|
16
|
+
: A
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { IsEqual } from '../equal/equal.js'
|
|
2
|
+
import type { CanAssign } from '../index.js'
|
|
3
|
+
import type { Tail } from './tail.js'
|
|
4
|
+
import type { UnionOfValues } from './union_of_values.js'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Determines whether the array type `A` contains any elements that satisfies the specified `Criteria` type.
|
|
8
|
+
*
|
|
9
|
+
* It operates in `loose` mode by default,
|
|
10
|
+
* which means literal types satisfies their widened counterparts.
|
|
11
|
+
*
|
|
12
|
+
* You can also change it to `strict` mode.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* Some<string[], string> // true
|
|
17
|
+
* Some<['a', boolean], boolean> // true
|
|
18
|
+
* Some<['a', true], boolean> //true
|
|
19
|
+
*
|
|
20
|
+
* Some<['a', true], boolean, 'strict'> // false
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export type Some<
|
|
24
|
+
A extends any[],
|
|
25
|
+
Criteria,
|
|
26
|
+
Mode extends 'strict' | 'loose' = 'loose',
|
|
27
|
+
Then = true,
|
|
28
|
+
Else = false
|
|
29
|
+
> = Mode extends 'strict' ? Some.Strict<A, Criteria, Then, Else> : Some.Loose<A, Criteria, Then, Else>
|
|
30
|
+
|
|
31
|
+
export namespace Some {
|
|
32
|
+
export type Strict<A extends unknown[], Criteria, Then, Else> = number extends A['length']
|
|
33
|
+
? IsEqual<UnionOfValues<A>, Criteria> extends true
|
|
34
|
+
? Then
|
|
35
|
+
: Else
|
|
36
|
+
: StrictTuple<A, Criteria, Then, Else>
|
|
37
|
+
|
|
38
|
+
export type StrictTuple<A extends unknown[], Criteria, Then, Else> = A['length'] extends 0
|
|
39
|
+
? Else
|
|
40
|
+
: IsEqual<A[0], Criteria> extends true
|
|
41
|
+
? Then
|
|
42
|
+
: StrictTuple<Tail<A>, Criteria, Then, Else>
|
|
43
|
+
|
|
44
|
+
export type Loose<A extends unknown[], Criteria, Then, Else> = number extends A['length']
|
|
45
|
+
? CanAssign<UnionOfValues<A>, Criteria, Then, Else>
|
|
46
|
+
: LooseTuple<A, Criteria, Then, Else>
|
|
47
|
+
|
|
48
|
+
export type LooseTuple<A extends unknown[], Criteria, Then, Else> = A['length'] extends 0
|
|
49
|
+
? Else
|
|
50
|
+
: A[0] extends Criteria
|
|
51
|
+
? Then
|
|
52
|
+
: LooseTuple<Tail<A>, Criteria, Then, Else>
|
|
53
|
+
}
|
package/ts/array/array_index.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { IsAny } from '../any/any_type.js'
|
|
2
|
-
import type {
|
|
3
|
-
import type { Abs } from '../math/
|
|
4
|
-
import type { GreaterThan } from '../math/
|
|
5
|
-
import type { Subtract } from '../math/
|
|
2
|
+
import type { IsEqual } from '../equal/equal.js'
|
|
3
|
+
import type { Abs } from '../math/abs.js'
|
|
4
|
+
import type { GreaterThan } from '../math/greater_than.js'
|
|
5
|
+
import type { Subtract } from '../math/subtract.js'
|
|
6
6
|
import type { IsNever } from '../never/never_type.js'
|
|
7
|
-
import type { Integer } from '../number/integer.js'
|
|
8
|
-
import type { Negative } from '../number/negative.js'
|
|
9
7
|
import type { StrictNumberType } from '../number/strict_number_type.js'
|
|
8
|
+
import type { Integer } from '../numeric/integer.js'
|
|
9
|
+
import type { Negative } from '../numeric/negative.js'
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Gets the normalized index to access the element of an array or tuple.
|
|
@@ -19,7 +19,13 @@ import type { StrictNumberType } from '../number/strict_number_type.js'
|
|
|
19
19
|
* type R = IndexAt<['a', 'b', 'c'], -4> // never
|
|
20
20
|
* ```
|
|
21
21
|
*/
|
|
22
|
-
export type IndexAt<
|
|
22
|
+
export type IndexAt<
|
|
23
|
+
A extends Array<unknown>,
|
|
24
|
+
N extends number,
|
|
25
|
+
Fail = never,
|
|
26
|
+
Upper = A['length'],
|
|
27
|
+
Lower = 0
|
|
28
|
+
> = IsEqual<
|
|
23
29
|
A['length'],
|
|
24
30
|
0,
|
|
25
31
|
Fail,
|
|
@@ -32,8 +38,8 @@ export type IndexAt<A extends Array<unknown>, N extends number, Fail = never> =
|
|
|
32
38
|
// A: tuple
|
|
33
39
|
Negative<
|
|
34
40
|
N,
|
|
35
|
-
GreaterThan<Abs<N>, A['length']> extends true ?
|
|
36
|
-
GreaterThan<A['length'], N> extends true ? N :
|
|
41
|
+
GreaterThan<Abs<N>, A['length']> extends true ? Lower : Subtract<A['length'], Abs<N>>,
|
|
42
|
+
GreaterThan<A['length'], N> extends true ? N : Upper
|
|
37
43
|
>
|
|
38
44
|
>,
|
|
39
45
|
// N: number or float
|
|
@@ -61,7 +67,7 @@ export type IndexAt<A extends Array<unknown>, N extends number, Fail = never> =
|
|
|
61
67
|
* ```
|
|
62
68
|
*/
|
|
63
69
|
export type IsIndexOutOfBound<A extends unknown[], N extends number, Then = true, Else = false> = IsNever<
|
|
64
|
-
IndexAt<A, N>,
|
|
70
|
+
IndexAt<A, N, never, never, never>,
|
|
65
71
|
Then,
|
|
66
72
|
Else
|
|
67
73
|
>
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { IndexAt } from './array_index.js'
|
|
2
|
+
import { ArrayType } from './array_type.js'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Splits an array into two at the specified `Index`.
|
|
6
|
+
*
|
|
7
|
+
* If the `Index` is out of bounds,
|
|
8
|
+
* it will set to the boundary value, similar to `array.splice()`.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* SplitAt<[1, 2, 3, 4, 5], 0> // [[], [1, 2, 3, 4, 5]]
|
|
13
|
+
* SplitAt<[1, 2, 3, 4, 5], -5> // [[], [1, 2, 3, 4, 5]]
|
|
14
|
+
*
|
|
15
|
+
* SplitAt<[1, 2, 3, 4, 5], 2> // [[1, 2], [3, 4, 5]]
|
|
16
|
+
*
|
|
17
|
+
* SplitAt<[1, 2, 3, 4, 5], 4> // [[1, 2, 3, 4], [5]]
|
|
18
|
+
* SplitAt<[1, 2, 3, 4, 5], -1> // [[1, 2, 3, 4], [5]]
|
|
19
|
+
*
|
|
20
|
+
* SplitAt<[1, 2, 3, 4, 5], 5> // [[1, 2, 3, 4, 5], []]
|
|
21
|
+
*
|
|
22
|
+
* // out of bound resets to boundary
|
|
23
|
+
* SplitAt<[1, 2, 3, 4, 5], 6> // [[1, 2, 3, 4, 5], []]
|
|
24
|
+
* SplitAt<[1, 2, 3, 4, 5], -6> // [[], [1, 2, 3, 4, 5]]
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export type SplitAt<A extends unknown[], Index extends number> = ArrayType<
|
|
28
|
+
A,
|
|
29
|
+
[A, A],
|
|
30
|
+
ArraySplitAtDevice<A, [], IndexAt<A, Index>>
|
|
31
|
+
>
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Splits an array into two at the specified `Index`.
|
|
35
|
+
* The device does not work on negative index nor out of bound index.
|
|
36
|
+
*
|
|
37
|
+
* @internal
|
|
38
|
+
*/
|
|
39
|
+
export type ArraySplitAtDevice<
|
|
40
|
+
A extends unknown[],
|
|
41
|
+
B extends unknown[],
|
|
42
|
+
Index extends number
|
|
43
|
+
> = Index extends B['length']
|
|
44
|
+
? [B, A]
|
|
45
|
+
: A extends [infer Head, ...infer Tail]
|
|
46
|
+
? ArraySplitAtDevice<Tail, [...B, Head], Index>
|
|
47
|
+
: never
|
package/ts/array/array_plus.ts
CHANGED
|
@@ -1,2 +1,10 @@
|
|
|
1
|
-
export type { At
|
|
1
|
+
export type { At } from './array.at.js'
|
|
2
|
+
export type { Concat } from './array.concat.js'
|
|
3
|
+
export type { Entries } from './array.entries.js'
|
|
4
|
+
export type { FindFirst as Find } from './array.find.js'
|
|
5
|
+
export type { FindLast } from './array.find_last.js'
|
|
6
|
+
export type { Reverse } from './array.reverse.js'
|
|
7
|
+
export type { Some } from './array.some.js'
|
|
2
8
|
export type { IndexAt, IsIndexOutOfBound } from './array_index.js'
|
|
9
|
+
export type { SplitAt } from './array_plus.split_at.js'
|
|
10
|
+
export type { PadStart } from './pad_start.js'
|
package/ts/array/drop.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { IsEqual } from '../equal/equal.js'
|
|
2
2
|
import type { NonNull, NonUndefined } from '../utils/index.js'
|
|
3
3
|
|
|
4
4
|
export type DropFirst<A extends any[]> = number extends A['length']
|
|
@@ -21,7 +21,7 @@ export type DropLast<A extends any[]> = number extends A['length']
|
|
|
21
21
|
? Heads
|
|
22
22
|
: never
|
|
23
23
|
|
|
24
|
-
type ExcludeUnionOfEmptyTuple<A> =
|
|
24
|
+
type ExcludeUnionOfEmptyTuple<A> = IsEqual<A, []> extends true ? A : Exclude<A, []>
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* drops entries matching `Criteria` in array or tuple `A`.
|
package/ts/array/index.ts
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
export * from './common_prop_keys.js'
|
|
2
|
-
export * from './create_tuple.js'
|
|
3
2
|
export * from './drop.js'
|
|
4
3
|
export * from './filter.js'
|
|
5
|
-
export * from './
|
|
6
|
-
export * from './find_last.js'
|
|
4
|
+
export * from './array.find.js'
|
|
5
|
+
export * from './array.find_last.js'
|
|
7
6
|
export * from './head.js'
|
|
8
7
|
export * from './intersect_of_props.js'
|
|
9
8
|
export * from './last.js'
|
|
10
9
|
export * from './literal_array.js'
|
|
11
|
-
export * from './
|
|
10
|
+
export * from './pad_start.js'
|
|
12
11
|
export * from './reduce_while.js'
|
|
13
12
|
export * from './reverse.js'
|
|
14
|
-
export * from './some.js'
|
|
13
|
+
export * from './array.some.js'
|
|
15
14
|
export * from './tail.js'
|
|
16
15
|
export * from './union_of_props.js'
|
|
17
16
|
export * from './union_of_values.js'
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { CanAssign } from '../index.js'
|
|
2
|
+
import type { CreateTuple } from '../tuple/create_tuple.js'
|
|
3
|
+
import type { PadStart as TuplePadStart } from '../tuple/tuple_plus.pad_start.js'
|
|
4
|
+
import type { UnionOfValues } from './union_of_values.js'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Pads the start of an array or tuple with `PadWith`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* // Padding array
|
|
12
|
+
* PadStart<number[], 1, string> // [string, ...number[]]
|
|
13
|
+
*
|
|
14
|
+
* // Ignore if the type is compatible
|
|
15
|
+
* PadStart<number[], 2, number> // number[]
|
|
16
|
+
* PadStart<number[], 3, 1> // number[]
|
|
17
|
+
*
|
|
18
|
+
* // Padding tuple
|
|
19
|
+
* PadStart<[1, 2, 3], 5, 0> // [0, 0, 1, 2, 3]
|
|
20
|
+
*
|
|
21
|
+
* // Ignore if MaxLength is less than the length of the tuple
|
|
22
|
+
* PadStart<[1, 2, 3], 5, 0> // [0, 0, 1, 2, 3]
|
|
23
|
+
*
|
|
24
|
+
* // Default to unknown
|
|
25
|
+
* PadStart<[1, 2, 3], 5> // [unknown, unknown, 1, 2, 3]
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export type PadStart<
|
|
29
|
+
A extends unknown[],
|
|
30
|
+
MaxLength extends number,
|
|
31
|
+
PadWith = unknown
|
|
32
|
+
> = number extends A['length']
|
|
33
|
+
? MaxLength extends 0
|
|
34
|
+
? A
|
|
35
|
+
: CanAssign<PadWith, UnionOfValues<A>> extends true
|
|
36
|
+
? A
|
|
37
|
+
: PadStart<[...CreateTuple<MaxLength, PadWith>, ...A], MaxLength, PadWith>
|
|
38
|
+
: TuplePadStart<A, MaxLength, PadWith>
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @deprecated use PadStart instead
|
|
42
|
+
*/
|
|
43
|
+
export type PadLeft<A extends any[], Total extends number, PadWith = any> = PadStart<A, Total, PadWith>
|
package/ts/array/readme.md
CHANGED
|
@@ -19,10 +19,190 @@ type R = ArrayType<number[] | 1> // never
|
|
|
19
19
|
type R = ArrayType<number[] & { a: 1 }> // never
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
- [`ArrayType<T, Then = T, Else = never>`](array_type.ts#L15): check if `T` is
|
|
23
|
-
- [`IsArray<T, Then = true, Else = false`](array_type.ts#L33): is `T`
|
|
24
|
-
- [`NotArrayType<T, Then = T, Else = never>`](array_type.ts#L47): check if `T` is not
|
|
25
|
-
- [`IsNotArray<T, Then = true, Else = false>`](array_type.ts#L61): is `T` not
|
|
22
|
+
- [`ArrayType<T, Then = T, Else = never>`](array_type.ts#L15): check if `T` is an array and not a tuple.
|
|
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).
|
|
26
|
+
|
|
27
|
+
## ArrayPlus
|
|
28
|
+
|
|
29
|
+
`ArrayPlus` contains all types and type utilities related to array.
|
|
30
|
+
Whenever possible, these types and type utilities also work with *tuples*,
|
|
31
|
+
as *tuples* is a subset of array.
|
|
32
|
+
|
|
33
|
+
For *tuple* specific types and type utilities,
|
|
34
|
+
please check [`TuplePlus`](../tuple/readme.md#TuplePlus).
|
|
35
|
+
|
|
36
|
+
### [`ArrayPlus.At`](./array.at.ts#L18)
|
|
37
|
+
|
|
38
|
+
> `ArrayPlus.At<A, N, Fail = never>`
|
|
39
|
+
|
|
40
|
+
Gets the type of the array or tuple `A` at index `N`.
|
|
41
|
+
|
|
42
|
+
For array, it will return the union of the type of the array value and `undefined`,
|
|
43
|
+
as there is no way to guarantee the array has value at `N`.
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
type A = Array<string | number>
|
|
47
|
+
|
|
48
|
+
ArrayPlus.At<A, 0> // string | number | undefined
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
For tuple, it will return the type of the tuple value at index `N`.
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
type T = [number, string, 1, 2, 3]
|
|
55
|
+
|
|
56
|
+
ArrayPlus.At<T, 0> // number
|
|
57
|
+
ArrayPlus.At<T, -1> // 3
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
If the `N` is out of bound,
|
|
61
|
+
or `N` is not a valid index,
|
|
62
|
+
`ArrayPlus.At` will return the `Fail` case, which defaults to `never`.
|
|
63
|
+
|
|
64
|
+
### [`ArrayPlus.Concat`](./array.concat.ts#L12)
|
|
65
|
+
|
|
66
|
+
> `ArrayPlus.Concat<A, B>`
|
|
67
|
+
|
|
68
|
+
Concats two arrays or tuples.
|
|
69
|
+
|
|
70
|
+
It is just an alias of `[...A, ...B]`.
|
|
71
|
+
It is added for completeness.
|
|
72
|
+
|
|
73
|
+
You are encouraged to use `[...A, ...B]` directly.
|
|
74
|
+
|
|
75
|
+
### [`ArrayPlus.Entries`](./array.entries.ts#L14)
|
|
76
|
+
|
|
77
|
+
> `ArrayPlus.Entries<A>`
|
|
78
|
+
|
|
79
|
+
Returns an array of key-value pairs for every entry in the array or tuple.
|
|
80
|
+
|
|
81
|
+
Note that this is not the same as `Array.entries(A)`,
|
|
82
|
+
which returns an iterable interator.
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
ArrayPlus.Entries<Array<string | number>> // Array<[number, string | number]>
|
|
86
|
+
ArrayPlus.Entries<[1, 2, 3]> // [[0, 1], [1, 2], [2, 3]]
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### [`ArrayPlus.Find`](./array.find.ts#L17)
|
|
90
|
+
|
|
91
|
+
> `ArrayPlus.Find<A, Criteria>
|
|
92
|
+
|
|
93
|
+
Returns the first type in the array or tuple that matches the `Criteria`.
|
|
94
|
+
|
|
95
|
+
If the `Criteria` is not met, it will return `never'.
|
|
96
|
+
|
|
97
|
+
For `Array<T>`, it will return `T | undefined` if `T` satisfies `Criteria`.
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
ArrayPlus.Find<Array<1 | 2 | 'x'>, number> // 1 | 2 | undefined
|
|
101
|
+
|
|
102
|
+
ArrayPlus.Find<[true, 1, 'x', 3], string> // 'x'
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### [`ArrayPlus.FindLast`](./array.find_last.ts#L17)
|
|
106
|
+
|
|
107
|
+
> `ArrayPlus.FindLast<A, Criteria>
|
|
108
|
+
|
|
109
|
+
Returns the last type in the array or tuple that matches the `Criteria`.
|
|
110
|
+
|
|
111
|
+
If the `Criteria` is not met, it will return `never'.
|
|
112
|
+
|
|
113
|
+
For `Array<T>`, it will return `T | undefined` if `T` satisfies `Criteria`.
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
ArrayPlus.FindLast<Array<1 | 2 | 'x'>, number> // 1 | 2 | undefined
|
|
117
|
+
|
|
118
|
+
ArrayPlus.FindLast<[true, 123, 'x', 321], number> // 321
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### [`ArrayPlus.Reverse`](./array.reverse.ts#L14)
|
|
122
|
+
|
|
123
|
+
> `ArrayPlus.Reverse<A>`
|
|
124
|
+
|
|
125
|
+
Reverses the order of the array or tuple.
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
ArrayPlus.Reverse<[1, 2, 3]> // [3, 2, 1]
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### [`ArrayPlus.SplitAt`](./array_plus.split_at.ts#L22)
|
|
132
|
+
|
|
133
|
+
> `ArrayPlus.SplitAt<A, Index>`
|
|
134
|
+
|
|
135
|
+
Splits the array or tuple at `Index`.
|
|
136
|
+
|
|
137
|
+
```ts
|
|
138
|
+
ArrayPlus.SplitAt<[1, 2, 3], 1> // [[1, 2], [3]]
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### [`ArrayPlus.Some`](./array.some.ts#L23)
|
|
142
|
+
|
|
143
|
+
> `ArrayPlus.Some<A, Criteria, Mode, Then, Else>`
|
|
144
|
+
|
|
145
|
+
Determines whether the array type `A` contains any elements that satisfies the specified `Criteria` type.
|
|
146
|
+
|
|
147
|
+
It operates in `loose` mode by default,
|
|
148
|
+
which means literal types satisfies their widened counterparts.
|
|
149
|
+
You can also change it to `strict` mode.
|
|
150
|
+
|
|
151
|
+
```ts
|
|
152
|
+
Some<string[], string> // true
|
|
153
|
+
Some<['a', boolean], boolean> // true
|
|
154
|
+
Some<['a', true], boolean> //true
|
|
155
|
+
|
|
156
|
+
Some<['a', true], boolean, 'strict'> // false
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## Builtin array methods
|
|
160
|
+
|
|
161
|
+
JavaScript has many builtin array methods.
|
|
162
|
+
We will try to bring them to the type-level.
|
|
163
|
+
|
|
164
|
+
Not all methods can be implemented in the type-level,
|
|
165
|
+
or in the same way.
|
|
166
|
+
|
|
167
|
+
For example, type-level does not support higher-level generics,
|
|
168
|
+
i.e. it is not possible to pass in a generic type and "invoke" it.
|
|
169
|
+
|
|
170
|
+
Therefore, methods like `map` and `reduce()` cannot be implemented generically.
|
|
171
|
+
They have to be implemented separately for each specific use case,
|
|
172
|
+
or with reduced capability.
|
|
173
|
+
|
|
174
|
+
They are exposed under the `ArrayPlus` namespace,
|
|
175
|
+
while some common ones are exposed at top-level.
|
|
176
|
+
|
|
177
|
+
Here are the list of array methods and their corresponding type-level functions, if availableL
|
|
178
|
+
|
|
179
|
+
- ✅ `at`: [`ArrayPlus.At`](#arrayplusat)
|
|
180
|
+
- ✅ `concat`: [`Concat` | `ArrayPlus.Concat`](#arrayplusconcat) (`[...A, ...B]`)
|
|
181
|
+
- 🚧 `copyWithin`: `CopyWithin<A, Target, Start, End>`
|
|
182
|
+
- ✴️ `entries`: [`ArrayPlus.Entries`](#arrayplusentries)
|
|
183
|
+
- 🚧 `every`: `Every<A, Criteria, Then = A, Else = never>`
|
|
184
|
+
- 🚧 `fill`: `Fill<A, V, Start, End>`
|
|
185
|
+
- ✴️ `find`: [`FindFirst` | `ArrayPlus.Find`](#arrayplusfind)
|
|
186
|
+
- ✴️ [`FindLast` | `ArrayPlus.FindLast`](#arrayplusfindlast)
|
|
187
|
+
- 🚧 `findIndex`: `FindIndex<A, Criteria> => number | number literal | never`
|
|
188
|
+
- 🚧 `flat`: `Flat<A>`
|
|
189
|
+
- 🚧 `flatMap`: `Flat<A, Criteria, R>`
|
|
190
|
+
- 🚧 `includes`:
|
|
191
|
+
- 🚧 `join`:
|
|
192
|
+
- 🚧 `keys`: `Range<0, T['length']>`?
|
|
193
|
+
- 🚧 `map`: `Map<A, Criteria, R>`
|
|
194
|
+
- 🚧 `pop`: `Pop<A>`
|
|
195
|
+
- 🧬 `push`: `[...A, T]`
|
|
196
|
+
- 🚧 `reduce`:
|
|
197
|
+
- 🚧 `reduceRight`:
|
|
198
|
+
- ✅ `reverse`: [`ArrayPlus.Reverse`](#arrayplusreverse)
|
|
199
|
+
- 🚧 `shift`:
|
|
200
|
+
- 🚧 `slice`:
|
|
201
|
+
- ✴️ `some`: [`Some` | `ArrayPlus.Some`](#arrayplussome)
|
|
202
|
+
- 🚧 `sort`:
|
|
203
|
+
- 🚧 `splice`:
|
|
204
|
+
- 🧬 `unshift`: `[T, ...A]`
|
|
205
|
+
- 🧬 `values`: `keyof A`
|
|
26
206
|
|
|
27
207
|
## References
|
|
28
208
|
|
|
@@ -8,6 +8,9 @@ import { AnyFunction } from '../function/any_function.js'
|
|
|
8
8
|
*/
|
|
9
9
|
export function assertType<T>(subject: T): asserts subject is T
|
|
10
10
|
export function assertType<T>(subject: unknown, validator: (s: T) => boolean): asserts subject is T
|
|
11
|
+
/**
|
|
12
|
+
* @deprecated this is not a failsafe test
|
|
13
|
+
*/
|
|
11
14
|
export function assertType<T extends new (...args: any) => any>(
|
|
12
15
|
subject: unknown,
|
|
13
16
|
constructor: T
|
|
@@ -78,6 +81,9 @@ assertType.noFunction = function <S>(subject: Exclude<S, AnyFunction>): void {
|
|
|
78
81
|
if (typeof subject === 'function') throw TypeError(`subject is function`)
|
|
79
82
|
}
|
|
80
83
|
|
|
84
|
+
/**
|
|
85
|
+
* @deprecated
|
|
86
|
+
*/
|
|
81
87
|
assertType.isConstructor = function (subject: AnyConstructor): asserts subject is AnyConstructor {
|
|
82
88
|
if (!isConstructor(subject)) throw TypeError(`subject is not a constructor`)
|
|
83
89
|
}
|