type-plus 6.8.1 → 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 +1054 -355
- 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/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/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 +1 -1
- 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/test_type.ts +131 -88
- package/ts/tuple/create_tuple.ts +42 -0
- 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
package/ts/nominal/brand.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// By Drew Colthorp, <https://spin.atomicobject.com/2018/01/15/typescript-flexible-nominal-typing/#comment-604580>
|
|
2
2
|
// <https://gist.github.com/dcolthorp/aa21cf87d847ae9942106435bf47565d>
|
|
3
3
|
|
|
4
|
-
import { isType } from '../
|
|
4
|
+
import { isType } from '../type-guard/is_type.js'
|
|
5
5
|
import type { Widen } from '../utils/index.js'
|
|
6
6
|
import { typeSym, valueSym } from './constants.js'
|
|
7
7
|
|
package/ts/nominal/flavor.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// By Drew Colthorp, <https://spin.atomicobject.com/2018/01/15/typescript-flexible-nominal-typing/#comment-604580>
|
|
2
2
|
// <https://gist.github.com/dcolthorp/aa21cf87d847ae9942106435bf47565d>
|
|
3
3
|
|
|
4
|
-
import { isType } from '../
|
|
4
|
+
import { isType } from '../type-guard/is_type.js'
|
|
5
5
|
import type { Widen } from '../utils/index.js'
|
|
6
6
|
import { typeSym, valueSym } from './constants.js'
|
|
7
7
|
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cast a string to a number literal type if possible.
|
|
3
|
+
*
|
|
4
|
+
* ```ts
|
|
5
|
+
* StringToNumber<'1'> // 1
|
|
6
|
+
* StringToNumber<'-1'> // -1
|
|
7
|
+
* ```
|
|
8
|
+
*/
|
|
9
|
+
export type StringToNumber<S extends string, Fail = never> = S extends `-0`
|
|
10
|
+
? 0
|
|
11
|
+
: S extends `${infer W}.0`
|
|
12
|
+
? StringToNumber<W>
|
|
13
|
+
: S extends `${infer W}.${infer F}0`
|
|
14
|
+
? StringToNumber<`${W}.${F}`>
|
|
15
|
+
: S extends `${infer N extends number}`
|
|
16
|
+
? N
|
|
17
|
+
: Fail
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import type { Add, IsStrictNumber } from '../index.js'
|
|
1
|
+
// import type { Add, IsStrictNumber } from '../index.js'
|
|
2
2
|
|
|
3
|
-
export type Sum<A extends number[], Fail = never> = IsStrictNumber<
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
>
|
|
3
|
+
// export type Sum<A extends number[], Fail = never> = IsStrictNumber<
|
|
4
|
+
// A['length'],
|
|
5
|
+
// Fail,
|
|
6
|
+
// A['length'] extends 0
|
|
7
|
+
// ? 0
|
|
8
|
+
// : A['length'] extends 1
|
|
9
|
+
// ? A[0]
|
|
10
|
+
// : A['length'] extends 2
|
|
11
|
+
// ? Add<A[0], A[1]>
|
|
12
|
+
// : A extends [infer F extends number, infer S extends number, ...infer Tail extends number[]]
|
|
13
|
+
// ? Sum<[Add<F, S>, ...Tail]>
|
|
14
|
+
// : never
|
|
15
|
+
// >
|
package/ts/number/number_plus.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
export type { Integer, IsInteger, IsNotInteger, IsWhole, NotInteger } from '
|
|
2
|
-
export type { IsNegative, IsNotNegative, Negative, NotNegative } from '
|
|
3
|
-
export type { Sum } from './number_array.js'
|
|
4
|
-
export type { IsNotNumber, IsNumber, NotNumberType, NumberType } from './number_type.js'
|
|
1
|
+
export type { Integer, IsInteger, IsNotInteger, IsWhole, NotInteger } from '../numeric/integer.js'
|
|
2
|
+
export type { IsNegative, IsNotNegative, Negative, NotNegative } from '../numeric/negative.js'
|
|
5
3
|
export type {
|
|
6
4
|
IsNotNumeric,
|
|
7
5
|
IsNumeric,
|
|
@@ -9,8 +7,10 @@ export type {
|
|
|
9
7
|
Numeric,
|
|
10
8
|
NumericType,
|
|
11
9
|
Zero
|
|
12
|
-
} from '
|
|
13
|
-
export type { IsNotPositive, IsPositive, NonPositive, Positive } from '
|
|
10
|
+
} from '../numeric/numeric_type.js'
|
|
11
|
+
export type { IsNotPositive, IsPositive, NonPositive, Positive } from '../numeric/positive.js'
|
|
12
|
+
// export type { Sum } from './number_array.js'
|
|
13
|
+
export type { IsNotNumber, IsNumber, NotNumberType, NumberType } from './number_type.js'
|
|
14
14
|
export type {
|
|
15
15
|
IsNotStrictNumber,
|
|
16
16
|
IsStrictNumber,
|
package/ts/number/readme.md
CHANGED
|
@@ -40,114 +40,6 @@ type R = StrictNumberType<unknown> // never
|
|
|
40
40
|
- [`NotStrictNumberType<T, Then = T, Else = never>`](strict_number_type.ts#L50): check if `T` is not `number`.
|
|
41
41
|
- [`IsNotStrictNumber<T, Then = true, Else = false>`](strict_number_type.ts#L65): is `T` not `number`.
|
|
42
42
|
|
|
43
|
-
---
|
|
44
|
-
|
|
45
|
-
`Numeric` type is either `number` or `bigint`.
|
|
46
|
-
|
|
47
|
-
The `NumericType<T>` and friends are used to check if `T` is `number` or `bigint`.
|
|
48
|
-
|
|
49
|
-
```ts
|
|
50
|
-
import type { NumericType } from 'type-plus'
|
|
51
|
-
|
|
52
|
-
type R = NumericType<number> // number
|
|
53
|
-
type R = NumericType<bigint> // bigint
|
|
54
|
-
type R = NumericType<1> // 1
|
|
55
|
-
type R = NumericType<1n> // 1n
|
|
56
|
-
|
|
57
|
-
type R = NumericType<never> // never
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
- [`NumericType<T, Then = T, Else = never>`](numeric_type.ts#L27): check if `T` is `number` or `bigint`.
|
|
61
|
-
- [`IsNumeric<T, Then = true, Else = false>`](numeric_type.ts#L42): is `T` `number` or `bigint`.
|
|
62
|
-
- [`NotNumericType<T, Then = T, Else = never>`](numeric_type.ts#L57): check if `T` is not `number` nor `bigint`.
|
|
63
|
-
- [`IsNotNumeric<T, Then = true, Else = false>`](numeric_type.ts#L72): is `T` not `number` nor `bigint`.
|
|
64
|
-
|
|
65
|
-
---
|
|
66
|
-
|
|
67
|
-
`Integer<T>` and friends are used to check if `T` is an integer.
|
|
68
|
-
|
|
69
|
-
```ts
|
|
70
|
-
import type { Integer } from 'type-plus'
|
|
71
|
-
|
|
72
|
-
type R = Integer<1> // 1
|
|
73
|
-
type R = Integer<1.0> // 1.0
|
|
74
|
-
|
|
75
|
-
type R = Integer<1.1> // never
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
- [`Integer<T, Then = T, Else = never>`](integer.ts#L17): check if `T` is an integer.
|
|
79
|
-
- [`IsInteger<T, Then = true, Else = false>`](integer.ts#L36): is `T` an integer.
|
|
80
|
-
- [`NotIntegerType<T, Then = T, Else = never>`](integer.ts#L51): check if `T` is not an integer.
|
|
81
|
-
- [`IsNotInteger<T, Then = true, Else = false>`](integer.ts#L66): is `T` not an integer.
|
|
82
|
-
- [`IsWhole<T, Then = true, Else = false>`](integer.ts#L81): same as `Integer<T>`, will be deprecated in the future.
|
|
83
|
-
|
|
84
|
-
---
|
|
85
|
-
|
|
86
|
-
`Positive<T>` and friends are used to check if `T` is a positive numeric value.
|
|
87
|
-
|
|
88
|
-
The `number` and `bigint` can be considered as a union of all positive and negative numeric literals.
|
|
89
|
-
|
|
90
|
-
That is why `IsPositive<T>` will yield `boolean` as the union is distributive.
|
|
91
|
-
`Positive<T>` returns `T` for `number` and `bigint` for the same reason.
|
|
92
|
-
It is a bit confusing but it is correct as it really returns `T | never`,
|
|
93
|
-
which resolves to `T`.
|
|
94
|
-
|
|
95
|
-
This behavior is different than `TrueType<T>` which `TrueType<boolean>` returns `never`.
|
|
96
|
-
|
|
97
|
-
This is because `TrueType<T>` is checking for the exect `true` type,
|
|
98
|
-
while `Positive<T>` is checking for a criteria of types (i.e. a set).
|
|
99
|
-
|
|
100
|
-
```ts
|
|
101
|
-
import type { Positive } from 'type-plus'
|
|
102
|
-
|
|
103
|
-
type R = Positive<1> // 1
|
|
104
|
-
type R = Positive<1.0> // 1.0
|
|
105
|
-
type R = Positive<1n> // 1n
|
|
106
|
-
|
|
107
|
-
type R = Positive<-1> // never
|
|
108
|
-
type R = Positive<'1'> // never
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
- [`Positive<T, Then = T, Else = never>`](positive.ts#L17): check if `T` is a positive numeric value.
|
|
112
|
-
- [`IsPositive<T, Then = true, Else = false>`](positive.ts#L40): is `T` a positive numeric value.
|
|
113
|
-
- [`NotPositiveType<T, Then = T, Else = never>`](positive.ts#L54): check if `T` is not a positive numeric value.
|
|
114
|
-
- [`IsNotPositive<T, Then = true, Else = false>`](positive.ts#L68): is `T` not a positive numeric value.
|
|
115
|
-
|
|
116
|
-
---
|
|
117
|
-
|
|
118
|
-
`Negative<T>` and friends are used to check if `T` is a negative numeric value.
|
|
119
|
-
|
|
120
|
-
The `number` and `bigint` can be considered as a union of all negative and negative numeric literals.
|
|
121
|
-
|
|
122
|
-
That is why `IsNegative<T>` will yield `boolean` as the union is distributive.
|
|
123
|
-
`Negative<T>` returns `T` for `number` and `bigint` for the same reason.
|
|
124
|
-
It is a bit confusing but it is correct as it really returns `T | never`,
|
|
125
|
-
which resolves to `T`.
|
|
126
|
-
|
|
127
|
-
This behavior is different than `TrueType<T>` which `TrueType<boolean>` returns `never`.
|
|
128
|
-
|
|
129
|
-
This is because `TrueType<T>` is checking for the exect `true` type,
|
|
130
|
-
while `Negative<T>` is checking for a criteria of types (i.e. a set).
|
|
131
|
-
|
|
132
|
-
```ts
|
|
133
|
-
import type { Negative } from 'type-plus'
|
|
134
|
-
|
|
135
|
-
type R = Negative<1> // never
|
|
136
|
-
type R = Negative<1.0> // never
|
|
137
|
-
type R = Negative<1n> // never
|
|
138
|
-
|
|
139
|
-
type R = Negative<number> // number
|
|
140
|
-
type R = Negative<any> // any
|
|
141
|
-
|
|
142
|
-
type R = Negative<-1> // -1
|
|
143
|
-
type R = Negative<'1'> // '1'
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
- [`Negative<T, Then = T, Else = never>`](negative.ts#L21): check if `T` is a negative numeric value.
|
|
147
|
-
- [`IsNegative<T, Then = true, Else = false>`](negative.ts#L57): is `T` a negative numeric value.
|
|
148
|
-
- [`NotNegativeType<T, Then = T, Else = never>`](negative.ts#L75): check if `T` is not a negative numeric value.
|
|
149
|
-
- [`IsNotNegative<T, Then = true, Else = false>`](negative.ts#L109): is `T` not a negative numeric value.
|
|
150
|
-
|
|
151
43
|
## References
|
|
152
44
|
|
|
153
45
|
- [Handbook]
|
|
@@ -3,6 +3,11 @@ import type { IsAny } from '../any/any_type.js'
|
|
|
3
3
|
/**
|
|
4
4
|
* Check if the type `T` is exactly the type `number` and not numeric literals.
|
|
5
5
|
*
|
|
6
|
+
* Note that if `T` is guaranteed to be a `number`, e.g. `SomeArray['length']`,
|
|
7
|
+
*
|
|
8
|
+
* A simple `number extends SomeArray['length'] ? Then, Else` is sufficient.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
6
11
|
* ```ts
|
|
7
12
|
* type R = StrictNumberType<number> // true
|
|
8
13
|
* type R = StrictNumberType<1> // false
|
|
@@ -20,6 +25,11 @@ export type StrictNumberType<T, Then = T, Else = never> = IsAny<
|
|
|
20
25
|
/**
|
|
21
26
|
* Is the type `T` exactly the type `number` and not numeric literals.
|
|
22
27
|
*
|
|
28
|
+
* Note that if `T` is guaranteed to be a `number`, e.g. `SomeArray['length']`,
|
|
29
|
+
*
|
|
30
|
+
* A simple `number extends SomeArray['length'] ? Then, Else` is sufficient.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
23
33
|
* ```ts
|
|
24
34
|
* type R = IsStrictNumber<number> // true
|
|
25
35
|
* type R = IsStrictNumber<1> // false
|
|
@@ -33,6 +43,7 @@ export type IsStrictNumber<T, Then = true, Else = false> = StrictNumberType<T, T
|
|
|
33
43
|
/**
|
|
34
44
|
* Check if the type `T` is not the type `number` or numeric literals.
|
|
35
45
|
*
|
|
46
|
+
* @example
|
|
36
47
|
* ```ts
|
|
37
48
|
* type R = NotStrictNumberType<number> // false
|
|
38
49
|
* type R = NotStrictNumberType<1> // true
|
|
@@ -46,6 +57,7 @@ export type NotStrictNumberType<T, Then = T, Else = never> = StrictNumberType<T,
|
|
|
46
57
|
/**
|
|
47
58
|
* Is the type `T` not the type `number` or numeric literals.
|
|
48
59
|
*
|
|
60
|
+
* @example
|
|
49
61
|
* ```ts
|
|
50
62
|
* type R = IsNotStrictNumber<number> // false
|
|
51
63
|
* type R = IsNotStrictNumber<1> // true
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { StringToBigint } from '../bigint/cast.js'
|
|
2
|
+
import type { StringToNumber } from '../number/cast.js'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Cast a string to a numeric literal type (number or bigint) if possible.
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* StringToNumeric<'1'> // 1
|
|
9
|
+
* StringToNumeric<'1n'> // 1n
|
|
10
|
+
* StringToNumeric<'-1'> // -1
|
|
11
|
+
* StringToNumeric<'-1n'> // -1n
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export type StringToNumeric<S extends string, Fail = never> = StringToBigint<S, StringToNumber<S, Fail>>
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Cast a numeric literal type (number or bigint) to string.
|
|
18
|
+
*
|
|
19
|
+
* ```ts
|
|
20
|
+
* NumericToString<1> // '1'
|
|
21
|
+
* NumericToString<1.23> // '1.23'
|
|
22
|
+
* NumericToString<0.00123> // '0.00123'
|
|
23
|
+
* NumericToString<1n> // '1n'
|
|
24
|
+
* NumericToString<-1> // '-1'
|
|
25
|
+
* NumericToString<-1n> // '-1n'
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export type NumericToString<N extends number | bigint> = N extends number ? `${N}` : `${N}n`
|
|
@@ -62,6 +62,8 @@ export type IsNotInteger<T, Then = true, Else = false> = NotInteger<T, Else, The
|
|
|
62
62
|
/**
|
|
63
63
|
* Check if T is an integer, including bigint.
|
|
64
64
|
*
|
|
65
|
+
* @deprecated use `IsInteger` instead
|
|
66
|
+
*
|
|
65
67
|
* ```ts
|
|
66
68
|
* type R = IsWhole<0> // 0
|
|
67
69
|
* type R = IsWhole<1n> // 1n
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type { Integer, IsInteger, IsNotInteger, IsWhole, NotInteger } from './integer.js'
|
|
2
|
+
export type { IsNegative, IsNotNegative, Negative, NotNegative } from './negative.js'
|
|
3
|
+
export type {
|
|
4
|
+
IsNotNumeric,
|
|
5
|
+
IsNumeric,
|
|
6
|
+
NotNumericType,
|
|
7
|
+
Numeric,
|
|
8
|
+
NumericType,
|
|
9
|
+
Zero
|
|
10
|
+
} from './numeric_type.js'
|
|
11
|
+
export type { IsNotPositive, IsPositive, NonPositive, Positive } from './positive.js'
|
|
12
|
+
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# number
|
|
2
|
+
|
|
3
|
+
## Type Checking
|
|
4
|
+
|
|
5
|
+
`Numeric` type is either `number` or `bigint`.
|
|
6
|
+
|
|
7
|
+
The `NumericType<T>` and friends are used to check if `T` is `number` or `bigint`.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import type { NumericType } from 'type-plus'
|
|
11
|
+
|
|
12
|
+
type R = NumericType<number> // number
|
|
13
|
+
type R = NumericType<bigint> // bigint
|
|
14
|
+
type R = NumericType<1> // 1
|
|
15
|
+
type R = NumericType<1n> // 1n
|
|
16
|
+
|
|
17
|
+
type R = NumericType<never> // never
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
- [`NumericType<T, Then = T, Else = never>`](numeric_type.ts#L27): check if `T` is `number` or `bigint`.
|
|
21
|
+
- [`IsNumeric<T, Then = true, Else = false>`](numeric_type.ts#L42): is `T` `number` or `bigint`.
|
|
22
|
+
- [`NotNumericType<T, Then = T, Else = never>`](numeric_type.ts#L57): check if `T` is not `number` nor `bigint`.
|
|
23
|
+
- [`IsNotNumeric<T, Then = true, Else = false>`](numeric_type.ts#L72): is `T` not `number` nor `bigint`.
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
`Integer<T>` and friends are used to check if `T` is an integer.
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import type { Integer } from 'type-plus'
|
|
31
|
+
|
|
32
|
+
type R = Integer<1> // 1
|
|
33
|
+
type R = Integer<1.0> // 1.0
|
|
34
|
+
|
|
35
|
+
type R = Integer<1.1> // never
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
- [`Integer<T, Then = T, Else = never>`](integer.ts#L17): check if `T` is an integer.
|
|
39
|
+
- [`IsInteger<T, Then = true, Else = false>`](integer.ts#L36): is `T` an integer.
|
|
40
|
+
- [`NotIntegerType<T, Then = T, Else = never>`](integer.ts#L51): check if `T` is not an integer.
|
|
41
|
+
- [`IsNotInteger<T, Then = true, Else = false>`](integer.ts#L66): is `T` not an integer.
|
|
42
|
+
- [`IsWhole<T, Then = true, Else = false>`](integer.ts#L81): same as `Integer<T>`, will be deprecated in the future.
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
`Positive<T>` and friends are used to check if `T` is a positive numeric value.
|
|
47
|
+
|
|
48
|
+
The `number` and `bigint` can be considered as a union of all positive and negative numeric literals.
|
|
49
|
+
|
|
50
|
+
That is why `IsPositive<T>` will yield `boolean` as the union is distributive.
|
|
51
|
+
`Positive<T>` returns `T` for `number` and `bigint` for the same reason.
|
|
52
|
+
It is a bit confusing but it is correct as it really returns `T | never`,
|
|
53
|
+
which resolves to `T`.
|
|
54
|
+
|
|
55
|
+
This behavior is different than `TrueType<T>` which `TrueType<boolean>` returns `never`.
|
|
56
|
+
|
|
57
|
+
This is because `TrueType<T>` is checking for the exact `true` type,
|
|
58
|
+
while `Positive<T>` is checking for a criteria of types (i.e. a set).
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
import type { Positive } from 'type-plus'
|
|
62
|
+
|
|
63
|
+
type R = Positive<1> // 1
|
|
64
|
+
type R = Positive<1.0> // 1.0
|
|
65
|
+
type R = Positive<1n> // 1n
|
|
66
|
+
|
|
67
|
+
type R = Positive<-1> // never
|
|
68
|
+
type R = Positive<'1'> // never
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
- [`Positive<T, Then = T, Else = never>`](positive.ts#L17): check if `T` is a positive numeric value.
|
|
72
|
+
- [`IsPositive<T, Then = true, Else = false>`](positive.ts#L40): is `T` a positive numeric value.
|
|
73
|
+
- [`NotPositiveType<T, Then = T, Else = never>`](positive.ts#L54): check if `T` is not a positive numeric value.
|
|
74
|
+
- [`IsNotPositive<T, Then = true, Else = false>`](positive.ts#L68): is `T` not a positive numeric value.
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
`Negative<T>` and friends are used to check if `T` is a negative numeric value.
|
|
79
|
+
|
|
80
|
+
The `number` and `bigint` can be considered as a union of all negative and negative numeric literals.
|
|
81
|
+
|
|
82
|
+
That is why `IsNegative<T>` will yield `boolean` as the union is distributive.
|
|
83
|
+
`Negative<T>` returns `T` for `number` and `bigint` for the same reason.
|
|
84
|
+
It is a bit confusing but it is correct as it really returns `T | never`,
|
|
85
|
+
which resolves to `T`.
|
|
86
|
+
|
|
87
|
+
This behavior is different than `TrueType<T>` which `TrueType<boolean>` returns `never`.
|
|
88
|
+
|
|
89
|
+
This is because `TrueType<T>` is checking for the exact `true` type,
|
|
90
|
+
while `Negative<T>` is checking for a criteria of types (i.e. a set).
|
|
91
|
+
|
|
92
|
+
```ts
|
|
93
|
+
import type { Negative } from 'type-plus'
|
|
94
|
+
|
|
95
|
+
type R = Negative<1> // never
|
|
96
|
+
type R = Negative<1.0> // never
|
|
97
|
+
type R = Negative<1n> // never
|
|
98
|
+
|
|
99
|
+
type R = Negative<number> // number
|
|
100
|
+
type R = Negative<any> // any
|
|
101
|
+
|
|
102
|
+
type R = Negative<-1> // -1
|
|
103
|
+
type R = Negative<'1'> // '1'
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
- [`Negative<T, Then = T, Else = never>`](negative.ts#L21): check if `T` is a negative numeric value.
|
|
107
|
+
- [`IsNegative<T, Then = true, Else = false>`](negative.ts#L57): is `T` a negative numeric value.
|
|
108
|
+
- [`NotNegativeType<T, Then = T, Else = never>`](negative.ts#L75): check if `T` is not a negative numeric value.
|
|
109
|
+
- [`IsNotNegative<T, Then = true, Else = false>`](negative.ts#L109): is `T` not a negative numeric value.
|
|
110
|
+
|
|
111
|
+
## References
|
|
112
|
+
|
|
113
|
+
- [Handbook]
|
|
114
|
+
|
|
115
|
+
[handbook]: https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#the-primitives-string-number-and-boolean
|
package/ts/object/ANotB.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { IsEqual } from '../equal/equal.js'
|
|
2
2
|
import type { AnyRecord } from './AnyRecord.js'
|
|
3
3
|
import type { IsDisjoint } from './IsDisjoint.js'
|
|
4
4
|
import type { KeysWithDiffType } from './KeysWithDiffType.js'
|
|
5
5
|
|
|
6
|
-
export type ANotB<A extends AnyRecord, B extends AnyRecord> =
|
|
6
|
+
export type ANotB<A extends AnyRecord, B extends AnyRecord> = IsEqual<A, B> extends true
|
|
7
7
|
? never
|
|
8
8
|
: IsDisjoint<A, B> extends true
|
|
9
9
|
? A
|
|
@@ -11,7 +11,7 @@ export type ANotB<A extends AnyRecord, B extends AnyRecord> = Equal<A, B> extend
|
|
|
11
11
|
|
|
12
12
|
export type BNotA<A extends AnyRecord, B extends AnyRecord> = ANotB<B, A>
|
|
13
13
|
|
|
14
|
-
export type LeftJoin<A extends AnyRecord, B extends AnyRecord> =
|
|
14
|
+
export type LeftJoin<A extends AnyRecord, B extends AnyRecord> = IsEqual<A, B> extends true
|
|
15
15
|
? A
|
|
16
16
|
: IsDisjoint<A, B> extends true
|
|
17
17
|
? A & B
|
package/ts/object/Partial.ts
CHANGED
|
@@ -2,6 +2,11 @@ import type { UnionKeys } from '../union_keys.js'
|
|
|
2
2
|
import type { Omit } from './omit.js'
|
|
3
3
|
import type { Pick } from './pick.js'
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* An alternative `Partial<T>` type that works with `exactOptionalPropertyTypes`
|
|
7
|
+
*/
|
|
8
|
+
export type Partial<T> = { [P in keyof T]?: T[P] | undefined }
|
|
9
|
+
|
|
5
10
|
/**
|
|
6
11
|
* Apply `Partial<>` on the selected properties.
|
|
7
12
|
*/
|
package/ts/object/Required.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
// Thanks [jack-williams](https://github.com/jack-williams) for the [solution](https://github.com/Microsoft/TypeScript/issues/29269#issuecomment-451602962)
|
|
2
2
|
|
|
3
|
+
import { NonUndefined } from '../utils/NonUndefined.js'
|
|
4
|
+
|
|
5
|
+
export type Required<T> = { [P in keyof T]-?: NonUndefined<T[P]> }
|
|
6
|
+
|
|
3
7
|
export type RequiredPick<T, U extends keyof T> = Required<Pick<T, U>> & Pick<T, Exclude<keyof T, U>>
|
|
4
8
|
|
|
5
9
|
export type RequiredExcept<T, U extends keyof T> = Required<Pick<T, Exclude<keyof T, U>>> & Pick<T, U>
|
package/ts/object/index.ts
CHANGED
|
@@ -8,7 +8,7 @@ export type { KeysOfOptional } from './KeyofOptional.js'
|
|
|
8
8
|
export type { KeysWithDiffType } from './KeysWithDiffType.js'
|
|
9
9
|
export type { KnownKeys } from './KnownKeys.js'
|
|
10
10
|
export type { OptionalKeys } from './OptionalKeys.js'
|
|
11
|
-
export type { PartialExcept, PartialOmit, PartialPick } from './Partial.js'
|
|
11
|
+
export type { Partial, PartialExcept, PartialOmit, PartialPick } from './Partial.js'
|
|
12
12
|
export type { RecursiveIntersect } from './RecursiveIntersect.js'
|
|
13
13
|
export type { RecursivePartial } from './RecursivePartial.js'
|
|
14
14
|
export type { RecursiveRequired } from './RecursiveRequired.js'
|
package/ts/object/object_type.ts
CHANGED
|
@@ -16,7 +16,7 @@ export type ObjectType<T, Then = T, Else = never> = IsAnyOrNever<T, Else, [T] ex
|
|
|
16
16
|
/**
|
|
17
17
|
* Is `T` an `object`.
|
|
18
18
|
*
|
|
19
|
-
* Note that `Function`
|
|
19
|
+
* Note that `Function`, `Array`, and *tuple* are also `object`.
|
|
20
20
|
*
|
|
21
21
|
* ```ts
|
|
22
22
|
* type R = IsObject<{}> // true
|
package/ts/object/split.ts
CHANGED
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
import type { AnyRecord } from './AnyRecord.js'
|
|
3
3
|
import type { Omit } from './omit.js'
|
|
4
4
|
import { reduceByKey } from './reduceKey.js'
|
|
5
|
+
import type { Partial } from './Partial.js'
|
|
6
|
+
import { NonUndefined } from '../utils/NonUndefined.js'
|
|
5
7
|
|
|
6
8
|
type Splitter<T extends AnyRecord> = Partial<{ [k in keyof T]: T[k] | undefined }>
|
|
7
9
|
export type Split<T extends AnyRecord, S extends AnyRecord> = {
|
|
8
|
-
[k in keyof S]-?: S[k] extends undefined ? T[k] : NonNullable<T[k]> | S[k]
|
|
10
|
+
[k in keyof S]-?: S[k] extends undefined ? T[k] : NonNullable<T[k]> | NonUndefined<S[k]>
|
|
9
11
|
}
|
|
10
12
|
|
|
11
13
|
/**
|
|
@@ -3,6 +3,26 @@ import type { IsEmptyObject } from './IsEmptyObject.js'
|
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Can `A` assign to `B`
|
|
6
|
+
*
|
|
7
|
+
* Note that when union is involved, the assignability is measured distributively.
|
|
8
|
+
* Meaning the result can be `Then | Else` (i.e. `boolean` by default),
|
|
9
|
+
* instead of distinctive `Then` (`true`) or `Else` (`false`).
|
|
10
|
+
*
|
|
11
|
+
* This is the correct behavior.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* CanAssign<number | string, number> // boolean
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* We are checking can `A` assign to `B`.
|
|
19
|
+
* Since `A` is `number | string`,
|
|
20
|
+
* `A` can assign to `B` when `A` is number` (true), and
|
|
21
|
+
* `A` cannot assign to `B` when `A` is string` (false).
|
|
22
|
+
* So the result is `true | false = boolean`.
|
|
23
|
+
*
|
|
24
|
+
* If you want to make sure all branches are assignable,
|
|
25
|
+
* use `StrictCanAssign<A, B>`.
|
|
6
26
|
*/
|
|
7
27
|
export type CanAssign<A, B, Then = true, Else = false> = IsEmptyObject<A> extends true
|
|
8
28
|
? Record<string, unknown> extends B
|
|
@@ -16,6 +36,32 @@ export type CanAssign<A, B, Then = true, Else = false> = IsEmptyObject<A> extend
|
|
|
16
36
|
? Then
|
|
17
37
|
: Else
|
|
18
38
|
|
|
39
|
+
/**
|
|
40
|
+
* Can `A` strictly assign to `B`.
|
|
41
|
+
*
|
|
42
|
+
* All branches in an union `A` are assignable to `B`.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* StrictCanAssign<number | string, number> // false
|
|
47
|
+
* StrictCanAssign<number | string, number | string> // true
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export type StrictCanAssign<A, B, Then = true, Else = false> = IsEmptyObject<A> extends true
|
|
51
|
+
? Record<string, unknown> extends B
|
|
52
|
+
? Then
|
|
53
|
+
: Else
|
|
54
|
+
: boolean extends A
|
|
55
|
+
? boolean extends B
|
|
56
|
+
? Then
|
|
57
|
+
: Else
|
|
58
|
+
: [A] extends [B]
|
|
59
|
+
? Then
|
|
60
|
+
: Else
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* @deprecated use `CanAssign` instead
|
|
64
|
+
*/
|
|
19
65
|
export type IsAssign<A, B, Then = true, Else = false> = CanAssign<A, B, Then, Else>
|
|
20
66
|
|
|
21
67
|
export function canAssign<T>(canAssign: false): <S>(subject: NotExtendable<S, T>) => true
|
package/ts/predicates/Extends.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type Extendable<A, B> = A extends B ?
|
|
2
|
-
export type NotExtendable<A, B> = A extends B ?
|
|
1
|
+
export type Extendable<A, B, Then = A, Else = never> = A extends B ? Then : Else
|
|
2
|
+
export type NotExtendable<A, B, Then = A, Else = never> = A extends B ? Else : Then
|
|
3
3
|
export type IsExtend<A, B, Then = true, Else = false> = A extends B ? Then : Else
|
|
4
4
|
export type IsNotExtend<A, B, Then = true, Else = false> = A extends B ? Else : Then
|
package/ts/predicates/index.ts
CHANGED
|
@@ -2,7 +2,6 @@ export * from './CanAssign.js'
|
|
|
2
2
|
export type { Extendable, IsExtend, IsNotExtend, NotExtendable } from './Extends.js'
|
|
3
3
|
export type { If } from './If.js'
|
|
4
4
|
export type { IsEmptyObject } from './IsEmptyObject.js'
|
|
5
|
-
export * from './isType.js'
|
|
6
5
|
export type { And, Not, Or, Xor } from './logical.js'
|
|
7
6
|
|
|
8
7
|
export type IsLiteral<T extends number | string, Then = true, Else = false> = number extends T
|