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/assertion/readme.md
CHANGED
|
@@ -1,12 +1,143 @@
|
|
|
1
|
-
# Assertion
|
|
1
|
+
# Assertion
|
|
2
2
|
|
|
3
3
|
[Assertion Functions][assertion_functions] are special functions that asserts certain conditions of your program.
|
|
4
4
|
|
|
5
|
+
It is introduced in TypeScript 3.7.
|
|
6
|
+
|
|
5
7
|
They throw an error if the condition is not met, and return nothing otherwise.
|
|
6
8
|
|
|
7
9
|
These assertion functions are typically used in runtime,
|
|
8
10
|
so that that type of the value can be narrowed down.
|
|
9
11
|
|
|
12
|
+
## assertType
|
|
13
|
+
|
|
14
|
+
`assertType<T>(subject)`:
|
|
15
|
+
|
|
16
|
+
✔️ `immediate`
|
|
17
|
+
|
|
18
|
+
It ensures `subject` satisfies `T`.
|
|
19
|
+
It is similar to `const x: T = subject` without introducing an unused variable.
|
|
20
|
+
You need to specify `T` for it to work.
|
|
21
|
+
|
|
22
|
+
`assertType<T>(subject, validator)`:
|
|
23
|
+
|
|
24
|
+
`assertType<T>(subject, Class)`:
|
|
25
|
+
|
|
26
|
+
✔️ `assertion function`, `runtime`
|
|
27
|
+
|
|
28
|
+
These overloads of `assertType` allow you to specify a `validator`.
|
|
29
|
+
With these overloads, `subject` can be `unknown` or `any`.
|
|
30
|
+
|
|
31
|
+
If `subject` fails the assertion,
|
|
32
|
+
a standard `TypeError` will be thrown and provide better error info.
|
|
33
|
+
For example:
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
const s: unknown = 1
|
|
37
|
+
|
|
38
|
+
// TypeError: subject fails to satisfy s => typeof s === 'boolean'
|
|
39
|
+
assertType<boolean>(s, s => typeof s === 'boolean')
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
The message beautification is provided by [`tersify`](https://github.com/unional/tersify).
|
|
43
|
+
|
|
44
|
+
`assertType.isUndefined(subject)`:
|
|
45
|
+
|
|
46
|
+
`assertType.isNull(subject)`:
|
|
47
|
+
|
|
48
|
+
`assertType.isNumber(subject)`:
|
|
49
|
+
|
|
50
|
+
`assertType.isBoolean(subject)`:
|
|
51
|
+
|
|
52
|
+
`assertType.isTrue(subject)`:
|
|
53
|
+
|
|
54
|
+
`assertType.isFalse(subject)`:
|
|
55
|
+
|
|
56
|
+
`assertType.isString(subject)`:
|
|
57
|
+
|
|
58
|
+
`assertType.isFunction(subject)`:
|
|
59
|
+
|
|
60
|
+
`assertType.isConstructor(subject)`:
|
|
61
|
+
|
|
62
|
+
`assertType.isError(subject)`:
|
|
63
|
+
|
|
64
|
+
✔️ `immediate`, `assertion function`, `runtime`
|
|
65
|
+
|
|
66
|
+
Compiler and runtime assertion with type narrowing from `any`.
|
|
67
|
+
They assert the type of `subject` is that specific type.
|
|
68
|
+
i.e. union type will fail at type level:
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
const s: number | undefined = undefined
|
|
72
|
+
assertType.isUndefined(s) // TypeScript complains
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
They accept `any` and will be narrowed to the specific type.
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
const s: any = undefined
|
|
79
|
+
assertType.isUndefined(s)
|
|
80
|
+
s // type is undefined
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
`assertType.isNever(subject)`:
|
|
84
|
+
|
|
85
|
+
✔️ `immediate`
|
|
86
|
+
|
|
87
|
+
Check if the subject type is `never`.
|
|
88
|
+
This function is not very useful in actual code as TypeScript will indicate the error.
|
|
89
|
+
But it can be useful when writing tests for types.
|
|
90
|
+
|
|
91
|
+
This is useful for variables. For type level only check, do the following:
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
assertType.isTrue(true as Equal<YourType, never>)
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
`assertType.noUndefined(subject)`:
|
|
98
|
+
|
|
99
|
+
`assertType.noNull(subject)`:
|
|
100
|
+
|
|
101
|
+
`assertType.noNumber(subject)`:
|
|
102
|
+
|
|
103
|
+
`assertType.noBoolean(subject)`:
|
|
104
|
+
|
|
105
|
+
`assertType.noTrue(subject)`:
|
|
106
|
+
|
|
107
|
+
`assertType.noFalse(subject)`:
|
|
108
|
+
|
|
109
|
+
`assertType.noString(subject)`:
|
|
110
|
+
|
|
111
|
+
`assertType.noFunction(subject)`:
|
|
112
|
+
|
|
113
|
+
`assertType.noError(subject)`:
|
|
114
|
+
|
|
115
|
+
✔️ `immediate`, `runtime`
|
|
116
|
+
|
|
117
|
+
Compiler and runtime assertion.
|
|
118
|
+
Assert `subject` type does not contain the specific type.
|
|
119
|
+
Work against unions.
|
|
120
|
+
|
|
121
|
+
```ts
|
|
122
|
+
const s: number | undefined = 1
|
|
123
|
+
assertType.noUndefined(s) // TypeScript complains
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
They accept `subject` with type `any` or `unknown`,
|
|
127
|
+
the assertion will happen in runtime to ensure `subject` is the specific type.
|
|
128
|
+
|
|
129
|
+
`assertType.as<T>(subject)`:
|
|
130
|
+
|
|
131
|
+
✔️ `immediate`
|
|
132
|
+
|
|
133
|
+
Assert `subject` as `T` inline.
|
|
134
|
+
This is useful to help TypeScript to adjust the type on the fly.
|
|
135
|
+
|
|
136
|
+
```ts
|
|
137
|
+
let s: number | undefined = 1
|
|
138
|
+
assertType.as<1>(s) // `s` type is now `1`
|
|
139
|
+
```
|
|
140
|
+
|
|
10
141
|
## References
|
|
11
142
|
|
|
12
143
|
- [Handbook][assertion_functions]
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cast a string to a bigint literal type if possible.
|
|
3
|
+
*
|
|
4
|
+
* ```ts
|
|
5
|
+
* StringToBigint<'1n'> // 1n
|
|
6
|
+
* StringToBigint<'-1n'> // -1n
|
|
7
|
+
* ```
|
|
8
|
+
*/
|
|
9
|
+
export type StringToBigint<S extends string, Fail = never> = S extends `-0n`
|
|
10
|
+
? 0n
|
|
11
|
+
: S extends `${infer N extends bigint}n`
|
|
12
|
+
? N
|
|
13
|
+
: Fail
|
package/ts/bigint/readme.md
CHANGED
|
@@ -4,45 +4,45 @@
|
|
|
4
4
|
|
|
5
5
|
## Type Checking
|
|
6
6
|
|
|
7
|
-
The `
|
|
7
|
+
The `BigintType<T>` and friends are used to check if a type is `bigint` or not.
|
|
8
8
|
|
|
9
9
|
They are loose type checks, meaning they match `bigint` and bigint literals,
|
|
10
10
|
as well as intersection types.
|
|
11
11
|
|
|
12
12
|
```ts
|
|
13
|
-
import type {
|
|
13
|
+
import type { BigintType } from 'type-plus'
|
|
14
14
|
|
|
15
|
-
type R =
|
|
15
|
+
type R = BigintType<bigint> // bigint
|
|
16
16
|
|
|
17
|
-
type R =
|
|
18
|
-
type R =
|
|
17
|
+
type R = BigintType<1n> // bigint
|
|
18
|
+
type R = BigintType<bigint & { a: 1}> // bigint
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
- [`
|
|
22
|
-
- [`
|
|
23
|
-
- [`
|
|
21
|
+
- [`BigintType<T, Then = T, Else = never>`](bigint_type.ts#L15): check if `T` is `bigint` or bigint literal.
|
|
22
|
+
- [`IsBigint<T, Then = true, Else = false`](bigint_type.ts#L33): is `T` `bigint`.
|
|
23
|
+
- [`NotBigintType<T, Then = T, Else = never>`](bigint_type.ts#L47): check if `T` is not `bigint`.
|
|
24
24
|
- [`IsNotBigInt<T, Then = true, Else = false>`](bigint_type.ts#L61): is `T` not `bigint`.
|
|
25
25
|
|
|
26
26
|
---
|
|
27
27
|
|
|
28
|
-
The `
|
|
28
|
+
The `StrictBigintType<T>` and friends are used to check if a type is exactly `bigint` or not.
|
|
29
29
|
|
|
30
30
|
They are strict type checks, meaning they match only the type `bigint`,
|
|
31
31
|
and not bigint literals or intersection types.
|
|
32
32
|
|
|
33
33
|
```ts
|
|
34
|
-
import type {
|
|
34
|
+
import type { StrictBigintType } from 'type-plus'
|
|
35
35
|
|
|
36
|
-
type R =
|
|
36
|
+
type R = StrictBigintType<bigint> // bigint
|
|
37
37
|
|
|
38
|
-
type R =
|
|
39
|
-
type R =
|
|
38
|
+
type R = StrictBigintType<1n> // never
|
|
39
|
+
type R = StrictBigintType<bigint & { a: 1}> // never
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
-
- [`
|
|
43
|
-
- [`
|
|
44
|
-
- [`
|
|
45
|
-
- [`
|
|
42
|
+
- [`StrictBigintType<T, Then = T, Else = never>`](strict_bigint_type.ts#L15): check if `T` is exactly `bigint`.
|
|
43
|
+
- [`IsStrictBigint<T, Then = true, Else = false`](strict_bigint_type.ts#L33): is `T` exactly `bigint`.
|
|
44
|
+
- [`NotStrictBigintType<T, Then = T, Else = never>`](strict_bigint_type.ts#L47): check if `T` is not exactly `bigint`.
|
|
45
|
+
- [`IsNotStrictBigint<T, Then = true, Else = false>`](strict_bigint_type.ts#L61): is `T` not exactly `bigint`.
|
|
46
46
|
|
|
47
47
|
## References
|
|
48
48
|
|
package/ts/equal/equal.ts
CHANGED
|
@@ -37,8 +37,12 @@ type IdentityEqual<A, B, Then, Else> = (<_>() => _ extends (A & _) | _ ? 1 : 2)
|
|
|
37
37
|
* type R = Equal<[any], [1]> // false
|
|
38
38
|
* type R = Equal<{ a: 1 }, { a: 1; b: 2 }> // false
|
|
39
39
|
* ```
|
|
40
|
+
*
|
|
41
|
+
* Note that intersection type checks only works at first level.
|
|
42
|
+
* It cannot be check recursively,
|
|
43
|
+
* or else will run into infinite recursion if the type includes recursive types.
|
|
40
44
|
*/
|
|
41
|
-
export type
|
|
45
|
+
export type IsEqual<A, B, Then = true, Else = false> = [A, B] extends [B, A]
|
|
42
46
|
? BothNever<
|
|
43
47
|
A,
|
|
44
48
|
B,
|
|
@@ -60,7 +64,7 @@ export type Equal<A, B, Then = true, Else = false> = [A, B] extends [B, A]
|
|
|
60
64
|
Properties<A>,
|
|
61
65
|
Properties<B>,
|
|
62
66
|
[A, B] extends [(...args: infer P1) => any, (...args: infer P2) => any]
|
|
63
|
-
?
|
|
67
|
+
? IsEqual<P1, P2, Then, Else>
|
|
64
68
|
: Then,
|
|
65
69
|
Else
|
|
66
70
|
>,
|
|
@@ -88,5 +92,51 @@ export type Equal<A, B, Then = true, Else = false> = [A, B] extends [B, A]
|
|
|
88
92
|
* type R = NotEqual<[any], [1]> // true
|
|
89
93
|
* type R = NotEqual<{ a: 1 }, { a: 1; b: 2 }> // true
|
|
90
94
|
* ```
|
|
95
|
+
*
|
|
96
|
+
* Note that intersection type checks only works at first level.
|
|
97
|
+
* It cannot be check recursively,
|
|
98
|
+
* or else will run into infinite recursion if the type includes recursive types.
|
|
99
|
+
*/
|
|
100
|
+
export type IsNotEqual<A, B, Then = true, Else = false> = IsEqual<A, B, Else, Then>
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Checks `A` and `B` are equal.
|
|
104
|
+
*
|
|
105
|
+
* @deprecated this will be changed to `filter` variant in the future.
|
|
106
|
+
* Please use `IsEqual` for the `predicate` behavior.
|
|
107
|
+
*
|
|
108
|
+
* ```ts
|
|
109
|
+
* type R = Equal<1, 1> // true
|
|
110
|
+
* type R = Equal<any, any> // true
|
|
111
|
+
* type R = Equal<boolean, boolean> // true
|
|
112
|
+
* type R = Equal<true, true> // true
|
|
113
|
+
* type R = Equal<[1], [1]> // true
|
|
114
|
+
*
|
|
115
|
+
* type R = Equal<boolean, true> // false
|
|
116
|
+
* type R = Equal<any, 1> // false
|
|
117
|
+
* type R = Equal<[any], [1]> // false
|
|
118
|
+
* type R = Equal<{ a: 1 }, { a: 1; b: 2 }> // false
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
export type Equal<A, B, Then = true, Else = false> = IsEqual<A, B, Then, Else>
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Checks `A` and `B` are not equal.
|
|
125
|
+
*
|
|
126
|
+
* @deprecated this will be changed to `filter` variant in the future.
|
|
127
|
+
* Please use `IsNotEqual` for the `predicate` behavior.
|
|
128
|
+
*
|
|
129
|
+
* ```ts
|
|
130
|
+
* type R = NotEqual<1, 1> // false
|
|
131
|
+
* type R = NotEqual<any, any> // false
|
|
132
|
+
* type R = NotEqual<boolean, boolean> // false
|
|
133
|
+
* type R = NotEqual<true, true> // false
|
|
134
|
+
* type R = NotEqual<[1], [1]> // false
|
|
135
|
+
*
|
|
136
|
+
* type R = NotEqual<boolean, true> // true
|
|
137
|
+
* type R = NotEqual<any, 1> // true
|
|
138
|
+
* type R = NotEqual<[any], [1]> // true
|
|
139
|
+
* type R = NotEqual<{ a: 1 }, { a: 1; b: 2 }> // true
|
|
140
|
+
* ```
|
|
91
141
|
*/
|
|
92
|
-
export type NotEqual<A, B, Then = true, Else = false> =
|
|
142
|
+
export type NotEqual<A, B, Then = true, Else = false> = IsNotEqual<A, B, Then, Else>
|
package/ts/equal/readme.md
CHANGED
|
@@ -1,27 +1,41 @@
|
|
|
1
|
-
#
|
|
1
|
+
# IsEqual
|
|
2
2
|
|
|
3
|
-
`
|
|
3
|
+
`IsEqual<A, B>` and friends check if `A` and `B` are equal.
|
|
4
4
|
|
|
5
5
|
It is a type-level version of `===`.
|
|
6
6
|
It handles special types (`any`, `unknown`, `never`, `void`) correctly.
|
|
7
7
|
|
|
8
8
|
```ts
|
|
9
|
-
import { type
|
|
10
|
-
|
|
11
|
-
type R =
|
|
12
|
-
type R =
|
|
13
|
-
type R =
|
|
14
|
-
type R =
|
|
15
|
-
type R =
|
|
16
|
-
|
|
17
|
-
type R =
|
|
18
|
-
type R =
|
|
19
|
-
type R =
|
|
20
|
-
type R =
|
|
9
|
+
import { type IsEqual } from 'type-plus'
|
|
10
|
+
|
|
11
|
+
type R = IsEqual<1, 1> // true
|
|
12
|
+
type R = IsEqual<any, any> // true
|
|
13
|
+
type R = IsEqual<boolean, boolean> // true
|
|
14
|
+
type R = IsEqual<true, true> // true
|
|
15
|
+
type R = IsEqual<[1], [1]> // true
|
|
16
|
+
|
|
17
|
+
type R = IsEqual<boolean, true> // false
|
|
18
|
+
type R = IsEqual<any, 1> // false
|
|
19
|
+
type R = IsEqual<[any], [1]> // false
|
|
20
|
+
type R = IsEqual<{ a: 1 }, { a: 1; b: 2 }> // false
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
Note that intersection type checks only works at first level.
|
|
24
|
+
It cannot be check recursively,
|
|
25
|
+
or else will run into infinite recursion if the type includes recursive types.
|
|
26
|
+
|
|
27
|
+
i.e.
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
// true
|
|
31
|
+
IsEqual<{ a: 1 } & { b: 2 }, { a: 1; b: 2 }>
|
|
32
|
+
|
|
33
|
+
// false
|
|
34
|
+
IsEqual<{ nested: { a: number; b: string } }, { nested: { a: number } & { b: string } }>
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
- [`IsEqual<A, B, Then = true, Else = false>`](equal.ts#L27): check if `A` and `B` are equal.
|
|
38
|
+
- [`IsNotEqual<A, B, Then = true, Else = false>`](equal.ts#L88): check if `A` and `B` are not equal.
|
|
25
39
|
|
|
26
40
|
---
|
|
27
41
|
|
package/ts/functional/Maybe.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Brand } from '../nominal/index.js'
|
|
2
|
-
import type {
|
|
2
|
+
import type { IsEqual } from '../equal/equal.js'
|
|
3
3
|
import type { Widen } from '../utils/index.js'
|
|
4
4
|
|
|
5
5
|
export type Maybe<T> = Just<T> | None<T>
|
|
@@ -8,7 +8,7 @@ export type None<T> = Brand<'maybe', void> & { unwrap(): T }
|
|
|
8
8
|
|
|
9
9
|
export function just<T>(
|
|
10
10
|
value: T
|
|
11
|
-
):
|
|
11
|
+
): IsEqual<T, undefined | null> extends true ? None<T> : Just<Widen<NonNullable<T>>> {
|
|
12
12
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
13
13
|
return {
|
|
14
14
|
unwrap() {
|
package/ts/index.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
export { required, requiredDeep, unpartial } from 'unpartial'
|
|
2
2
|
export type { IsAnyOrNever } from './any/any_or_never.js'
|
|
3
3
|
export type { AnyType, IsAny, IsNotAny, NotAnyType } from './any/any_type.js'
|
|
4
|
-
export type { At
|
|
4
|
+
export type { At } from './array/array.at.js'
|
|
5
|
+
export type { Concat } from './array/array.concat.js'
|
|
5
6
|
export * as ArrayPlus from './array/array_plus.js'
|
|
6
7
|
export type { ArrayType, IsArray, IsNotArray, NotArrayType } from './array/array_type.js'
|
|
7
8
|
export * from './array/index.js'
|
|
8
9
|
export * from './assertion/assert_type.js'
|
|
9
10
|
export type { BigintType, IsBigint, IsNotBigint, NotBigintType } from './bigint/bigint_type.js'
|
|
11
|
+
export type { StringToBigint } from './bigint/cast.js'
|
|
10
12
|
export type {
|
|
11
13
|
IsNotStrictBigint,
|
|
12
14
|
IsStrictBigint,
|
|
@@ -24,7 +26,7 @@ export type {
|
|
|
24
26
|
export type { IsNotTrue, IsTrue, NotTrueType, TrueType } from './boolean/true_type.js'
|
|
25
27
|
export * from './class/index.js'
|
|
26
28
|
export type { ComposableTypes, NonComposableTypes } from './composable_types.js'
|
|
27
|
-
export type { Equal, NotEqual } from './equal/equal.js'
|
|
29
|
+
export type { Equal, IsEqual, IsNotEqual, NotEqual } from './equal/equal.js'
|
|
28
30
|
export type { AnyFunction } from './function/any_function.js'
|
|
29
31
|
export * from './function/extract_function.js'
|
|
30
32
|
export type { FunctionType, IsFunction, IsNotFunction, NotFunctionType } from './function/function_type.js'
|
|
@@ -36,25 +38,25 @@ export type {
|
|
|
36
38
|
} from './function/strict_function_type.js'
|
|
37
39
|
export * from './functional/index.js'
|
|
38
40
|
export type { JSONArray, JSONObject, JSONPrimitive, JSONTypes } from './json.js'
|
|
39
|
-
export type {
|
|
40
|
-
|
|
41
|
-
Add,
|
|
42
|
-
Decrement,
|
|
43
|
-
Digit,
|
|
44
|
-
DigitArray,
|
|
45
|
-
GreaterThan,
|
|
46
|
-
Increment,
|
|
47
|
-
Max,
|
|
48
|
-
Subtract
|
|
49
|
-
} from './math/index.js'
|
|
41
|
+
export type { Abs, Add, Decrement, GreaterThan, Increment, Max, Multiply, Subtract } from './math/index.js'
|
|
42
|
+
export * as MathPlus from './math/math_plus.js'
|
|
50
43
|
export type { IsNever, IsNotNever, Is_Never, NeverType, NotNeverType, Not_Never } from './never/never_type.js'
|
|
51
44
|
export * from './nodejs/index.js'
|
|
52
45
|
export * from './nominal/index.js'
|
|
53
46
|
export type { IsNotNull, IsNull, NotNullType, NullType } from './null/null_type.js'
|
|
54
|
-
export type {
|
|
55
|
-
export type { IsNegative, IsNotNegative, Negative, NotNegative } from './number/negative.js'
|
|
47
|
+
export type { StringToNumber } from './number/cast.js'
|
|
56
48
|
export * as NumberPlus from './number/number_plus.js'
|
|
57
49
|
export type { IsNotNumber, IsNumber, NotNumberType, NumberType } from './number/number_type.js'
|
|
50
|
+
export type {
|
|
51
|
+
IsNotStrictNumber,
|
|
52
|
+
IsStrictNumber,
|
|
53
|
+
NotStrictNumberType,
|
|
54
|
+
StrictNumberType
|
|
55
|
+
} from './number/strict_number_type.js'
|
|
56
|
+
export type { NumericToString, StringToNumeric } from './numeric/cast.js'
|
|
57
|
+
export type { Integer, IsInteger, IsNotInteger, IsWhole, NotInteger } from './numeric/integer.js'
|
|
58
|
+
export type { IsNegative, IsNotNegative, Negative, NotNegative } from './numeric/negative.js'
|
|
59
|
+
export * as NumericPlus from './numeric/numeric_plus.js'
|
|
58
60
|
export type {
|
|
59
61
|
IsNotNumeric,
|
|
60
62
|
IsNumeric,
|
|
@@ -62,14 +64,8 @@ export type {
|
|
|
62
64
|
Numeric,
|
|
63
65
|
NumericType,
|
|
64
66
|
Zero
|
|
65
|
-
} from './
|
|
66
|
-
export type { IsNotPositive, IsPositive, NonPositive, Positive } from './
|
|
67
|
-
export type {
|
|
68
|
-
IsNotStrictNumber,
|
|
69
|
-
IsStrictNumber,
|
|
70
|
-
NotStrictNumberType,
|
|
71
|
-
StrictNumberType
|
|
72
|
-
} from './number/strict_number_type.js'
|
|
67
|
+
} from './numeric/numeric_type.js'
|
|
68
|
+
export type { IsNotPositive, IsPositive, NonPositive, Positive } from './numeric/positive.js'
|
|
73
69
|
export * from './object/index.js'
|
|
74
70
|
export type { IsNotObject, IsObject, NotObjectType, ObjectType } from './object/object_type.js'
|
|
75
71
|
export * from './predicates/index.js'
|
|
@@ -87,7 +83,10 @@ export type { IsNotString, IsString, NotStringType, StringType } from './string/
|
|
|
87
83
|
export type { IsNotSymbol, IsSymbol, NotSymbolType, SymbolType } from './symbol/symbol_type.js'
|
|
88
84
|
export * from './testing/stub.js'
|
|
89
85
|
export * from './testing/test_type.js'
|
|
86
|
+
export * from './tuple/create_tuple.js'
|
|
87
|
+
export * as TuplePlus from './tuple/tuple_plus.js'
|
|
90
88
|
export type { IsNotTuple, IsTuple, NotTupleType, TupleType } from './tuple/tuple_type.js'
|
|
89
|
+
export * from './type-guard/is_type.js'
|
|
91
90
|
export type { Failed, FailedT } from './type/failed.js'
|
|
92
91
|
export type { NoInfer } from './type/no_infer.js'
|
|
93
92
|
export type {
|
|
@@ -100,4 +99,3 @@ export type { UnionKeys } from './union_keys.js'
|
|
|
100
99
|
export type { IsNotUnknown, IsUnknown, NotUnknownType, UnknownType } from './unknown/unknown_type.js'
|
|
101
100
|
export * from './utils/index.js'
|
|
102
101
|
export type { IsNotVoid, IsVoid, NotVoidType, VoidType } from './void/void_type.js'
|
|
103
|
-
|
package/ts/math/README.md
CHANGED
|
@@ -1,7 +1,97 @@
|
|
|
1
|
-
# Math
|
|
2
|
-
|
|
3
|
-
##
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
# Math
|
|
2
|
+
|
|
3
|
+
## Add
|
|
4
|
+
|
|
5
|
+
> `Add<A, B>` | `MathPlus.Add<A, B>`
|
|
6
|
+
|
|
7
|
+
Performs `A + B` which can be either `number` or `bigint`.
|
|
8
|
+
|
|
9
|
+
It supports positive, negative, floating point numbers.
|
|
10
|
+
It will perform coerce conversion if the necessary.
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
Add<1, 2> // 3
|
|
14
|
+
Add<1.2, -2> // -0.8
|
|
15
|
+
Add<1n, 2.3> // 3.3 <-- converted to `number`
|
|
16
|
+
Add<9007199254740992, 1> // 9007199254740993n <-- converted to `bigint`
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Subtract
|
|
20
|
+
|
|
21
|
+
> `Subtract<A, B>` | `MathPlus.Subtract<A, B>`
|
|
22
|
+
|
|
23
|
+
Performs `A - B` which can be either `number` or `bigint`.
|
|
24
|
+
|
|
25
|
+
It supports positive, negative, floating point numbers.
|
|
26
|
+
It will perform coerce conversion if the necessary.
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
Subtract<100, 2> // 98
|
|
30
|
+
Subtract<1.2, 2> // -0.8
|
|
31
|
+
Subtract<1n, 2.3> // -1.3 <-- converted to `number`
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Multiply
|
|
35
|
+
|
|
36
|
+
> `Multiply<A, B>` | `MathPlus.Multiply<A, B>`
|
|
37
|
+
|
|
38
|
+
Performs `A * B` which can be either `number` or `bigint`.
|
|
39
|
+
|
|
40
|
+
It supports positive, negative, floating point numbers.
|
|
41
|
+
It will perform coerce conversion if the necessary.
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
Multiply<100, 2> // 200
|
|
45
|
+
Multiply<1.2, 2> // 2.4
|
|
46
|
+
Multiply<1n, 2.3> // 2.3 <-- converted to `number`
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## GreaterThan
|
|
50
|
+
|
|
51
|
+
> `GreaterThan<A, B>` | `MathPlus.GreaterThan<A, B>`
|
|
52
|
+
|
|
53
|
+
Performs `A > B` which can be either `number` or `bigint`.
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
GreaterThan<100, 2> // true
|
|
57
|
+
GreaterThan<-1, 2> // false
|
|
58
|
+
GreaterThan<1.2, 2> // false
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Max
|
|
62
|
+
|
|
63
|
+
> `Max<A, B>` | `MathPlus.Max<A, B>`
|
|
64
|
+
|
|
65
|
+
Performs `Math.max(A, B)` which can be either `number` or `bigint`.
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
Max<100, 2> // 100
|
|
69
|
+
Max<-1, 2> // 2
|
|
70
|
+
Max<1.2, 2> // 2
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## MathPlus
|
|
74
|
+
|
|
75
|
+
`MathPlus` contains all types and type utilities related to math.
|
|
76
|
+
|
|
77
|
+
### [`MathPlus.ToNegative`](./math.to-negative.ts#L12)
|
|
78
|
+
|
|
79
|
+
> `MathPlus.ToNegative<N>`
|
|
80
|
+
|
|
81
|
+
Converts a number or bigint `N` to negative.
|
|
82
|
+
If `N` is already negative, it returns itself.
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
MathPlus.ToNegative<5> // -5
|
|
86
|
+
MathPlus.ToNegative<0> // 0
|
|
87
|
+
MathPlus.ToNegative<-5> // -5
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## References
|
|
91
|
+
|
|
92
|
+
- [Implementing Arithmetic Within TypeScript’s Type System](https://itnext.io/implementing-arithmetic-within-typescripts-type-system-a1ef140a6f6f)
|
|
93
|
+
- [typepark](https://github.com/kgtkr/typepark)
|
|
94
|
+
- [typical](https://github.com/KiaraGrouwstra/typical/tree/master/src)
|
|
95
|
+
|
|
96
|
+
- <https://stackoverflow.com/questions/3060064/how-computer-multiplies-2-numbers>
|
|
97
|
+
- <https://en.wikipedia.org/wiki/Binary_multiplier>
|
package/ts/math/abs.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { IsBigint } from '../bigint/bigint_type.js'
|
|
2
|
+
import type { IsNumber } from '../number/number_type.js'
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* Returns the absolute value of a number or bigint `N`.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* Abs<-5> // 5
|
|
10
|
+
* Abs<5> // 5
|
|
11
|
+
* Abs<-1n> // 1n // Where `1n` is a bigint
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export type Abs<N extends number | bigint, Fail = never> = IsNumber<
|
|
15
|
+
N,
|
|
16
|
+
[number] extends [N] ? Fail : `${N}` extends `-${infer P extends number}` ? P : N,
|
|
17
|
+
IsBigint<N, [bigint] extends [N] ? Fail : `${N}` extends `-${infer P extends bigint}` ? P : N, Fail>
|
|
18
|
+
>
|
package/ts/math/add.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { NumericStruct } from './numeric_struct.js'
|
|
2
|
+
|
|
3
|
+
export type Add<A extends number | bigint, B extends number | bigint, Fail = never> = [
|
|
4
|
+
NumericStruct.FromNumeric<A, Fail>,
|
|
5
|
+
NumericStruct.FromNumeric<B, Fail>
|
|
6
|
+
] extends [infer MA, infer MB]
|
|
7
|
+
? MA extends NumericStruct
|
|
8
|
+
? MB extends NumericStruct
|
|
9
|
+
? NumericStruct.ToNumeric<NumericStruct.Add<MA, MB>>
|
|
10
|
+
: Fail
|
|
11
|
+
: Fail
|
|
12
|
+
: never
|
|
13
|
+
|
|
14
|
+
export type Increment<N extends number | bigint> = Add<N, 1>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { IsPositive } from '../numeric/positive.js'
|
|
2
|
+
import type { Subtract } from './subtract.js'
|
|
3
|
+
|
|
4
|
+
export type GreaterThan<A extends number | bigint, B extends number | bigint, Fail = never> = Subtract<
|
|
5
|
+
A,
|
|
6
|
+
B,
|
|
7
|
+
'fail'
|
|
8
|
+
> extends infer R extends number
|
|
9
|
+
? R extends 0
|
|
10
|
+
? false
|
|
11
|
+
: IsPositive<R>
|
|
12
|
+
: Fail
|
package/ts/math/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
export type { Abs } from './
|
|
2
|
-
export type {
|
|
3
|
-
export type {
|
|
4
|
-
export type {
|
|
5
|
-
export type {
|
|
6
|
-
export type {
|
|
1
|
+
export type { Abs } from './abs.js'
|
|
2
|
+
// export type { Digit, DigitArray } from './Digit.js'
|
|
3
|
+
export type { GreaterThan } from './greater_than.js'
|
|
4
|
+
export type { Max } from './max.js'
|
|
5
|
+
export type { Add, Increment } from './add.js'
|
|
6
|
+
export type { Multiply } from './multiply.js'
|
|
7
|
+
export type { Decrement, Subtract } from './subtract.js'
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a number or bigint `N` to negative.
|
|
3
|
+
* If `N` is already negative, it returns itself.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* ToNegative<5> // -5
|
|
8
|
+
* ToNegative<0> // 0
|
|
9
|
+
* ToNegative<-5> // -5
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export type ToNegative<N extends number | bigint> = N extends number
|
|
13
|
+
? N extends 0
|
|
14
|
+
? 0
|
|
15
|
+
: `-${N}` extends `${infer W extends number}`
|
|
16
|
+
? W
|
|
17
|
+
: N
|
|
18
|
+
: N extends 0n
|
|
19
|
+
? 0n
|
|
20
|
+
: `-${N}` extends `${infer W extends bigint}`
|
|
21
|
+
? W
|
|
22
|
+
: N
|