type-plus 7.4.0 → 7.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.
Files changed (202) hide show
  1. package/README.md +81 -92
  2. package/cjs/array/array.entries.d.ts +4 -3
  3. package/cjs/array/array.entries.d.ts.map +1 -1
  4. package/cjs/array/array_index.d.ts +4 -1
  5. package/cjs/array/array_index.d.ts.map +1 -1
  6. package/cjs/array/array_plus.common_prop_keys.d.ts +27 -0
  7. package/cjs/array/array_plus.common_prop_keys.d.ts.map +1 -0
  8. package/cjs/array/array_plus.common_prop_keys.js +3 -0
  9. package/cjs/array/array_plus.common_prop_keys.js.map +1 -0
  10. package/cjs/array/array_plus.d.ts +6 -3
  11. package/cjs/array/array_plus.d.ts.map +1 -1
  12. package/cjs/array/array_plus.drop_match.d.ts +4 -0
  13. package/cjs/array/array_plus.drop_match.d.ts.map +1 -0
  14. package/cjs/array/array_plus.drop_match.js +3 -0
  15. package/cjs/array/array_plus.drop_match.js.map +1 -0
  16. package/cjs/array/array_plus.element_match.d.ts +44 -0
  17. package/cjs/array/array_plus.element_match.d.ts.map +1 -0
  18. package/cjs/array/array_plus.element_match.js +3 -0
  19. package/cjs/array/array_plus.element_match.js.map +1 -0
  20. package/cjs/array/array_plus.find.d.ts +57 -0
  21. package/cjs/array/array_plus.find.d.ts.map +1 -0
  22. package/cjs/array/array_plus.find.js +3 -0
  23. package/cjs/array/array_plus.find.js.map +1 -0
  24. package/cjs/array/array_plus.split_at.d.ts +20 -15
  25. package/cjs/array/array_plus.split_at.d.ts.map +1 -1
  26. package/cjs/array/find_first.d.ts +62 -0
  27. package/cjs/array/find_first.d.ts.map +1 -0
  28. package/cjs/array/{array.find.js → find_first.js} +1 -1
  29. package/cjs/array/find_first.js.map +1 -0
  30. package/cjs/array/head.d.ts +18 -6
  31. package/cjs/array/head.d.ts.map +1 -1
  32. package/cjs/array/last.d.ts +17 -6
  33. package/cjs/array/last.d.ts.map +1 -1
  34. package/cjs/assertion/assert_type.d.ts +4 -1
  35. package/cjs/assertion/assert_type.d.ts.map +1 -1
  36. package/cjs/assertion/assert_type.js.map +1 -1
  37. package/cjs/index.d.ts +5 -2
  38. package/cjs/index.d.ts.map +1 -1
  39. package/cjs/index.js.map +1 -1
  40. package/cjs/never/never_type.d.ts +11 -0
  41. package/cjs/never/never_type.d.ts.map +1 -1
  42. package/cjs/object/index.d.ts +0 -1
  43. package/cjs/object/index.d.ts.map +1 -1
  44. package/cjs/object/index.js.map +1 -1
  45. package/cjs/testing/test_type.d.ts +277 -276
  46. package/cjs/testing/test_type.d.ts.map +1 -1
  47. package/cjs/testing/test_type.js.map +1 -1
  48. package/cjs/tuple/common_prop_keys.d.ts +15 -10
  49. package/cjs/tuple/common_prop_keys.d.ts.map +1 -1
  50. package/cjs/tuple/drop.d.ts +45 -26
  51. package/cjs/tuple/drop.d.ts.map +1 -1
  52. package/cjs/tuple/drop.js.map +1 -1
  53. package/cjs/tuple/tuple_plus.common_prop_keys.d.ts +28 -0
  54. package/cjs/tuple/tuple_plus.common_prop_keys.d.ts.map +1 -0
  55. package/cjs/tuple/tuple_plus.common_prop_keys.js +3 -0
  56. package/cjs/tuple/tuple_plus.common_prop_keys.js.map +1 -0
  57. package/cjs/tuple/tuple_plus.d.ts +3 -0
  58. package/cjs/tuple/tuple_plus.d.ts.map +1 -1
  59. package/cjs/tuple/tuple_plus.drop_match.d.ts +6 -0
  60. package/cjs/tuple/tuple_plus.drop_match.d.ts.map +1 -0
  61. package/cjs/tuple/tuple_plus.drop_match.js +3 -0
  62. package/cjs/tuple/tuple_plus.drop_match.js.map +1 -0
  63. package/cjs/tuple/tuple_plus.filter.d.ts +2 -2
  64. package/cjs/tuple/tuple_plus.find.d.ts +64 -0
  65. package/cjs/tuple/tuple_plus.find.d.ts.map +1 -0
  66. package/cjs/tuple/tuple_plus.find.js +3 -0
  67. package/cjs/tuple/tuple_plus.find.js.map +1 -0
  68. package/cjs/tuple/tuple_plus.pad_start.d.ts +7 -6
  69. package/cjs/tuple/tuple_plus.pad_start.d.ts.map +1 -1
  70. package/cjs/tuple/tuple_type.d.ts +41 -23
  71. package/cjs/tuple/tuple_type.d.ts.map +1 -1
  72. package/cjs/union/union.d.ts +33 -0
  73. package/cjs/union/union.d.ts.map +1 -0
  74. package/cjs/union/union.js +3 -0
  75. package/cjs/union/union.js.map +1 -0
  76. package/cjs/unknown/unknown_type.d.ts +12 -0
  77. package/cjs/unknown/unknown_type.d.ts.map +1 -1
  78. package/cjs/utils/options.d.ts +10 -0
  79. package/cjs/utils/options.d.ts.map +1 -0
  80. package/cjs/utils/options.js +3 -0
  81. package/cjs/utils/options.js.map +1 -0
  82. package/esm/array/array.entries.d.ts +4 -3
  83. package/esm/array/array.entries.d.ts.map +1 -1
  84. package/esm/array/array_index.d.ts +4 -1
  85. package/esm/array/array_index.d.ts.map +1 -1
  86. package/esm/array/array_plus.common_prop_keys.d.ts +27 -0
  87. package/esm/array/array_plus.common_prop_keys.d.ts.map +1 -0
  88. package/esm/array/array_plus.common_prop_keys.js +2 -0
  89. package/esm/array/array_plus.common_prop_keys.js.map +1 -0
  90. package/esm/array/array_plus.d.ts +6 -3
  91. package/esm/array/array_plus.d.ts.map +1 -1
  92. package/esm/array/array_plus.drop_match.d.ts +4 -0
  93. package/esm/array/array_plus.drop_match.d.ts.map +1 -0
  94. package/esm/array/array_plus.drop_match.js +2 -0
  95. package/esm/array/array_plus.drop_match.js.map +1 -0
  96. package/esm/array/array_plus.element_match.d.ts +44 -0
  97. package/esm/array/array_plus.element_match.d.ts.map +1 -0
  98. package/esm/array/array_plus.element_match.js +2 -0
  99. package/esm/array/array_plus.element_match.js.map +1 -0
  100. package/esm/array/array_plus.find.d.ts +57 -0
  101. package/esm/array/array_plus.find.d.ts.map +1 -0
  102. package/esm/array/array_plus.find.js +2 -0
  103. package/esm/array/array_plus.find.js.map +1 -0
  104. package/esm/array/array_plus.split_at.d.ts +20 -15
  105. package/esm/array/array_plus.split_at.d.ts.map +1 -1
  106. package/esm/array/find_first.d.ts +62 -0
  107. package/esm/array/find_first.d.ts.map +1 -0
  108. package/esm/array/find_first.js +2 -0
  109. package/esm/array/find_first.js.map +1 -0
  110. package/esm/array/head.d.ts +18 -6
  111. package/esm/array/head.d.ts.map +1 -1
  112. package/esm/array/last.d.ts +17 -6
  113. package/esm/array/last.d.ts.map +1 -1
  114. package/esm/assertion/assert_type.d.ts +4 -1
  115. package/esm/assertion/assert_type.d.ts.map +1 -1
  116. package/esm/assertion/assert_type.js.map +1 -1
  117. package/esm/index.d.ts +5 -2
  118. package/esm/index.d.ts.map +1 -1
  119. package/esm/index.js.map +1 -1
  120. package/esm/never/never_type.d.ts +11 -0
  121. package/esm/never/never_type.d.ts.map +1 -1
  122. package/esm/object/index.d.ts +0 -1
  123. package/esm/object/index.d.ts.map +1 -1
  124. package/esm/object/index.js.map +1 -1
  125. package/esm/testing/test_type.d.ts +277 -276
  126. package/esm/testing/test_type.d.ts.map +1 -1
  127. package/esm/testing/test_type.js.map +1 -1
  128. package/esm/tuple/common_prop_keys.d.ts +15 -10
  129. package/esm/tuple/common_prop_keys.d.ts.map +1 -1
  130. package/esm/tuple/drop.d.ts +45 -26
  131. package/esm/tuple/drop.d.ts.map +1 -1
  132. package/esm/tuple/drop.js.map +1 -1
  133. package/esm/tuple/tuple_plus.common_prop_keys.d.ts +28 -0
  134. package/esm/tuple/tuple_plus.common_prop_keys.d.ts.map +1 -0
  135. package/esm/tuple/tuple_plus.common_prop_keys.js +2 -0
  136. package/esm/tuple/tuple_plus.common_prop_keys.js.map +1 -0
  137. package/esm/tuple/tuple_plus.d.ts +3 -0
  138. package/esm/tuple/tuple_plus.d.ts.map +1 -1
  139. package/esm/tuple/tuple_plus.drop_match.d.ts +6 -0
  140. package/esm/tuple/tuple_plus.drop_match.d.ts.map +1 -0
  141. package/esm/tuple/tuple_plus.drop_match.js +2 -0
  142. package/esm/tuple/tuple_plus.drop_match.js.map +1 -0
  143. package/esm/tuple/tuple_plus.filter.d.ts +2 -2
  144. package/esm/tuple/tuple_plus.find.d.ts +64 -0
  145. package/esm/tuple/tuple_plus.find.d.ts.map +1 -0
  146. package/esm/tuple/tuple_plus.find.js +2 -0
  147. package/esm/tuple/tuple_plus.find.js.map +1 -0
  148. package/esm/tuple/tuple_plus.pad_start.d.ts +7 -6
  149. package/esm/tuple/tuple_plus.pad_start.d.ts.map +1 -1
  150. package/esm/tuple/tuple_type.d.ts +41 -23
  151. package/esm/tuple/tuple_type.d.ts.map +1 -1
  152. package/esm/union/union.d.ts +33 -0
  153. package/esm/union/union.d.ts.map +1 -0
  154. package/esm/union/union.js +2 -0
  155. package/esm/union/union.js.map +1 -0
  156. package/esm/unknown/unknown_type.d.ts +12 -0
  157. package/esm/unknown/unknown_type.d.ts.map +1 -1
  158. package/esm/utils/options.d.ts +10 -0
  159. package/esm/utils/options.d.ts.map +1 -0
  160. package/esm/utils/options.js +2 -0
  161. package/esm/utils/options.js.map +1 -0
  162. package/package.json +12 -1
  163. package/ts/array/array.entries.ts +4 -2
  164. package/ts/array/array_index.ts +33 -23
  165. package/ts/array/array_plus.common_prop_keys.ts +35 -0
  166. package/ts/array/array_plus.drop_match.ts +16 -0
  167. package/ts/array/array_plus.element_match.ts +61 -0
  168. package/ts/array/array_plus.find.ts +71 -0
  169. package/ts/array/array_plus.split_at.ts +52 -23
  170. package/ts/array/array_plus.ts +6 -3
  171. package/ts/array/find_first.ts +71 -0
  172. package/ts/array/head.ts +28 -6
  173. package/ts/array/last.ts +26 -6
  174. package/ts/array/readme.md +152 -32
  175. package/ts/assertion/assert_type.ts +4 -1
  176. package/ts/assertion/readme.md +3 -2
  177. package/ts/index.ts +5 -5
  178. package/ts/never/never_type.ts +13 -0
  179. package/ts/object/index.ts +0 -1
  180. package/ts/testing/test_type.ts +279 -277
  181. package/ts/tuple/common_prop_keys.ts +18 -32
  182. package/ts/tuple/drop.ts +61 -60
  183. package/ts/tuple/readme.md +178 -39
  184. package/ts/tuple/tuple_plus.common_prop_keys.ts +47 -0
  185. package/ts/tuple/tuple_plus.drop_match.ts +20 -0
  186. package/ts/tuple/tuple_plus.filter.ts +2 -2
  187. package/ts/tuple/tuple_plus.find.ts +88 -0
  188. package/ts/tuple/tuple_plus.pad_start.ts +28 -25
  189. package/ts/tuple/tuple_plus.ts +3 -0
  190. package/ts/tuple/tuple_type.ts +67 -25
  191. package/ts/union/readme.md +81 -0
  192. package/ts/union/union.ts +37 -0
  193. package/ts/unknown/unknown_type.ts +13 -0
  194. package/ts/utils/options.ts +10 -0
  195. package/cjs/array/array.find.d.ts +0 -23
  196. package/cjs/array/array.find.d.ts.map +0 -1
  197. package/cjs/array/array.find.js.map +0 -1
  198. package/esm/array/array.find.d.ts +0 -23
  199. package/esm/array/array.find.d.ts.map +0 -1
  200. package/esm/array/array.find.js +0 -2
  201. package/esm/array/array.find.js.map +0 -1
  202. package/ts/array/array.find.ts +0 -34
@@ -17,39 +17,42 @@
17
17
  * PadStart<[1, 2, 3], 5> // [unknown, unknown, 1, 2, 3]
18
18
  * ```
19
19
  */
20
- export type PadStart<Tuple extends unknown[], MaxLength extends number, PadWith = unknown> = PadStartDevice<
20
+ export type PadStart<Tuple extends unknown[], MaxLength extends number, PadWith = unknown> = PadStart.Device<
21
21
  Tuple,
22
22
  MaxLength,
23
23
  PadWith,
24
24
  []
25
25
  >
26
26
 
27
- type PadStartDevice<
28
- Source extends unknown[],
29
- MaxLength extends number,
30
- PadWith,
31
- Result extends unknown[]
32
- > =
33
- Result['length'] extends MaxLength
34
- ? (
35
- Source extends []
36
- ? Result
37
- : (
38
- Source extends [...infer Head, infer Tail]
39
- ? (
40
- [Tail, ...Result] extends infer R extends unknown[]
41
- ? PadStartDevice<Head, R['length'], PadWith, R>
27
+ export namespace PadStart {
28
+ export type Device<
29
+ Source extends unknown[],
30
+ MaxLength extends number,
31
+ PadWith,
32
+ Result extends unknown[]
33
+ > =
34
+ Result['length'] extends MaxLength
35
+ ? (
36
+ Source extends []
37
+ ? Result
38
+ : (
39
+ Source extends [...infer Head, infer Tail]
40
+ ? (
41
+ [Tail, ...Result] extends infer R extends unknown[]
42
+ ? Device<Head, R['length'], PadWith, R>
43
+ : never
44
+ )
42
45
  : never
43
46
  )
44
- : never
45
47
  )
46
- )
47
- : (
48
- Source extends []
49
- ? PadStartDevice<Source, MaxLength, PadWith, [PadWith, ...Result]>
50
48
  : (
51
- Source extends [...infer Head, infer Tail]
52
- ? PadStartDevice<Head, MaxLength, PadWith, [Tail, ...Result]>
53
- : Source
49
+ Source extends []
50
+ ? Device<Source, MaxLength, PadWith, [PadWith, ...Result]>
51
+ : (
52
+ Source extends [...infer Head, infer Tail]
53
+ ? Device<Head, MaxLength, PadWith, [Tail, ...Result]>
54
+ : Source
55
+ )
54
56
  )
55
- )
57
+
58
+ }
@@ -1,2 +1,5 @@
1
+ export type { CommonPropKeys } from './tuple_plus.common_prop_keys.js'
2
+ export type { DropMatch } from './tuple_plus.drop_match.js'
1
3
  export type { Filter } from './tuple_plus.filter.js'
4
+ export type { Find } from './tuple_plus.find.js'
2
5
  export type { PadStart } from './tuple_plus.pad_start.js'
@@ -1,8 +1,13 @@
1
- import type { IsNever } from '../never/never_type.js'
1
+ import type { IsNever, NeverType } from '../never/never_type.js'
2
2
 
3
3
  /**
4
- * Check if `T` is a tuple and not an array.
4
+ * 🌪️ *filter*
5
5
  *
6
+ * Filter `T` to ensure it is a tuple, excluding array.
7
+ *
8
+ * @typeParam Cases['never'] Return type when `T` is `never`. Default to `Else`.
9
+ *
10
+ * @example
6
11
  * ```ts
7
12
  * type R = TupleType<[]> // []
8
13
  * type R = TupleType<[1]> // [1]
@@ -13,52 +18,89 @@ import type { IsNever } from '../never/never_type.js'
13
18
  * type R = TupleType<unknown> // never
14
19
  * ```
15
20
  */
16
- export type TupleType<T, Then = T, Else = never> = IsNever<
21
+ export type TupleType<
22
+ T,
23
+ Then = T,
24
+ Else = never,
25
+ Options extends TupleType.Options = TupleType.DefaultOptions<Else>
26
+ > = IsNever<
17
27
  T,
18
- Else,
28
+ Options['caseNever'],
19
29
  [T] extends [any[]] ? (number extends T['length'] ? Else : Then) : Else
20
30
  >
21
31
 
32
+ export namespace TupleType {
33
+ export interface Options extends NeverType.Options {
34
+ }
35
+
36
+ export interface DefaultOptions<Else> {
37
+ caseNever: Else
38
+ }
39
+ }
40
+
41
+
22
42
  /**
23
- * Check if `T` is not a tuple.
43
+ * 🎭 *validate*
44
+ *
45
+ * Validate that `T` is a tuple, excluding array.
24
46
  *
25
47
  * ```ts
26
- * type R = NotTupleType<[]> // never
27
- * type R = NotTupleType<[1]> // never
48
+ * type R = IsTuple<[]> // true
28
49
  *
29
- * type R = NotTupleType<number[]> // number[]
30
- * type R = NotTupleType<string> // string
31
- * type R = NotTupleType<never> // never
32
- * type R = NotTupleType<unknown> // unknown
50
+ * type R = IsTuple<number[]> // false
51
+ * type R = IsTuple<string> // false
52
+ * type R = IsTuple<never> // false
53
+ * type R = IsTuple<unknown> // false
33
54
  * ```
34
55
  */
35
- export type NotTupleType<T, Then = T, Else = never> = TupleType<T, Else, Then>
56
+ export type IsTuple<
57
+ T,
58
+ Then = true,
59
+ Else = false,
60
+ Options extends TupleType.Options = TupleType.DefaultOptions<Else>
61
+ > = TupleType<T, Then, Else, Options>
62
+
36
63
 
37
64
  /**
38
- * Is `T` a tuple and not an array.
65
+ * 🌪️ *filter*
66
+ *
67
+ * Filter `T` to ensure it is not an tuple, excluding array.
39
68
  *
40
69
  * ```ts
41
- * type R = IsTuple<[]> // true
70
+ * type R = NotTupleType<[]> // never
71
+ * type R = NotTupleType<[1]> // never
42
72
  *
43
- * type R = IsTuple<number[]> // false
44
- * type R = IsTuple<string> // false
45
- * type R = IsTuple<never> // false
46
- * type R = IsTuple<unknown> // false
73
+ * type R = NotTupleType<number[]> // number[]
74
+ * type R = NotTupleType<string> // string
75
+ * type R = NotTupleType<never> // never
76
+ * type R = NotTupleType<unknown> // unknown
47
77
  * ```
48
78
  */
49
- export type IsTuple<T, Then = true, Else = false> = TupleType<T, Then, Else>
79
+ export type NotTupleType<
80
+ T,
81
+ Then = T,
82
+ Else = never,
83
+ Options extends TupleType.Options = TupleType.DefaultOptions<Then>
84
+ > = TupleType<T, Else, Then, Options>
50
85
 
51
86
  /**
52
- * Is `T` not a tuple.
87
+ * 🎭 *validate*
88
+ *
89
+ * Validate that `T` is not a tuple, excluding array.
53
90
  *
54
91
  * ```ts
55
92
  * type R = IsNotTuple<[]> // false
56
93
  * type R = IsNotTuple<[1]> // false
57
94
  *
58
- * type R = IsNotTuple<number[]> // false
59
- * type R = IsNotTuple<string> // false
60
- * type R = IsNotTuple<never> // false
61
- * type R = IsNotTuple<unknown> // false
95
+ * type R = IsNotTuple<number[]> // true
96
+ * type R = IsNotTuple<string> // true
97
+ * type R = IsNotTuple<never> // true
98
+ * type R = IsNotTuple<unknown> // true
62
99
  * ```
63
100
  */
64
- export type IsNotTuple<T, Then = true, Else = false> = TupleType<T, Else, Then>
101
+ export type IsNotTuple<
102
+ T,
103
+ Then = true,
104
+ Else = false,
105
+ Options extends TupleType.Options = TupleType.DefaultOptions<Then>
106
+ > = TupleType<T, Else, Then, Options>
@@ -0,0 +1,81 @@
1
+ # union
2
+
3
+ Union type is a type that combines multiple types as union.
4
+
5
+ A value belongs to a union type if it belongs to one (or more) of its member types.
6
+
7
+ For example:
8
+
9
+ ```ts
10
+ type U1 = string | number
11
+
12
+ const u1: U1 = 'a'
13
+ const u2: U1 = 1
14
+ ```
15
+
16
+ As a mental shortcut, you can think of it as an *or* operator.
17
+ But it is better to think of it as union of category instead.
18
+
19
+ ## Union Members
20
+
21
+ Each member of a union type is referred to as the union's member.
22
+
23
+ It is useful to understand the relationship between members of a union type.
24
+
25
+ In this context, we are going to consider types as sets,
26
+ instead of categories, to make it easier to understand.
27
+
28
+ Given two union members of a union,
29
+ their relationship can be describe as "A x B" where "x" is:
30
+
31
+ - disjoint: there is no overlap between A and B (e.g. `number | string`).
32
+ - overlap: there are some overlap between A and B (e.g. `1 | 2` and `2 | 3` has overlap `2`)
33
+ - subset/superset: A is a subset of B (or B is a superset of A) when every element in A is also in B (e.g. `1 | 2` is a subset of `number`)
34
+
35
+ The union type will consider these relations when it is declared.
36
+
37
+ There are other relations between members of a union type,
38
+ which will affect how the union type behaves.
39
+
40
+ For example:
41
+
42
+ - property overlap: e.g. `{ a: 1 } | { a: 2 }`
43
+ - property overlap with extension: e.g. `{ a: 1, b?: 2 } | { a: 1, c?: 3 }`
44
+
45
+ The names of these relations are not properly defined and may change in the future.
46
+
47
+ ## [UnionType](./union.ts#l13)
48
+
49
+ `UnionType<T, Then = T, Else = never>`
50
+
51
+ 🌪️ *filter*
52
+
53
+ Filter the type `T` to ensure it is a union.
54
+
55
+ ```ts
56
+ import type { UnionType } from 'type-plus'
57
+
58
+ type R = UnionType<1 | 2> // 1 | 2
59
+ type R = UnionType<boolean> // boolean
60
+ type R = UnionType<number> // never
61
+ ```
62
+
63
+ ## [IsUnion](./union.ts#l30)
64
+
65
+ 🎭 *validate*
66
+
67
+ Validate that `T` is a union.
68
+
69
+ ```ts
70
+ import type { IsUnion } from 'type-plus'
71
+
72
+ type R = IsUnion<1 | 2> // true
73
+ type R = IsUnion<boolean> // true
74
+ type R = IsUnion<number> // false
75
+ ```
76
+
77
+ ## Reference
78
+
79
+ - [handbook]
80
+
81
+ [handbook]: https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#union-types
@@ -0,0 +1,37 @@
1
+ /**
2
+ * 🌪️ *filter*
3
+ *
4
+ * Filter the type `T` to ensure it is a union.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * type R = IsUnion<'a' | 'b'> // 'a' | 'b'
9
+ * type R = IsUnion<boolean> // boolean
10
+ * type R = IsUnion<number> // never
11
+ * ```
12
+ */
13
+ export type UnionType<T, Then = T, Else = never> = UnionType.Device<T, Then, Else>
14
+
15
+ /**
16
+ * 🎭 *validate*
17
+ *
18
+ * Validate the type `T` is a union.
19
+ *
20
+ * @author Nurbol Alpysbayev
21
+ * @see https://stackoverflow.com/questions/53953814/typescript-check-if-a-type-is-a-union
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * type R = IsUnion<'a' | 'b'> // true
26
+ * type R = IsUnion<boolean> // true
27
+ * type R = IsUnion<number> // false
28
+ * ```
29
+ */
30
+ export type IsUnion<T, Then = true, Else = false> = UnionType.Device<T, Then, Else>
31
+
32
+ export namespace UnionType {
33
+ export type Device<T, Then, Else, U = T> =
34
+ (T extends unknown ? (U extends T ? 1 : 2) : never) extends 1
35
+ ? Else
36
+ : Then
37
+ }
@@ -53,3 +53,16 @@ export type NotUnknownType<T, Then = T, Else = never> = UnknownType<T, Else, The
53
53
  * ```
54
54
  */
55
55
  export type IsNotUnknown<T, Then = true, Else = false> = UnknownType<T, Else, Then>
56
+
57
+ /**
58
+ * 🌪️ *filter*
59
+ *
60
+ * Returns `T` if `T` is not `unknown`, otherwise `Else`.
61
+ *
62
+ * @example
63
+ * ```ts
64
+ * type R = NotUnknownOr<number, string> // number
65
+ * type R = NotUnknownOr<unknown, number> // number
66
+ * ```
67
+ */
68
+ export type NotUnknownOr<T, Else> = UnknownType<T, Else, T>
@@ -0,0 +1,10 @@
1
+
2
+ /**
3
+ * 🦴 *utilities*
4
+ * ㊙️ *internal*
5
+ *
6
+ * Merge the input Options `I` with the default Options `D`.
7
+ */
8
+ export type MergeOptions<I, D> = {
9
+ [k in keyof D]: k extends keyof I ? I[k] : D[k]
10
+ }
@@ -1,23 +0,0 @@
1
- import type { TupleType } from '../tuple/tuple_type.js';
2
- /**
3
- * 🦴 *utilities*
4
- *
5
- * Gets the first type in the array or tuple that matches the `Criteria`.
6
- *
7
- * If the `Criteria` is not met, it will return `never'.
8
- *
9
- * For `Array<T>`, it will return `T | undefined` if `T` satisfies `Criteria`.
10
- *
11
- * @example
12
- * ```ts
13
- * ArrayPlus.Find<Array<1 | 2 | 'x'>, number> // 1 | 2 | undefined
14
- *
15
- * ArrayPlus.Find<[true, 1, 'x', 3], string> // 'x'
16
- * ```
17
- */
18
- export type FindFirst<A extends unknown[], Criteria> = TupleType<A, A['length'] extends 0 ? never : A extends [infer Head, ...infer Tail] ? Head extends Criteria ? Head : FindFirst<Tail, Criteria> : never, A extends Array<infer T> ? (T extends Criteria ? T | undefined : never) : never>;
19
- /**
20
- * @deprecated use FindFirst
21
- */
22
- export type First<A extends any[], Criteria> = FindFirst<A, Criteria>;
23
- //# sourceMappingURL=array.find.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"array.find.d.ts","sourceRoot":"","sources":["../../ts/array/array.find.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAEvD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,OAAO,EAAE,EAAE,QAAQ,IAAI,SAAS,CAC/D,CAAC,EACD,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,GAClB,KAAK,GACL,CAAC,SAAS,CAAC,MAAM,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,GACrC,IAAI,SAAS,QAAQ,GACpB,IAAI,GACJ,SAAS,CAAC,IAAI,EAAE,QAAQ,CAAC,GAC1B,KAAK,EACR,CAAC,SAAS,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,SAAS,QAAQ,GAAG,CAAC,GAAG,SAAS,GAAG,KAAK,CAAC,GAAG,KAAK,CAC/E,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,KAAK,CAAC,CAAC,SAAS,GAAG,EAAE,EAAE,QAAQ,IAAI,SAAS,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"array.find.js","sourceRoot":"","sources":["../../ts/array/array.find.ts"],"names":[],"mappings":""}
@@ -1,23 +0,0 @@
1
- import type { TupleType } from '../tuple/tuple_type.js';
2
- /**
3
- * 🦴 *utilities*
4
- *
5
- * Gets the first type in the array or tuple that matches the `Criteria`.
6
- *
7
- * If the `Criteria` is not met, it will return `never'.
8
- *
9
- * For `Array<T>`, it will return `T | undefined` if `T` satisfies `Criteria`.
10
- *
11
- * @example
12
- * ```ts
13
- * ArrayPlus.Find<Array<1 | 2 | 'x'>, number> // 1 | 2 | undefined
14
- *
15
- * ArrayPlus.Find<[true, 1, 'x', 3], string> // 'x'
16
- * ```
17
- */
18
- export type FindFirst<A extends unknown[], Criteria> = TupleType<A, A['length'] extends 0 ? never : A extends [infer Head, ...infer Tail] ? Head extends Criteria ? Head : FindFirst<Tail, Criteria> : never, A extends Array<infer T> ? (T extends Criteria ? T | undefined : never) : never>;
19
- /**
20
- * @deprecated use FindFirst
21
- */
22
- export type First<A extends any[], Criteria> = FindFirst<A, Criteria>;
23
- //# sourceMappingURL=array.find.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"array.find.d.ts","sourceRoot":"","sources":["../../ts/array/array.find.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAEvD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,OAAO,EAAE,EAAE,QAAQ,IAAI,SAAS,CAC/D,CAAC,EACD,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,GAClB,KAAK,GACL,CAAC,SAAS,CAAC,MAAM,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,GACrC,IAAI,SAAS,QAAQ,GACpB,IAAI,GACJ,SAAS,CAAC,IAAI,EAAE,QAAQ,CAAC,GAC1B,KAAK,EACR,CAAC,SAAS,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,SAAS,QAAQ,GAAG,CAAC,GAAG,SAAS,GAAG,KAAK,CAAC,GAAG,KAAK,CAC/E,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,KAAK,CAAC,CAAC,SAAS,GAAG,EAAE,EAAE,QAAQ,IAAI,SAAS,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAA"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=array.find.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"array.find.js","sourceRoot":"","sources":["../../ts/array/array.find.ts"],"names":[],"mappings":""}
@@ -1,34 +0,0 @@
1
- import type { TupleType } from '../tuple/tuple_type.js'
2
-
3
- /**
4
- * 🦴 *utilities*
5
- *
6
- * Gets the first type in the array or tuple that matches the `Criteria`.
7
- *
8
- * If the `Criteria` is not met, it will return `never'.
9
- *
10
- * For `Array<T>`, it will return `T | undefined` if `T` satisfies `Criteria`.
11
- *
12
- * @example
13
- * ```ts
14
- * ArrayPlus.Find<Array<1 | 2 | 'x'>, number> // 1 | 2 | undefined
15
- *
16
- * ArrayPlus.Find<[true, 1, 'x', 3], string> // 'x'
17
- * ```
18
- */
19
- export type FindFirst<A extends unknown[], Criteria> = TupleType<
20
- A,
21
- A['length'] extends 0
22
- ? never
23
- : A extends [infer Head, ...infer Tail]
24
- ? Head extends Criteria
25
- ? Head
26
- : FindFirst<Tail, Criteria>
27
- : never,
28
- A extends Array<infer T> ? (T extends Criteria ? T | undefined : never) : never
29
- >
30
-
31
- /**
32
- * @deprecated use FindFirst
33
- */
34
- export type First<A extends any[], Criteria> = FindFirst<A, Criteria>