type-plus 6.5.0 → 6.6.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 +27 -15
- package/cjs/any/any_or_never.d.ts +0 -2
- package/cjs/any/any_or_never.d.ts.map +1 -1
- package/cjs/any/any_type.d.ts +2 -6
- package/cjs/any/any_type.d.ts.map +1 -1
- package/cjs/array/array.d.ts +0 -4
- package/cjs/array/array.d.ts.map +1 -1
- package/cjs/array/array_index.d.ts +7 -10
- package/cjs/array/array_index.d.ts.map +1 -1
- package/cjs/array/array_type.d.ts +0 -8
- package/cjs/array/array_type.d.ts.map +1 -1
- package/cjs/bigint/bigint_type.d.ts +4 -12
- package/cjs/bigint/bigint_type.d.ts.map +1 -1
- package/cjs/bigint/strict_bigint_type.d.ts +4 -12
- package/cjs/bigint/strict_bigint_type.d.ts.map +1 -1
- package/cjs/boolean/boolean_type.d.ts +0 -8
- package/cjs/boolean/boolean_type.d.ts.map +1 -1
- package/cjs/boolean/false_type.d.ts +0 -8
- package/cjs/boolean/false_type.d.ts.map +1 -1
- package/cjs/boolean/strict_boolean_type.d.ts +0 -8
- package/cjs/boolean/strict_boolean_type.d.ts.map +1 -1
- package/cjs/boolean/true_type.d.ts +0 -8
- package/cjs/boolean/true_type.d.ts.map +1 -1
- package/cjs/equal/equal.d.ts +4 -5
- package/cjs/equal/equal.d.ts.map +1 -1
- package/cjs/function/function_type.d.ts +0 -8
- package/cjs/function/function_type.d.ts.map +1 -1
- package/cjs/function/strict_function_type.d.ts +0 -8
- package/cjs/function/strict_function_type.d.ts.map +1 -1
- package/cjs/index.d.ts +2 -0
- package/cjs/index.d.ts.map +1 -1
- package/cjs/index.js.map +1 -1
- package/cjs/never/never_type.d.ts +2 -10
- package/cjs/never/never_type.d.ts.map +1 -1
- package/cjs/null/null_type.d.ts +4 -12
- package/cjs/null/null_type.d.ts.map +1 -1
- package/cjs/number/integer.d.ts +1 -9
- package/cjs/number/integer.d.ts.map +1 -1
- package/cjs/number/negative.d.ts +0 -8
- package/cjs/number/negative.d.ts.map +1 -1
- package/cjs/number/number_type.d.ts +0 -8
- package/cjs/number/number_type.d.ts.map +1 -1
- package/cjs/number/numeric_type.d.ts +0 -8
- package/cjs/number/numeric_type.d.ts.map +1 -1
- package/cjs/number/positive.d.ts +1 -9
- package/cjs/number/positive.d.ts.map +1 -1
- package/cjs/number/strict_number_type.d.ts +4 -12
- package/cjs/number/strict_number_type.d.ts.map +1 -1
- package/cjs/object/object_type.d.ts +1 -9
- package/cjs/object/object_type.d.ts.map +1 -1
- package/cjs/string/strict_string_type.d.ts +14 -19
- package/cjs/string/strict_string_type.d.ts.map +1 -1
- package/cjs/string/string.d.ts +24 -0
- package/cjs/string/string.d.ts.map +1 -0
- package/cjs/string/string.js +3 -0
- package/cjs/string/string.js.map +1 -0
- package/cjs/string/string_plus.d.ts +27 -0
- package/cjs/string/string_plus.d.ts.map +1 -0
- package/cjs/string/string_plus.js +3 -0
- package/cjs/string/string_plus.js.map +1 -0
- package/cjs/string/string_type.d.ts +4 -12
- package/cjs/string/string_type.d.ts.map +1 -1
- package/cjs/symbol/symbol_type.d.ts +5 -15
- package/cjs/symbol/symbol_type.d.ts.map +1 -1
- package/cjs/tuple/tuple_type.d.ts +0 -8
- package/cjs/tuple/tuple_type.d.ts.map +1 -1
- package/cjs/type/failed.d.ts +2 -3
- package/cjs/type/failed.d.ts.map +1 -1
- package/cjs/type/failed.js +0 -1
- package/cjs/type/failed.js.map +1 -1
- package/cjs/undefined/undefined_type.d.ts +4 -12
- package/cjs/undefined/undefined_type.d.ts.map +1 -1
- package/cjs/unknown/unknown_type.d.ts +4 -12
- package/cjs/unknown/unknown_type.d.ts.map +1 -1
- package/cjs/void/void_type.d.ts +0 -8
- package/cjs/void/void_type.d.ts.map +1 -1
- package/esm/any/any_or_never.d.ts +0 -2
- package/esm/any/any_or_never.d.ts.map +1 -1
- package/esm/any/any_type.d.ts +2 -6
- package/esm/any/any_type.d.ts.map +1 -1
- package/esm/array/array.d.ts +0 -4
- package/esm/array/array.d.ts.map +1 -1
- package/esm/array/array_index.d.ts +7 -10
- package/esm/array/array_index.d.ts.map +1 -1
- package/esm/array/array_type.d.ts +0 -8
- package/esm/array/array_type.d.ts.map +1 -1
- package/esm/bigint/bigint_type.d.ts +4 -12
- package/esm/bigint/bigint_type.d.ts.map +1 -1
- package/esm/bigint/strict_bigint_type.d.ts +4 -12
- package/esm/bigint/strict_bigint_type.d.ts.map +1 -1
- package/esm/boolean/boolean_type.d.ts +0 -8
- package/esm/boolean/boolean_type.d.ts.map +1 -1
- package/esm/boolean/false_type.d.ts +0 -8
- package/esm/boolean/false_type.d.ts.map +1 -1
- package/esm/boolean/strict_boolean_type.d.ts +0 -8
- package/esm/boolean/strict_boolean_type.d.ts.map +1 -1
- package/esm/boolean/true_type.d.ts +0 -8
- package/esm/boolean/true_type.d.ts.map +1 -1
- package/esm/equal/equal.d.ts +4 -5
- package/esm/equal/equal.d.ts.map +1 -1
- package/esm/function/function_type.d.ts +0 -8
- package/esm/function/function_type.d.ts.map +1 -1
- package/esm/function/strict_function_type.d.ts +0 -8
- package/esm/function/strict_function_type.d.ts.map +1 -1
- package/esm/index.d.ts +2 -0
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js.map +1 -1
- package/esm/never/never_type.d.ts +2 -10
- package/esm/never/never_type.d.ts.map +1 -1
- package/esm/null/null_type.d.ts +4 -12
- package/esm/null/null_type.d.ts.map +1 -1
- package/esm/number/integer.d.ts +1 -9
- package/esm/number/integer.d.ts.map +1 -1
- package/esm/number/negative.d.ts +0 -8
- package/esm/number/negative.d.ts.map +1 -1
- package/esm/number/number_type.d.ts +0 -8
- package/esm/number/number_type.d.ts.map +1 -1
- package/esm/number/numeric_type.d.ts +0 -8
- package/esm/number/numeric_type.d.ts.map +1 -1
- package/esm/number/positive.d.ts +1 -9
- package/esm/number/positive.d.ts.map +1 -1
- package/esm/number/strict_number_type.d.ts +4 -12
- package/esm/number/strict_number_type.d.ts.map +1 -1
- package/esm/object/object_type.d.ts +1 -9
- package/esm/object/object_type.d.ts.map +1 -1
- package/esm/string/strict_string_type.d.ts +14 -19
- package/esm/string/strict_string_type.d.ts.map +1 -1
- package/esm/string/string.d.ts +24 -0
- package/esm/string/string.d.ts.map +1 -0
- package/esm/string/string.js +2 -0
- package/esm/string/string.js.map +1 -0
- package/esm/string/string_plus.d.ts +27 -0
- package/esm/string/string_plus.d.ts.map +1 -0
- package/esm/string/string_plus.js +2 -0
- package/esm/string/string_plus.js.map +1 -0
- package/esm/string/string_type.d.ts +4 -12
- package/esm/string/string_type.d.ts.map +1 -1
- package/esm/symbol/symbol_type.d.ts +5 -15
- package/esm/symbol/symbol_type.d.ts.map +1 -1
- package/esm/tuple/tuple_type.d.ts +0 -8
- package/esm/tuple/tuple_type.d.ts.map +1 -1
- package/esm/type/failed.d.ts +2 -3
- package/esm/type/failed.d.ts.map +1 -1
- package/esm/type/failed.js +1 -1
- package/esm/type/failed.js.map +1 -1
- package/esm/undefined/undefined_type.d.ts +4 -12
- package/esm/undefined/undefined_type.d.ts.map +1 -1
- package/esm/unknown/unknown_type.d.ts +4 -12
- package/esm/unknown/unknown_type.d.ts.map +1 -1
- package/esm/void/void_type.d.ts +0 -8
- package/esm/void/void_type.d.ts.map +1 -1
- package/package.json +2 -2
- package/ts/any/any_or_never.ts +0 -2
- package/ts/any/any_type.ts +2 -6
- package/ts/array/array.ts +0 -4
- package/ts/array/array_index.ts +7 -10
- package/ts/array/array_type.ts +0 -8
- package/ts/bigint/bigint_type.ts +4 -12
- package/ts/bigint/strict_bigint_type.ts +4 -12
- package/ts/boolean/boolean_type.ts +0 -8
- package/ts/boolean/false_type.ts +0 -8
- package/ts/boolean/strict_boolean_type.ts +0 -8
- package/ts/boolean/true_type.ts +0 -8
- package/ts/equal/equal.ts +9 -5
- package/ts/equal/readme.md +3 -0
- package/ts/function/function_type.ts +0 -8
- package/ts/function/strict_function_type.ts +0 -8
- package/ts/index.ts +2 -0
- package/ts/never/never_type.ts +2 -10
- package/ts/null/null_type.ts +4 -12
- package/ts/number/integer.ts +1 -9
- package/ts/number/negative.ts +0 -8
- package/ts/number/number_type.ts +0 -8
- package/ts/number/numeric_type.ts +0 -8
- package/ts/number/positive.ts +1 -9
- package/ts/number/strict_number_type.ts +4 -12
- package/ts/object/object_type.ts +1 -9
- package/ts/string/readme.md +5 -0
- package/ts/string/strict_string_type.ts +15 -19
- package/ts/string/string.ts +36 -0
- package/ts/string/string_plus.ts +33 -0
- package/ts/string/string_type.ts +4 -12
- package/ts/symbol/symbol_type.ts +5 -17
- package/ts/tuple/tuple_type.ts +0 -8
- package/ts/type/failed.ts +1 -3
- package/ts/type/readme.md +22 -0
- package/ts/undefined/undefined_type.ts +4 -12
- package/ts/unknown/unknown_type.ts +4 -12
- package/ts/void/void_type.ts +0 -8
- package/cjs/type/constants.d.ts +0 -5
- package/cjs/type/constants.d.ts.map +0 -1
- package/cjs/type/constants.js +0 -8
- package/cjs/type/constants.js.map +0 -1
- package/esm/type/constants.d.ts +0 -5
- package/esm/type/constants.d.ts.map +0 -1
- package/esm/type/constants.js +0 -5
- package/esm/type/constants.js.map +0 -1
- package/ts/type/constants.ts +0 -4
package/ts/number/positive.ts
CHANGED
|
@@ -5,8 +5,6 @@ import { IsNever } from '../index.js'
|
|
|
5
5
|
* Check if `T` is a positive numeric type.
|
|
6
6
|
*
|
|
7
7
|
* ```ts
|
|
8
|
-
* import type { Positive } from 'type-plus'
|
|
9
|
-
*
|
|
10
8
|
* type R = Positive<1> // 1
|
|
11
9
|
* type R = Positive<0> // 0
|
|
12
10
|
* type R = Positive<1n> // 1n
|
|
@@ -24,15 +22,13 @@ export type Positive<T, Then = T, Else = never> = IsAny<
|
|
|
24
22
|
* Is `T` a positive numeric type.
|
|
25
23
|
*
|
|
26
24
|
* ```ts
|
|
27
|
-
* import type { IsPositive } from 'type-plus'
|
|
28
|
-
*
|
|
29
25
|
* type R = IsPositive<1> // true
|
|
30
26
|
* type R = IsPositive<0> // true
|
|
31
27
|
* type R = IsPositive<1n> // true
|
|
32
28
|
*
|
|
33
29
|
* type R = IsPositive<number> // boolean
|
|
34
30
|
* type R = IsPositive<bigint> // boolean
|
|
35
|
-
* type R =
|
|
31
|
+
* type R = IsPositive<any> // boolean
|
|
36
32
|
*
|
|
37
33
|
* type R = IsPositive<-1> // false
|
|
38
34
|
* ```
|
|
@@ -43,8 +39,6 @@ export type IsPositive<T, Then = true, Else = false> = Positive<T, Then, Else>
|
|
|
43
39
|
* Check if `T` is not a positive numeric type.
|
|
44
40
|
*
|
|
45
41
|
* ```ts
|
|
46
|
-
* import type { NonPositive } from 'type-plus'
|
|
47
|
-
*
|
|
48
42
|
* type R = NonPositive<-1> // -1
|
|
49
43
|
*
|
|
50
44
|
* type R = NonPositive<0> // never
|
|
@@ -57,8 +51,6 @@ export type NonPositive<T, Then = T, Else = never> = Positive<T, Else, Then>
|
|
|
57
51
|
* Is `T` not a positive numeric type.
|
|
58
52
|
*
|
|
59
53
|
* ```ts
|
|
60
|
-
* import type { IsNotPositive } from 'type-plus'
|
|
61
|
-
*
|
|
62
54
|
* type R = IsNotPositive<-1> // true
|
|
63
55
|
*
|
|
64
56
|
* type R = IsNotPositive<0> // false
|
|
@@ -4,8 +4,6 @@ import type { IsAny } from '../any/any_type.js'
|
|
|
4
4
|
* Check if the type `T` is exactly the type `number` and not numeric literals.
|
|
5
5
|
*
|
|
6
6
|
* ```ts
|
|
7
|
-
* import type { StrictNumberType } from 'type-plus'
|
|
8
|
-
*
|
|
9
7
|
* type R = StrictNumberType<number> // true
|
|
10
8
|
* type R = StrictNumberType<1> // false
|
|
11
9
|
*
|
|
@@ -23,8 +21,6 @@ export type StrictNumberType<T, Then = T, Else = never> = IsAny<
|
|
|
23
21
|
* Is the type `T` exactly the type `number` and not numeric literals.
|
|
24
22
|
*
|
|
25
23
|
* ```ts
|
|
26
|
-
* import type { IsStrictNumber } from 'type-plus'
|
|
27
|
-
*
|
|
28
24
|
* type R = IsStrictNumber<number> // true
|
|
29
25
|
* type R = IsStrictNumber<1> // false
|
|
30
26
|
*
|
|
@@ -38,13 +34,11 @@ export type IsStrictNumber<T, Then = true, Else = false> = StrictNumberType<T, T
|
|
|
38
34
|
* Check if the type `T` is not the type `number` or numeric literals.
|
|
39
35
|
*
|
|
40
36
|
* ```ts
|
|
41
|
-
*
|
|
37
|
+
* type R = NotStrictNumberType<number> // false
|
|
38
|
+
* type R = NotStrictNumberType<1> // true
|
|
42
39
|
*
|
|
43
|
-
* type R =
|
|
44
|
-
* type R =
|
|
45
|
-
*
|
|
46
|
-
* type R = NotStictNumberType<never> // true
|
|
47
|
-
* type R = NotStictNumberType<unknown> // true
|
|
40
|
+
* type R = NotStrictNumberType<never> // true
|
|
41
|
+
* type R = NotStrictNumberType<unknown> // true
|
|
48
42
|
* ```
|
|
49
43
|
*/
|
|
50
44
|
export type NotStrictNumberType<T, Then = T, Else = never> = StrictNumberType<T, Else, Then>
|
|
@@ -53,8 +47,6 @@ export type NotStrictNumberType<T, Then = T, Else = never> = StrictNumberType<T,
|
|
|
53
47
|
* Is the type `T` not the type `number` or numeric literals.
|
|
54
48
|
*
|
|
55
49
|
* ```ts
|
|
56
|
-
* import type { IsNotStrictNumber } from 'type-plus'
|
|
57
|
-
*
|
|
58
50
|
* type R = IsNotStrictNumber<number> // false
|
|
59
51
|
* type R = IsNotStrictNumber<1> // true
|
|
60
52
|
*
|
package/ts/object/object_type.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import { IsAnyOrNever } from '../any/any_or_never.js'
|
|
1
|
+
import type { IsAnyOrNever } from '../any/any_or_never.js'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Check if `T` is an `object`.
|
|
5
5
|
*
|
|
6
6
|
* ```ts
|
|
7
|
-
* import { type ObjectType } from 'type-plus'
|
|
8
|
-
*
|
|
9
7
|
* type R = ObjectType<{}> // {}
|
|
10
8
|
* type R = ObjectType<{ a: 1 }> // { a: 1 }
|
|
11
9
|
* type R = ObjectType<Function> // Function
|
|
@@ -21,8 +19,6 @@ export type ObjectType<T, Then = T, Else = never> = IsAnyOrNever<T, Else, [T] ex
|
|
|
21
19
|
* Note that `Function` is also an `object`.
|
|
22
20
|
*
|
|
23
21
|
* ```ts
|
|
24
|
-
* import { type IsObject } from 'type-plus'
|
|
25
|
-
*
|
|
26
22
|
* type R = IsObject<{}> // true
|
|
27
23
|
* type R = IsObject<{ a: 1 }> // true
|
|
28
24
|
* type R = IsObject<Function> // true
|
|
@@ -36,8 +32,6 @@ export type IsObject<T, Then = true, Else = false> = ObjectType<T, Then, Else>
|
|
|
36
32
|
* Check if `T` is not an `object`.
|
|
37
33
|
*
|
|
38
34
|
* ```ts
|
|
39
|
-
* import { type NotObjectType } from 'type-plus'
|
|
40
|
-
*
|
|
41
35
|
* type R = NotObjectType<{}> // never
|
|
42
36
|
* type R = NotObjectType<{ a: 1 }> // never
|
|
43
37
|
* type R = NotObjectType<Function> // never
|
|
@@ -53,8 +47,6 @@ export type NotObjectType<T, Then = T, Else = never> = ObjectType<T, Else, Then>
|
|
|
53
47
|
* Note that `Function` is also an `object`.
|
|
54
48
|
*
|
|
55
49
|
* ```ts
|
|
56
|
-
* import { type IsNotObject } from 'type-plus'
|
|
57
|
-
*
|
|
58
50
|
* type R = IsNotObject<{}> // false
|
|
59
51
|
* type R = IsNotObject<{ a: 1 }> // false
|
|
60
52
|
* type R = IsNotObject<Function> // false
|
package/ts/string/readme.md
CHANGED
|
@@ -36,6 +36,11 @@ type R = StrictStringType<1> // never
|
|
|
36
36
|
- [`NotStrictStringType<T, Then = T, Else = never>`](strict_string_type.ts#L52): check if `T` is not exactly `string`.
|
|
37
37
|
- [`IsNotStrictString<T, Then = true, Else = false>`](strict_string_type.ts#L69): is `T` not exactly `string`.
|
|
38
38
|
|
|
39
|
+
## String Utilities
|
|
40
|
+
|
|
41
|
+
- [`StringIncludes<Subject, Search, Then = true, Else = false>`](./string.ts): check if `Subject` includes `Search`.
|
|
42
|
+
- [`StringSplit<Subject, Separater>`](./string.ts): split `Subject` by `Separater`.
|
|
43
|
+
|
|
39
44
|
## References
|
|
40
45
|
|
|
41
46
|
- [Handbook]
|
|
@@ -3,26 +3,26 @@ import type { IsAny } from '../any/any_type.js'
|
|
|
3
3
|
/**
|
|
4
4
|
* Check if the type `T` is exactly `string`.
|
|
5
5
|
*
|
|
6
|
-
* ```
|
|
7
|
-
* import type { StrictStringType } from 'type-plus'
|
|
8
|
-
*
|
|
6
|
+
* ```ts
|
|
9
7
|
* type R = StrictStringType<string> // string
|
|
10
|
-
*
|
|
11
|
-
* type R = StrictStringType<''> // never
|
|
12
|
-
* type R = StrictStringType<'1'> // never
|
|
13
|
-
* type R = StrictStringType<string | boolean> // never
|
|
14
|
-
* type R = StrictStringType<never> // never
|
|
15
|
-
* type R = StrictStringType<unknown> // never
|
|
8
|
+
*
|
|
9
|
+
* type R = StrictStringType<''> // never
|
|
10
|
+
* type R = StrictStringType<'1'> // never
|
|
11
|
+
* type R = StrictStringType<string | boolean> // never
|
|
12
|
+
* type R = StrictStringType<never> // never
|
|
13
|
+
* type R = StrictStringType<unknown> // never
|
|
16
14
|
* ```
|
|
17
15
|
*/
|
|
18
|
-
export type StrictStringType<T, Then = T, Else = never> = IsAny<
|
|
16
|
+
export type StrictStringType<T, Then = T, Else = never> = IsAny<
|
|
17
|
+
T,
|
|
18
|
+
Else,
|
|
19
|
+
[T, string] extends [string, T] ? Then : Else
|
|
20
|
+
>
|
|
19
21
|
|
|
20
22
|
/**
|
|
21
23
|
* Is the type `T` exactly `string`.
|
|
22
24
|
*
|
|
23
|
-
* ```
|
|
24
|
-
* import type { IsStrictString } from 'type-plus'
|
|
25
|
-
*
|
|
25
|
+
* ```ts
|
|
26
26
|
* type R = IsStrictString<string> // true
|
|
27
27
|
*
|
|
28
28
|
* type R = IsStrictString<''> // false
|
|
@@ -37,9 +37,7 @@ export type IsStrictString<T, Then = true, Else = false> = StrictStringType<T, T
|
|
|
37
37
|
/**
|
|
38
38
|
* Check if the type `T` is not exactly `string`.
|
|
39
39
|
*
|
|
40
|
-
* ```
|
|
41
|
-
* import type { NotStrictStringType } from 'type-plus'
|
|
42
|
-
*
|
|
40
|
+
* ```ts
|
|
43
41
|
* type R = NotStrictStringType<string> // never
|
|
44
42
|
*
|
|
45
43
|
* type R = NotStrictStringType<''> // ''
|
|
@@ -54,9 +52,7 @@ export type NotStrictStringType<T, Then = T, Else = never> = StrictStringType<T,
|
|
|
54
52
|
/**
|
|
55
53
|
* Is the type `T` not exactly `string`.
|
|
56
54
|
*
|
|
57
|
-
* ```
|
|
58
|
-
* import type { IsNotStrictString } from 'type-plus'
|
|
59
|
-
*
|
|
55
|
+
* ```ts
|
|
60
56
|
* type R = IsNotStrictString<string> // false
|
|
61
57
|
*
|
|
62
58
|
* type R = IsNotStrictString<''> // true
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if `Subject` includes `Search`.
|
|
3
|
+
* If either of them is not a string, returns `Else`.
|
|
4
|
+
*
|
|
5
|
+
* ```ts
|
|
6
|
+
* type R = StringIncludes<'abc', 'a'> // true
|
|
7
|
+
*
|
|
8
|
+
* type R = StringIncludes<'abc', 'd'> // false
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
export type StringIncludes<
|
|
12
|
+
Subject extends string,
|
|
13
|
+
Search extends string,
|
|
14
|
+
Then = true,
|
|
15
|
+
Else = false
|
|
16
|
+
> = Subject extends `${infer _}${Search}${infer _}` ? Then : Else
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Split a string into substrings using the specified separator,
|
|
20
|
+
* and return them as an array.
|
|
21
|
+
*
|
|
22
|
+
* ```ts
|
|
23
|
+
* type R = StringSplit<'abc', ''> // ['a', 'b', 'c']
|
|
24
|
+
* type R = StringSplit<'abc', 'a'> // ['', 'bc']
|
|
25
|
+
* type R = StringSplit<'abc', 'b'> // ['a', 'c']
|
|
26
|
+
* type R = StringSplit<'abc', 'c'> // ['ab', '']
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export type StringSplit<
|
|
30
|
+
Subject extends string,
|
|
31
|
+
Seperator extends string
|
|
32
|
+
> = Subject extends `${infer A}${Seperator}${infer B}`
|
|
33
|
+
? [A, ...StringSplit<B, Seperator>]
|
|
34
|
+
: Seperator extends ''
|
|
35
|
+
? []
|
|
36
|
+
: [Subject]
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { StringIncludes, StringSplit } from './string.js'
|
|
2
|
+
|
|
3
|
+
export namespace StringPlus {
|
|
4
|
+
/**
|
|
5
|
+
* Check if `Subject` includes `Search`.
|
|
6
|
+
* If either of them is not a string, returns `Else`.
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* type R = StringPlus.Includes<'abc', 'a'> // true
|
|
10
|
+
*
|
|
11
|
+
* type R = StringPlus.Includes<'abc', 'd'> // false
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export type Includes<
|
|
15
|
+
Subject extends string,
|
|
16
|
+
Search extends string,
|
|
17
|
+
Then = true,
|
|
18
|
+
Else = false
|
|
19
|
+
> = StringIncludes<Subject, Search, Then, Else>
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Split a string into substrings using the specified separator,
|
|
23
|
+
* and return them as an array.
|
|
24
|
+
*
|
|
25
|
+
* ```ts
|
|
26
|
+
* type R = StringPlus.Split<'abc', ''> // ['a', 'b', 'c']
|
|
27
|
+
* type R = StringPlus.Split<'abc', 'a'> // ['', 'bc']
|
|
28
|
+
* type R = StringPlus.Split<'abc', 'b'> // ['a', 'c']
|
|
29
|
+
* type R = StringPlus.Split<'abc', 'c'> // ['ab', '']
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export type Split<Subject extends string, Seperator extends string> = StringSplit<Subject, Seperator>
|
|
33
|
+
}
|
package/ts/string/string_type.ts
CHANGED
|
@@ -3,9 +3,7 @@ import type { IsAnyOrNever } from '../any/any_or_never.js'
|
|
|
3
3
|
/**
|
|
4
4
|
* Check if the type `T` is `string` or string literals.
|
|
5
5
|
*
|
|
6
|
-
* ```
|
|
7
|
-
* import type { StringType } from 'type-plus'
|
|
8
|
-
*
|
|
6
|
+
* ```ts
|
|
9
7
|
* type R = StringType<string> // string
|
|
10
8
|
* type R = StringType<''> // ''
|
|
11
9
|
* type R = StringType<'1'> // '1'
|
|
@@ -20,9 +18,7 @@ export type StringType<T, Then = T, Else = never> = IsAnyOrNever<T, Else, [T] ex
|
|
|
20
18
|
/**
|
|
21
19
|
* Is the type `T` `string` or string literals.
|
|
22
20
|
*
|
|
23
|
-
* ```
|
|
24
|
-
* import type { IsString } from 'type-plus'
|
|
25
|
-
*
|
|
21
|
+
* ```ts
|
|
26
22
|
* type R = IsString<string> // true
|
|
27
23
|
* type R = IsString<''> // true
|
|
28
24
|
* type R = IsString<'a'> // true
|
|
@@ -37,9 +33,7 @@ export type IsString<T, Then = true, Else = false> = StringType<T, Then, Else>
|
|
|
37
33
|
/**
|
|
38
34
|
* Check if the type `T` is not `string` nor string literals.
|
|
39
35
|
*
|
|
40
|
-
* ```
|
|
41
|
-
* import type { NotStringType } from 'type-plus'
|
|
42
|
-
*
|
|
36
|
+
* ```ts
|
|
43
37
|
* type R = NotStringType<string> // never
|
|
44
38
|
* type R = NotStringType<''> // ''
|
|
45
39
|
* type R = NotStringType<'a'> // 'a'
|
|
@@ -54,9 +48,7 @@ export type NotStringType<T, Then = T, Else = never> = StringType<T, Else, Then>
|
|
|
54
48
|
/**
|
|
55
49
|
* Is the type `T` not `string` nor string literals.
|
|
56
50
|
*
|
|
57
|
-
* ```
|
|
58
|
-
* import type { IsNotString } from 'type-plus'
|
|
59
|
-
*
|
|
51
|
+
* ```ts
|
|
60
52
|
* type R = IsNotString<string> // false
|
|
61
53
|
* type R = IsNotString<''> // false
|
|
62
54
|
* type R = IsNotString<'a'> // false
|
package/ts/symbol/symbol_type.ts
CHANGED
|
@@ -3,9 +3,7 @@ import type { IsAnyOrNever } from '../any/any_or_never.js'
|
|
|
3
3
|
/**
|
|
4
4
|
* Check if the type `T` is exactly `symbol`.
|
|
5
5
|
*
|
|
6
|
-
* ```
|
|
7
|
-
* import type { SymbolType } from 'type-plus'
|
|
8
|
-
*
|
|
6
|
+
* ```ts
|
|
9
7
|
* type R = SymbolType<symbol> // symbol
|
|
10
8
|
*
|
|
11
9
|
* type R = SymbolType<never> // never
|
|
@@ -13,18 +11,12 @@ import type { IsAnyOrNever } from '../any/any_or_never.js'
|
|
|
13
11
|
* type R = SymbolType<symbol | boolean> // never
|
|
14
12
|
* ```
|
|
15
13
|
*/
|
|
16
|
-
export type SymbolType<T, Then = T, Else = never> = IsAnyOrNever<
|
|
17
|
-
T,
|
|
18
|
-
Else,
|
|
19
|
-
[T] extends [symbol] ? Then : Else
|
|
20
|
-
>
|
|
14
|
+
export type SymbolType<T, Then = T, Else = never> = IsAnyOrNever<T, Else, [T] extends [symbol] ? Then : Else>
|
|
21
15
|
|
|
22
16
|
/**
|
|
23
17
|
* Is the type `T` exactly `symbol`.
|
|
24
18
|
*
|
|
25
|
-
* ```
|
|
26
|
-
* import type { IsSymbol } from 'type-plus'
|
|
27
|
-
*
|
|
19
|
+
* ```ts
|
|
28
20
|
* type R = IsSymbol<symbol> // true
|
|
29
21
|
*
|
|
30
22
|
* type R = IsSymbol<never> // false
|
|
@@ -37,9 +29,7 @@ export type IsSymbol<T, Then = true, Else = false> = SymbolType<T, Then, Else>
|
|
|
37
29
|
/**
|
|
38
30
|
* Check if the type `T` is not `symbol`.
|
|
39
31
|
*
|
|
40
|
-
* ```
|
|
41
|
-
* import type { NotSymbolType } from 'type-plus'
|
|
42
|
-
*
|
|
32
|
+
* ```ts
|
|
43
33
|
* type R = NotSymbolType<symbol> // never
|
|
44
34
|
*
|
|
45
35
|
* type R = NotSymbolType<never> // never
|
|
@@ -52,9 +42,7 @@ export type NotSymbolType<T, Then = T, Else = never> = SymbolType<T, Else, Then>
|
|
|
52
42
|
/**
|
|
53
43
|
* Is the type `T` not `symbol`.
|
|
54
44
|
*
|
|
55
|
-
* ```
|
|
56
|
-
* import type { IsNotSymbol } from 'type-plus'
|
|
57
|
-
*
|
|
45
|
+
* ```ts
|
|
58
46
|
* type R = IsNotSymbol<symbol> // false
|
|
59
47
|
*
|
|
60
48
|
* type R = IsNotSymbol<never> // true
|
package/ts/tuple/tuple_type.ts
CHANGED
|
@@ -4,8 +4,6 @@ import type { IsNever } from '../never/never_type.js'
|
|
|
4
4
|
* Check if `T` is a tuple and not an array.
|
|
5
5
|
*
|
|
6
6
|
* ```ts
|
|
7
|
-
* import type { TupleType } from 'type-plus'
|
|
8
|
-
*
|
|
9
7
|
* type R = TupleType<[]> // []
|
|
10
8
|
* type R = TupleType<[1]> // [1]
|
|
11
9
|
*
|
|
@@ -25,8 +23,6 @@ export type TupleType<T, Then = T, Else = never> = IsNever<
|
|
|
25
23
|
* Check if `T` is not a tuple.
|
|
26
24
|
*
|
|
27
25
|
* ```ts
|
|
28
|
-
* import type { NotTupleType } from 'type-plus'
|
|
29
|
-
*
|
|
30
26
|
* type R = NotTupleType<[]> // never
|
|
31
27
|
* type R = NotTupleType<[1]> // never
|
|
32
28
|
*
|
|
@@ -42,8 +38,6 @@ export type NotTupleType<T, Then = T, Else = never> = TupleType<T, Else, Then>
|
|
|
42
38
|
* Is `T` a tuple and not an array.
|
|
43
39
|
*
|
|
44
40
|
* ```ts
|
|
45
|
-
* import type { IsTuple } from 'type-plus'
|
|
46
|
-
*
|
|
47
41
|
* type R = IsTuple<[]> // true
|
|
48
42
|
*
|
|
49
43
|
* type R = IsTuple<number[]> // false
|
|
@@ -58,8 +52,6 @@ export type IsTuple<T, Then = true, Else = false> = TupleType<T, Then, Else>
|
|
|
58
52
|
* Is `T` not a tuple.
|
|
59
53
|
*
|
|
60
54
|
* ```ts
|
|
61
|
-
* import type { IsNotTuple } from 'type-plus'
|
|
62
|
-
*
|
|
63
55
|
* type R = IsNotTuple<[]> // false
|
|
64
56
|
* type R = IsNotTuple<[1]> // false
|
|
65
57
|
*
|
package/ts/type/failed.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
declare const uniSym: unique symbol
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* A failed type with message.
|
|
@@ -11,8 +11,6 @@ import { uniSym } from './constants.js'
|
|
|
11
11
|
* use `FailedT` or create your own failed type instead.
|
|
12
12
|
*
|
|
13
13
|
* ```ts
|
|
14
|
-
* import { Failed } from 'type-plus'
|
|
15
|
-
*
|
|
16
14
|
* type T = Failed<'error message'>
|
|
17
15
|
* ```
|
|
18
16
|
*/
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# type
|
|
2
|
+
|
|
3
|
+
General type utilities.
|
|
4
|
+
|
|
5
|
+
## Failed
|
|
6
|
+
|
|
7
|
+
`Failed<Msg>` is a type to describe a failure.
|
|
8
|
+
|
|
9
|
+
Use the same concept to create your own failure types.
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { type Failed } from 'type-plus'
|
|
13
|
+
|
|
14
|
+
type YourComplexType<A,B,C> = A extends B ?
|
|
15
|
+
... // and many more hard work later...
|
|
16
|
+
: Failed<'you are doing something wrong!'>
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
[![Just Code: I failed][failed-type]][failed-type-url]
|
|
20
|
+
|
|
21
|
+
[failed-type]: https://img.youtube.com/vi/3pEXVe6KJO4/0.jpg
|
|
22
|
+
[failed-type-url]: https://www.youtube.com/live/3pEXVe6KJO4
|
|
@@ -3,9 +3,7 @@ import type { IsAny } from '../any/any_type.js'
|
|
|
3
3
|
/**
|
|
4
4
|
* Check if the type `T` is exactly `undefined`.
|
|
5
5
|
*
|
|
6
|
-
* ```
|
|
7
|
-
* import type { UndefinedType } from 'type-plus'
|
|
8
|
-
*
|
|
6
|
+
* ```ts
|
|
9
7
|
* type R = UndefinedType<undefined> // undefined
|
|
10
8
|
*
|
|
11
9
|
* type R = UndefinedType<never> // never
|
|
@@ -22,9 +20,7 @@ export type UndefinedType<T, Then = T, Else = never> = IsAny<
|
|
|
22
20
|
/**
|
|
23
21
|
* Is the type `T` exactly `undefined`.
|
|
24
22
|
*
|
|
25
|
-
* ```
|
|
26
|
-
* import type { IsUndefined } from 'type-plus'
|
|
27
|
-
*
|
|
23
|
+
* ```ts
|
|
28
24
|
* type R = IsUndefined<undefined> // true
|
|
29
25
|
*
|
|
30
26
|
* type R = IsUndefined<never> // false
|
|
@@ -37,9 +33,7 @@ export type IsUndefined<T, Then = true, Else = false> = UndefinedType<T, Then, E
|
|
|
37
33
|
/**
|
|
38
34
|
* Check if the type `T` is not `undefined`.
|
|
39
35
|
*
|
|
40
|
-
* ```
|
|
41
|
-
* import type { NotUndefinedType } from 'type-plus'
|
|
42
|
-
*
|
|
36
|
+
* ```ts
|
|
43
37
|
* type R = NotUndefinedType<undefined> // never
|
|
44
38
|
*
|
|
45
39
|
* type R = NotUndefinedType<never> // never
|
|
@@ -52,9 +46,7 @@ export type NotUndefinedType<T, Then = T, Else = never> = UndefinedType<T, Else,
|
|
|
52
46
|
/**
|
|
53
47
|
* Is the type `T` not `undefined`.
|
|
54
48
|
*
|
|
55
|
-
* ```
|
|
56
|
-
* import type { IsNotUndefined } from 'type-plus'
|
|
57
|
-
*
|
|
49
|
+
* ```ts
|
|
58
50
|
* type R = IsNotUndefined<undefined> // false
|
|
59
51
|
*
|
|
60
52
|
* type R = IsNotUndefined<never> // true
|
|
@@ -3,9 +3,7 @@ import type { IsAny } from '../any/any_type.js'
|
|
|
3
3
|
/**
|
|
4
4
|
* Check if the type `T` is exactly `unknown`.
|
|
5
5
|
*
|
|
6
|
-
* ```
|
|
7
|
-
* import type { UnknownType } from 'type-plus'
|
|
8
|
-
*
|
|
6
|
+
* ```ts
|
|
9
7
|
* type R = UnknownType<unknown> // unknown
|
|
10
8
|
*
|
|
11
9
|
* type R = UnknownType<number> // never
|
|
@@ -21,9 +19,7 @@ export type UnknownType<T, Then = T, Else = never> = IsAny<
|
|
|
21
19
|
/**
|
|
22
20
|
* Is the type `T` exactly `unknown`.
|
|
23
21
|
*
|
|
24
|
-
* ```
|
|
25
|
-
* import type { IsUnknown } from 'type-plus'
|
|
26
|
-
*
|
|
22
|
+
* ```ts
|
|
27
23
|
* type R = IsUnknown<unknown> // true
|
|
28
24
|
*
|
|
29
25
|
* type R = IsUnknown<number> // false
|
|
@@ -35,9 +31,7 @@ export type IsUnknown<T, Then = true, Else = false> = UnknownType<T, Then, Else>
|
|
|
35
31
|
/**
|
|
36
32
|
* Check if the type `T` is not `unknown`.
|
|
37
33
|
*
|
|
38
|
-
* ```
|
|
39
|
-
* import type { NotUnknownType } from 'type-plus'
|
|
40
|
-
*
|
|
34
|
+
* ```ts
|
|
41
35
|
* type R = NotUnknownType<unknown> // never
|
|
42
36
|
*
|
|
43
37
|
* type R = NotUnknownType<never> // never
|
|
@@ -50,9 +44,7 @@ export type NotUnknownType<T, Then = T, Else = never> = UnknownType<T, Else, The
|
|
|
50
44
|
/**
|
|
51
45
|
* Is the type `T` not exactly `unknown`.
|
|
52
46
|
*
|
|
53
|
-
* ```
|
|
54
|
-
* import type { IsNotUnknown } from 'type-plus'
|
|
55
|
-
*
|
|
47
|
+
* ```ts
|
|
56
48
|
* type R = IsNotUnknown<unknown> // false
|
|
57
49
|
*
|
|
58
50
|
* type R = IsNotUnknown<never> // true
|
package/ts/void/void_type.ts
CHANGED
|
@@ -5,8 +5,6 @@ import type { IsUndefined } from '../undefined/undefined_type.js'
|
|
|
5
5
|
* Check if `T` is `void`.
|
|
6
6
|
*
|
|
7
7
|
* ```ts
|
|
8
|
-
* import type { VoidType } from 'type-plus'
|
|
9
|
-
*
|
|
10
8
|
* type R = VoidType<void> // void
|
|
11
9
|
*
|
|
12
10
|
* type R = VoidType<1> // never
|
|
@@ -22,8 +20,6 @@ export type VoidType<T, Then = T, Else = never> = IsAnyOrNever<
|
|
|
22
20
|
* Check if `T` is not `void`.
|
|
23
21
|
*
|
|
24
22
|
* ```ts
|
|
25
|
-
* import type { VoidType } from 'type-plus'
|
|
26
|
-
*
|
|
27
23
|
* type R = VoidType<void> // never
|
|
28
24
|
*
|
|
29
25
|
* type R = VoidType<1> // 1
|
|
@@ -35,8 +31,6 @@ export type NotVoidType<T, Then = T, Else = never> = VoidType<T, Else, Then>
|
|
|
35
31
|
* Is `T` `void`.
|
|
36
32
|
*
|
|
37
33
|
* ```ts
|
|
38
|
-
* import type { IsVoid } from 'type-plus'
|
|
39
|
-
*
|
|
40
34
|
* type R = IsVoid<void> // true
|
|
41
35
|
*
|
|
42
36
|
* type R = IsVoid<1> // false
|
|
@@ -48,8 +42,6 @@ export type IsVoid<T, Then = true, Else = false> = VoidType<T, Then, Else>
|
|
|
48
42
|
* Is `T` not `void`.
|
|
49
43
|
*
|
|
50
44
|
* ```ts
|
|
51
|
-
* import type { IsNotVoid } from 'type-plus'
|
|
52
|
-
*
|
|
53
45
|
* type R = IsNotVoid<void> // false
|
|
54
46
|
*
|
|
55
47
|
* type R = IsNotVoid<1> // true
|
package/cjs/type/constants.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../ts/type/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,MAAM,eAAsB,CAAA"}
|
package/cjs/type/constants.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../ts/type/constants.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACU,QAAA,MAAM,GAAG,MAAM,CAAC,WAAW,CAAC,CAAA"}
|
package/esm/type/constants.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../ts/type/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,MAAM,eAAsB,CAAA"}
|
package/esm/type/constants.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../ts/type/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,MAAM,CAAC,WAAW,CAAC,CAAA"}
|
package/ts/type/constants.ts
DELETED