@planet-matrix/mobius-model 0.4.0 → 0.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 (179) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/README.md +134 -21
  3. package/dist/index.js +45 -4
  4. package/dist/index.js.map +186 -11
  5. package/oxlint.config.ts +6 -0
  6. package/package.json +16 -10
  7. package/src/abort/README.md +92 -0
  8. package/src/abort/abort-manager.ts +278 -0
  9. package/src/abort/abort-signal-listener-manager.ts +81 -0
  10. package/src/abort/index.ts +2 -0
  11. package/src/basic/README.md +69 -117
  12. package/src/basic/enhance.ts +10 -0
  13. package/src/basic/function.ts +81 -62
  14. package/src/basic/index.ts +2 -0
  15. package/src/basic/is.ts +152 -71
  16. package/src/basic/object.ts +82 -0
  17. package/src/basic/promise.ts +29 -8
  18. package/src/basic/string.ts +2 -33
  19. package/src/color/README.md +105 -0
  20. package/src/color/index.ts +3 -0
  21. package/src/color/internal.ts +42 -0
  22. package/src/color/rgb/analyze.ts +236 -0
  23. package/src/color/rgb/construct.ts +130 -0
  24. package/src/color/rgb/convert.ts +227 -0
  25. package/src/color/rgb/derive.ts +303 -0
  26. package/src/color/rgb/index.ts +6 -0
  27. package/src/color/rgb/internal.ts +208 -0
  28. package/src/color/rgb/parse.ts +302 -0
  29. package/src/color/rgb/serialize.ts +144 -0
  30. package/src/color/types.ts +57 -0
  31. package/src/color/xyz/analyze.ts +80 -0
  32. package/src/color/xyz/construct.ts +19 -0
  33. package/src/color/xyz/convert.ts +71 -0
  34. package/src/color/xyz/index.ts +3 -0
  35. package/src/color/xyz/internal.ts +23 -0
  36. package/src/css/README.md +93 -0
  37. package/src/css/class.ts +559 -0
  38. package/src/css/index.ts +1 -0
  39. package/src/encoding/README.md +92 -0
  40. package/src/encoding/base64.ts +107 -0
  41. package/src/encoding/index.ts +1 -0
  42. package/src/environment/README.md +97 -0
  43. package/src/environment/basic.ts +26 -0
  44. package/src/environment/device.ts +311 -0
  45. package/src/environment/feature.ts +285 -0
  46. package/src/environment/geo.ts +337 -0
  47. package/src/environment/index.ts +7 -0
  48. package/src/environment/runtime.ts +400 -0
  49. package/src/environment/snapshot.ts +60 -0
  50. package/src/environment/variable.ts +239 -0
  51. package/src/event/README.md +90 -0
  52. package/src/event/class-event-proxy.ts +228 -0
  53. package/src/event/common.ts +19 -0
  54. package/src/event/event-manager.ts +203 -0
  55. package/src/event/index.ts +4 -0
  56. package/src/event/instance-event-proxy.ts +186 -0
  57. package/src/event/internal.ts +24 -0
  58. package/src/exception/README.md +96 -0
  59. package/src/exception/browser.ts +219 -0
  60. package/src/exception/index.ts +4 -0
  61. package/src/exception/nodejs.ts +169 -0
  62. package/src/exception/normalize.ts +106 -0
  63. package/src/exception/types.ts +99 -0
  64. package/src/identifier/README.md +92 -0
  65. package/src/identifier/id.ts +119 -0
  66. package/src/identifier/index.ts +2 -0
  67. package/src/identifier/uuid.ts +187 -0
  68. package/src/index.ts +18 -1
  69. package/src/log/README.md +79 -0
  70. package/src/log/index.ts +5 -0
  71. package/src/log/log-emitter.ts +72 -0
  72. package/src/log/log-record.ts +10 -0
  73. package/src/log/log-scheduler.ts +74 -0
  74. package/src/log/log-type.ts +8 -0
  75. package/src/log/logger.ts +543 -0
  76. package/src/orchestration/README.md +89 -0
  77. package/src/orchestration/coordination/barrier.ts +214 -0
  78. package/src/orchestration/coordination/count-down-latch.ts +215 -0
  79. package/src/orchestration/coordination/errors.ts +98 -0
  80. package/src/orchestration/coordination/index.ts +16 -0
  81. package/src/orchestration/coordination/internal/wait-constraints.ts +95 -0
  82. package/src/orchestration/coordination/internal/wait-queue.ts +109 -0
  83. package/src/orchestration/coordination/keyed-lock.ts +168 -0
  84. package/src/orchestration/coordination/mutex.ts +257 -0
  85. package/src/orchestration/coordination/permit.ts +127 -0
  86. package/src/orchestration/coordination/read-write-lock.ts +444 -0
  87. package/src/orchestration/coordination/semaphore.ts +280 -0
  88. package/src/orchestration/index.ts +1 -0
  89. package/src/random/README.md +78 -0
  90. package/src/random/index.ts +1 -0
  91. package/src/random/string.ts +35 -0
  92. package/src/reactor/README.md +4 -0
  93. package/src/reactor/reactor-core/primitive.ts +9 -9
  94. package/src/reactor/reactor-core/reactive-system.ts +5 -5
  95. package/src/singleton/README.md +79 -0
  96. package/src/singleton/factory.ts +55 -0
  97. package/src/singleton/index.ts +2 -0
  98. package/src/singleton/manager.ts +204 -0
  99. package/src/storage/README.md +107 -0
  100. package/src/storage/index.ts +1 -0
  101. package/src/storage/table.ts +449 -0
  102. package/src/timer/README.md +86 -0
  103. package/src/timer/expiration/expiration-manager.ts +594 -0
  104. package/src/timer/expiration/index.ts +3 -0
  105. package/src/timer/expiration/min-heap.ts +208 -0
  106. package/src/timer/expiration/remaining-manager.ts +241 -0
  107. package/src/timer/index.ts +1 -0
  108. package/src/type/README.md +54 -307
  109. package/src/type/class.ts +2 -2
  110. package/src/type/index.ts +14 -14
  111. package/src/type/is.ts +265 -2
  112. package/src/type/object.ts +37 -0
  113. package/src/type/string.ts +7 -2
  114. package/src/type/tuple.ts +6 -6
  115. package/src/type/union.ts +16 -0
  116. package/src/web/README.md +77 -0
  117. package/src/web/capture.ts +35 -0
  118. package/src/web/clipboard.ts +97 -0
  119. package/src/web/dom.ts +117 -0
  120. package/src/web/download.ts +16 -0
  121. package/src/web/event.ts +46 -0
  122. package/src/web/index.ts +10 -0
  123. package/src/web/local-storage.ts +113 -0
  124. package/src/web/location.ts +28 -0
  125. package/src/web/permission.ts +172 -0
  126. package/src/web/script-loader.ts +432 -0
  127. package/tests/unit/abort/abort-manager.spec.ts +225 -0
  128. package/tests/unit/abort/abort-signal-listener-manager.spec.ts +62 -0
  129. package/tests/unit/basic/array.spec.ts +1 -1
  130. package/tests/unit/basic/object.spec.ts +32 -1
  131. package/tests/unit/basic/stream.spec.ts +1 -1
  132. package/tests/unit/basic/string.spec.ts +0 -9
  133. package/tests/unit/color/rgb/analyze.spec.ts +110 -0
  134. package/tests/unit/color/rgb/construct.spec.ts +56 -0
  135. package/tests/unit/color/rgb/convert.spec.ts +60 -0
  136. package/tests/unit/color/rgb/derive.spec.ts +103 -0
  137. package/tests/unit/color/rgb/parse.spec.ts +66 -0
  138. package/tests/unit/color/rgb/serialize.spec.ts +46 -0
  139. package/tests/unit/color/xyz/analyze.spec.ts +33 -0
  140. package/tests/unit/color/xyz/construct.spec.ts +10 -0
  141. package/tests/unit/color/xyz/convert.spec.ts +18 -0
  142. package/tests/unit/css/class.spec.ts +157 -0
  143. package/tests/unit/encoding/base64.spec.ts +40 -0
  144. package/tests/unit/environment/basic.spec.ts +20 -0
  145. package/tests/unit/environment/device.spec.ts +146 -0
  146. package/tests/unit/environment/feature.spec.ts +388 -0
  147. package/tests/unit/environment/geo.spec.ts +111 -0
  148. package/tests/unit/environment/runtime.spec.ts +364 -0
  149. package/tests/unit/environment/snapshot.spec.ts +4 -0
  150. package/tests/unit/environment/variable.spec.ts +190 -0
  151. package/tests/unit/event/class-event-proxy.spec.ts +225 -0
  152. package/tests/unit/event/event-manager.spec.ts +246 -0
  153. package/tests/unit/event/instance-event-proxy.spec.ts +187 -0
  154. package/tests/unit/exception/browser.spec.ts +213 -0
  155. package/tests/unit/exception/nodejs.spec.ts +144 -0
  156. package/tests/unit/exception/normalize.spec.ts +57 -0
  157. package/tests/unit/identifier/id.spec.ts +71 -0
  158. package/tests/unit/identifier/uuid.spec.ts +85 -0
  159. package/tests/unit/log/log-emitter.spec.ts +33 -0
  160. package/tests/unit/log/log-scheduler.spec.ts +40 -0
  161. package/tests/unit/log/log-type.spec.ts +7 -0
  162. package/tests/unit/log/logger.spec.ts +222 -0
  163. package/tests/unit/orchestration/coordination/barrier.spec.ts +96 -0
  164. package/tests/unit/orchestration/coordination/count-down-latch.spec.ts +63 -0
  165. package/tests/unit/orchestration/coordination/errors.spec.ts +29 -0
  166. package/tests/unit/orchestration/coordination/keyed-lock.spec.ts +109 -0
  167. package/tests/unit/orchestration/coordination/mutex.spec.ts +132 -0
  168. package/tests/unit/orchestration/coordination/permit.spec.ts +43 -0
  169. package/tests/unit/orchestration/coordination/read-write-lock.spec.ts +154 -0
  170. package/tests/unit/orchestration/coordination/semaphore.spec.ts +135 -0
  171. package/tests/unit/random/string.spec.ts +11 -0
  172. package/tests/unit/reactor/alien-signals-effect.spec.ts +11 -10
  173. package/tests/unit/reactor/preact-signal.spec.ts +1 -2
  174. package/tests/unit/singleton/singleton.spec.ts +49 -0
  175. package/tests/unit/storage/table.spec.ts +620 -0
  176. package/tests/unit/timer/expiration/expiration-manager.spec.ts +464 -0
  177. package/tests/unit/timer/expiration/min-heap.spec.ts +71 -0
  178. package/tests/unit/timer/expiration/remaining-manager.spec.ts +234 -0
  179. package/.oxlintrc.json +0 -5
package/src/type/is.ts CHANGED
@@ -1,46 +1,95 @@
1
1
  // oxlint-disable no-explicit-any
2
2
 
3
3
  /**
4
+ * 表示 JavaScript 与 TypeScript 中的原始类型联合。
5
+ *
4
6
  * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types}
5
7
  */
6
8
  export type Primitive = string | number | boolean | bigint | symbol | null | undefined
7
9
  /**
8
- * @see {@link https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-2.html#object-type}
9
- */
10
+ * 表示非原始类型。
11
+ *
12
+ * @see {@link https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-2.html#object-type}
13
+ */
10
14
  export type NonPrimitive = object
11
15
 
16
+ /**
17
+ * 判断目标类型是否为原始类型。
18
+ */
12
19
  export type IsPrimitive<T> =
13
20
  T extends string ? true : T extends number ? true : T extends boolean ? true : T extends bigint ? true
14
21
  : T extends symbol ? true : T extends null ? true : T extends undefined ? true : false
22
+ /**
23
+ * 当目标类型是原始类型时返回 `TRUE`,否则返回 `FALSE`。
24
+ */
15
25
  export type IfPrimitive<T, TRUE = true, FALSE = never> = IsPrimitive<T> extends true ? TRUE : FALSE
16
26
 
27
+ /**
28
+ * 判断联合类型的每个成员是否都属于原始类型集合。
29
+ */
17
30
  export type IsPrimitiveUnion<T> = T extends Primitive ? true : false
31
+ /**
32
+ * 当联合类型成员都属于原始类型集合时返回 `TRUE`,否则返回 `FALSE`。
33
+ */
18
34
  export type IfPrimitiveUnion<T, TRUE = true, FALSE = never> = IsPrimitiveUnion<T> extends true ? TRUE : FALSE
19
35
 
20
36
  /**
21
37
  * Predicate whether the target is `string`.
22
38
  */
23
39
  export type IsString<T> = T extends string ? true : false
40
+ /**
41
+ * 当目标类型是 `string` 时返回 `TRUE`,否则返回 `FALSE`。
42
+ */
24
43
  export type IfString<T, TRUE = true, FALSE = never> = IsString<T> extends true ? TRUE : FALSE
44
+ /**
45
+ * 将目标类型收窄为 `string`,否则回退到 `string`。
46
+ */
25
47
  export type CastString<T> = T extends string ? T : string
48
+ /**
49
+ * 判断目标类型是否为字符串字面量类型。
50
+ */
26
51
  export type IsStringLiteral<T> = T extends string ? (string extends T ? false : true) : false
27
52
 
28
53
  /**
29
54
  * Predicate whether the target is `number`.
30
55
  */
31
56
  export type IsNumber<T> = T extends number ? true : false
57
+ /**
58
+ * 当目标类型是 `number` 时返回 `TRUE`,否则返回 `FALSE`。
59
+ */
32
60
  export type IfNumber<T, TRUE = true, FALSE = never> = IsNumber<T> extends true ? TRUE : FALSE
61
+ /**
62
+ * 将目标类型收窄为 `number`,否则回退到 `number`。
63
+ */
33
64
  export type CastNumber<T> = T extends number ? T : number
65
+ /**
66
+ * 判断目标类型是否为数字字面量类型。
67
+ */
34
68
  export type IsNumberLiteral<T> = T extends number ? (number extends T ? false : true) : false
35
69
 
36
70
  /**
37
71
  * Predicate whether the target is `boolean`.
38
72
  */
39
73
  export type IsBoolean<T> = T extends boolean ? true : false
74
+ /**
75
+ * 当目标类型是 `boolean` 时返回 `TRUE`,否则返回 `FALSE`。
76
+ */
40
77
  export type IfBoolean<T, TRUE = true, FALSE = never> = IsBoolean<T> extends true ? TRUE : FALSE
78
+ /**
79
+ * 将目标类型收窄为 `boolean`,否则回退到 `boolean`。
80
+ */
41
81
  export type CastBoolean<T> = T extends boolean ? T : boolean
82
+ /**
83
+ * 判断目标类型是否为字面量 `true`。
84
+ */
42
85
  export type IsTrue<T> = T extends true ? true : false
86
+ /**
87
+ * 判断目标类型是否为字面量 `false`。
88
+ */
43
89
  export type IsFalse<T> = T extends false ? true : false
90
+ /**
91
+ * 判断目标类型是否为布尔字面量类型。
92
+ */
44
93
  export type IsBooleanLiteral<T> =
45
94
  [T] extends [boolean] // Check if T is assignable to boolean (true, false, or boolean)
46
95
  ? ([boolean] extends [T] // Check if boolean is assignable to T (only true for 'boolean' itself)
@@ -53,86 +102,203 @@ export type IsBooleanLiteral<T> =
53
102
  * Predicate whether the target is `bigint`.
54
103
  */
55
104
  export type IsBigInt<T> = T extends bigint ? true : false
105
+ /**
106
+ * 当目标类型是 `bigint` 时返回 `TRUE`,否则返回 `FALSE`。
107
+ */
56
108
  export type IfBigInt<T, TRUE = true, FALSE = never> = IsBigInt<T> extends true ? TRUE : FALSE
109
+ /**
110
+ * 将目标类型收窄为 `bigint`,否则回退到 `bigint`。
111
+ */
57
112
  export type CastBigInt<T> = T extends bigint ? T : bigint
58
113
 
59
114
  /**
60
115
  * Predicate whether the target is `symbol`.
61
116
  */
62
117
  export type IsSymbol<T> = T extends symbol ? true : false
118
+ /**
119
+ * 当目标类型是 `symbol` 时返回 `TRUE`,否则返回 `FALSE`。
120
+ */
63
121
  export type IfSymbol<T, TRUE = true, FALSE = never> = IsSymbol<T> extends true ? TRUE : FALSE
122
+ /**
123
+ * 将目标类型收窄为 `symbol`,否则回退到 `symbol`。
124
+ */
64
125
  export type CastSymbol<T> = T extends symbol ? T : symbol
65
126
 
66
127
  /**
67
128
  * Predicate whether the target is `null`.
68
129
  */
69
130
  export type IsNull<T> = Exclude<T, null> extends never ? true : false
131
+ /**
132
+ * 当目标类型是 `null` 时返回 `TRUE`,否则返回 `FALSE`。
133
+ */
70
134
  export type IfNull<T, TRUE = true, FALSE = never> = IsNull<T> extends true ? TRUE : FALSE
135
+ /**
136
+ * 将目标类型收窄为 `null`,否则回退到 `null`。
137
+ */
71
138
  export type CastNull<T> = T extends null ? T : null
139
+ /**
140
+ * 判断目标类型是否包含 `null`。
141
+ */
72
142
  export type IsNullable<T> = T extends Exclude<T, null> ? false : true
143
+ /**
144
+ * 当目标类型可空时返回 `TRUE`,否则返回 `FALSE`。
145
+ */
73
146
  export type IfNullable<T, TRUE = true, FALSE = never> = IsNullable<T> extends true ? TRUE : FALSE
147
+ /**
148
+ * 为目标类型附加 `null`。
149
+ */
74
150
  export type Nullable<T> = T | null
151
+ /**
152
+ * 从目标类型中移除 `null`。
153
+ */
75
154
  export type NonNullable<T> = Exclude<T, null>
76
155
 
77
156
  /**
78
157
  * Predicate whether the target is `undefined`.
79
158
  */
80
159
  export type IsUndefined<T> = Exclude<T, undefined> extends never ? true : false
160
+ /**
161
+ * 当目标类型是 `undefined` 时返回 `TRUE`,否则返回 `FALSE`。
162
+ */
81
163
  export type IfUndefined<T, TRUE = true, FALSE = never> = IsUndefined<T> extends true ? TRUE : FALSE
164
+ /**
165
+ * 将目标类型收窄为 `undefined`,否则回退到 `undefined`。
166
+ */
82
167
  export type CastUndefined<T> = T extends undefined ? T : undefined
168
+ /**
169
+ * 判断目标类型是否包含 `undefined`。
170
+ */
83
171
  export type IsUndefinedable<T> = T extends Exclude<T, undefined> ? false : true
172
+ /**
173
+ * 当目标类型可为 `undefined` 时返回 `TRUE`,否则返回 `FALSE`。
174
+ */
84
175
  export type IfUndefinedable<T, TRUE = true, FALSE = never> = IsUndefinedable<T> extends true ? TRUE : FALSE
176
+ /**
177
+ * 为目标类型附加 `undefined`。
178
+ */
85
179
  export type Undefinedable<T> = T | undefined
180
+ /**
181
+ * 从目标类型中移除 `undefined`。
182
+ */
86
183
  export type NonUndefinedable<T> = Exclude<T, undefined>
87
184
 
88
185
  /**
89
186
  * Predicate whether the target is `null | undefined`.
90
187
  */
91
188
  export type IsNil<T> = Exclude<T, undefined | null> extends never ? true : false
189
+ /**
190
+ * 当目标类型是 `null | undefined` 时返回 `TRUE`,否则返回 `FALSE`。
191
+ */
92
192
  export type IfNil<T, TRUE = true, FALSE = never> = IsNil<T> extends true ? TRUE : FALSE
193
+ /**
194
+ * 将目标类型收窄为 `null | undefined`,否则回退到该并集。
195
+ */
93
196
  export type CastNil<T> = T extends undefined | null ? T : undefined | null
197
+ /**
198
+ * 判断目标类型是否包含 `null` 或 `undefined`。
199
+ */
94
200
  export type IsNilable<T> = T extends Exclude<T, null | undefined> ? false : true
201
+ /**
202
+ * 当目标类型可为 `null` 或 `undefined` 时返回 `TRUE`,否则返回 `FALSE`。
203
+ */
95
204
  export type IfNilable<T, TRUE = true, FALSE = never> = IsNilable<T> extends true ? TRUE : FALSE
205
+ /**
206
+ * 为目标类型附加 `null | undefined`。
207
+ */
96
208
  export type Nilable<T> = T | null | undefined
209
+ /**
210
+ * 从目标类型中移除 `null | undefined`。
211
+ */
97
212
  export type NonNilable<T> = Exclude<T, null | undefined>
98
213
 
99
214
  /**
100
215
  * Predicate whether the target is `Record`.
101
216
  */
102
217
  export type IsRecord<T> = T extends Record<string | number | symbol, unknown> ? true : false
218
+ /**
219
+ * 当目标类型是记录类型时返回 `TRUE`,否则返回 `FALSE`。
220
+ */
103
221
  export type IfRecord<T, TRUE = true, FALSE = never> = IsRecord<T> extends true ? TRUE : FALSE
222
+ /**
223
+ * 判断目标类型是否为字符串键记录类型。
224
+ */
104
225
  export type IsStringRecord<T> = T extends Record<string, unknown> ? true : false
226
+ /**
227
+ * 当目标类型是字符串键记录类型时返回 `TRUE`,否则返回 `FALSE`。
228
+ */
105
229
  export type IfStringRecord<T, TRUE = true, FALSE = never> = IsStringRecord<T> extends true ? TRUE : FALSE
230
+ /**
231
+ * 判断目标类型是否为数字键记录类型。
232
+ */
106
233
  export type IsNumberRecord<T> = T extends Record<number, unknown> ? true : false
234
+ /**
235
+ * 当目标类型是数字键记录类型时返回 `TRUE`,否则返回 `FALSE`。
236
+ */
107
237
  export type IfNumberRecord<T, TRUE = true, FALSE = never> = IsNumberRecord<T> extends true ? TRUE : FALSE
238
+ /**
239
+ * 判断目标类型是否为符号键记录类型。
240
+ */
108
241
  export type IsSymbolRecord<T> = T extends Record<symbol, unknown> ? true : false
242
+ /**
243
+ * 当目标类型是符号键记录类型时返回 `TRUE`,否则返回 `FALSE`。
244
+ */
109
245
  export type IfSymbolRecord<T, TRUE = true, FALSE = never> = IsSymbolRecord<T> extends true ? TRUE : FALSE
110
246
 
247
+ /**
248
+ * 判断目标类型是否为对象类型。
249
+ */
111
250
  // oxlint-disable-next-line no-wrapper-object-types ban-types
112
251
  export type IsObject<Target> = Target extends Object ? true : false
252
+ /**
253
+ * 当目标类型是对象类型时返回 `TRUE`,否则返回 `FALSE`。
254
+ */
113
255
  export type IfObject<Target, TRUE = true, FALSE = never> = IsObject<Target> extends true ? TRUE : FALSE
256
+ /**
257
+ * 表示普通对象结构。
258
+ */
114
259
  export type PlainObject = Record<PropertyKey, unknown>
115
260
  /**
116
261
  * Predicate whether the target is `EmptyObject`(`{}`).
117
262
  */
118
263
  export type IsEmptyObject<Target extends Record<PropertyKey, unknown>> = keyof Target extends never ? true : false
264
+ /**
265
+ * 当目标类型是空对象时返回 `TRUE`,否则返回 `FALSE`。
266
+ */
119
267
  export type IfEmptyObject<Target extends Record<PropertyKey, unknown>, TRUE = true, FALSE = never> = IsEmptyObject<Target> extends true ? TRUE : FALSE
120
268
 
121
269
  /**
122
270
  * Predicate whether the target is `Array`.
123
271
  */
124
272
  export type IsArray<T> = T extends readonly unknown[] ? (number extends T["length"] ? true : false) : false
273
+ /**
274
+ * 当目标类型是数组时返回 `TRUE`,否则返回 `FALSE`。
275
+ */
125
276
  export type IfArray<T, TRUE = true, FALSE = never> = IsArray<T> extends true ? TRUE : FALSE
126
277
  // ReadonlyArray is subset of Array.
278
+ /**
279
+ * 判断目标类型是否为只读数组。
280
+ */
127
281
  export type IsReadonlyArray<T> = T extends readonly unknown[] ? (T extends unknown[] ? false : true) : false
282
+ /**
283
+ * 当目标类型是只读数组时返回 `TRUE`,否则返回 `FALSE`。
284
+ */
128
285
  export type IfReadonlyArray<T, TRUE = true, FALSE = never> = IsReadonlyArray<T> extends true ? TRUE : FALSE
286
+ /**
287
+ * 判断目标类型是否为可写数组。
288
+ */
129
289
  export type IsWritableArray<T> = T extends unknown[] ? (number extends T["length"] ? true : false) : false
290
+ /**
291
+ * 当目标类型是可写数组时返回 `TRUE`,否则返回 `FALSE`。
292
+ */
130
293
  export type IfWritableArray<T, TRUE = true, FALSE = never> = IsWritableArray<T> extends true ? TRUE : FALSE
131
294
 
132
295
  /**
133
296
  * Predicate whether the target is `ArrayLike`.
134
297
  */
135
298
  export type IsArrayLike<T> = T extends ArrayLike<unknown> ? true : false
299
+ /**
300
+ * 当目标类型满足 `ArrayLike` 结构时返回 `TRUE`,否则返回 `FALSE`。
301
+ */
136
302
  export type IfArrayLike<T, TRUE = true, FALSE = never> = IsArrayLike<T> extends true ? TRUE : FALSE
137
303
 
138
304
  /**
@@ -141,77 +307,160 @@ export type IfArrayLike<T, TRUE = true, FALSE = never> = IsArrayLike<T> extends
141
307
  * @see {@link https://github.com/type-challenges/type-challenges/issues/4491#issuecomment-975808109}
142
308
  */
143
309
  export type IsTuple<T> = T extends readonly unknown[] ? (number extends T["length"] ? false : true) : false
310
+ /**
311
+ * 当目标类型是元组时返回 `TRUE`,否则返回 `FALSE`。
312
+ */
144
313
  export type IfTuple<T, TRUE = true, FALSE = never> = IsTuple<T> extends true ? TRUE : FALSE
314
+ /**
315
+ * 判断目标类型是否为只读元组。
316
+ */
145
317
  export type IsReadonlyTuple<T> = T extends readonly unknown[] ? (T extends unknown[] ? false : true) : false
318
+ /**
319
+ * 当目标类型是只读元组时返回 `TRUE`,否则返回 `FALSE`。
320
+ */
146
321
  export type IfReadonlyTuple<T, TRUE = true, FALSE = never> = IsReadonlyTuple<T> extends true ? TRUE : FALSE
322
+ /**
323
+ * 判断目标类型是否为可写元组。
324
+ */
147
325
  export type IsWritableTuple<T> = T extends unknown[] ? (number extends T["length"] ? false : true) : false
326
+ /**
327
+ * 当目标类型是可写元组时返回 `TRUE`,否则返回 `FALSE`。
328
+ */
148
329
  export type IfWritableTuple<T, TRUE = true, FALSE = never> = IsWritableTuple<T> extends true ? TRUE : FALSE
149
330
 
150
331
  /**
151
332
  * Predicate whether the target is `Array` or `Tuple`.
152
333
  */
153
334
  export type IsArrayOrTuple<T> = T extends readonly unknown[] ? true : false
335
+ /**
336
+ * 当目标类型是数组或元组时返回 `TRUE`,否则返回 `FALSE`。
337
+ */
154
338
  export type IfArrayOrTuple<T, TRUE = true, FALSE = never> = IsArrayOrTuple<T> extends true ? TRUE : FALSE
155
339
 
156
340
  /**
157
341
  * Predicate whether the target is of type function.
158
342
  */
159
343
  export type AnyFunction = (...args: any[]) => any
344
+ /**
345
+ * 根据输入类型构造对应参数列表的任意函数类型。
346
+ */
160
347
  export type AnyFunctionOfTake<A> = A extends readonly [...infer R] ? ((...args: R) => any) : ((arg: A) => any)
348
+ /**
349
+ * 表示返回值固定为指定类型的任意函数。
350
+ */
161
351
  export type AnyFunctionOfReturn<T> = (...args: any[]) => T
352
+ /**
353
+ * 判断目标类型是否为函数类型。
354
+ */
162
355
  export type IsFunction<T> = T extends AnyFunction ? true : false
356
+ /**
357
+ * 当目标类型是函数类型时返回 `TRUE`,否则返回 `FALSE`。
358
+ */
163
359
  export type IfFunction<T, TRUE = true, FALSE = never> = IsFunction<T> extends true ? TRUE : FALSE
360
+ /**
361
+ * 将目标类型收窄为任意函数类型,否则回退到 `AnyFunction`。
362
+ */
164
363
  export type CastFunction<T> = T extends AnyFunction ? T : AnyFunction
165
364
 
365
+ /**
366
+ * 表示返回非 `Promise` 值的任意同步函数。
367
+ */
166
368
  export type AnySyncFunction = (...args: any[]) => Exclude<unknown, Promise<any>>;
167
369
  /**
168
370
  * Predicate whether the target is of type sync function.
169
371
  */
170
372
  export type IsSyncFunction<T> = T extends (...args: any[]) => infer R ? (R extends Promise<any> ? false : true) : false
373
+ /**
374
+ * 当目标类型是同步函数时返回 `TRUE`,否则返回 `FALSE`。
375
+ */
171
376
  export type IfSyncFunction<T, TRUE = true, FALSE = never> = IsSyncFunction<T> extends true ? TRUE : FALSE
377
+ /**
378
+ * 将目标类型收窄为同步函数,否则回退到通用函数类型。
379
+ */
172
380
  export type CastSyncFunction<T> = T extends (...args: unknown[]) => infer R ? (R extends Promise<unknown> ? (...args: Parameters<T>) => Awaited<R> : T) : AnyFunction
173
381
 
382
+ /**
383
+ * 表示返回 `Promise` 的任意异步函数。
384
+ */
174
385
  export type AnyAsyncFunction = (...args: any[]) => Promise<any>
175
386
  /**
176
387
  * Predicate whether the target is of type async function.
177
388
  */
178
389
  export type IsAsyncFunction<T> = T extends AnyAsyncFunction ? true : false
390
+ /**
391
+ * 当目标类型是异步函数时返回 `TRUE`,否则返回 `FALSE`。
392
+ */
179
393
  export type IfAsyncFunction<T, TRUE = true, FALSE = never> = IsAsyncFunction<T> extends true ? TRUE : FALSE
394
+ /**
395
+ * 将目标类型收窄为异步函数,否则回退到 `AnyAsyncFunction`。
396
+ */
180
397
  export type CastAsyncFunction<T> = T extends AnyAsyncFunction ? T : AnyAsyncFunction
181
398
 
399
+ /**
400
+ * 表示任意生成器函数。
401
+ */
182
402
  export type AnyGeneratorFunction = (...args: any[]) => Generator<any, any, any>
183
403
  /**
184
404
  * Predicate whether the target is of type generator function.
185
405
  */
186
406
  export type IsGeneratorFunction<T> = T extends AnyGeneratorFunction ? true : false
407
+ /**
408
+ * 当目标类型是生成器函数时返回 `TRUE`,否则返回 `FALSE`。
409
+ */
187
410
  export type IfGeneratorFunction<T, TRUE = true, FALSE = never> = IsGeneratorFunction<T> extends true ? TRUE : FALSE
411
+ /**
412
+ * 将目标类型收窄为生成器函数,否则回退到 `AnyGeneratorFunction`。
413
+ */
188
414
  export type CastGeneratorFunction<T> = T extends AnyGeneratorFunction ? T : AnyGeneratorFunction
189
415
 
416
+ /**
417
+ * 表示任意异步生成器函数。
418
+ */
190
419
  export type AnyAsyncGeneratorFunction = (...args: any[]) => AsyncGenerator<any, any, any>
191
420
  /**
192
421
  * Predicate whether the target is of type async generator function.
193
422
  */
194
423
  export type IsAsyncGeneratorFunction<T> = T extends AnyAsyncGeneratorFunction ? true : false
424
+ /**
425
+ * 当目标类型是异步生成器函数时返回 `TRUE`,否则返回 `FALSE`。
426
+ */
195
427
  export type IfAsyncGeneratorFunction<T, TRUE = true, FALSE = never> = IsAsyncGeneratorFunction<T> extends true ? TRUE : FALSE
428
+ /**
429
+ * 将目标类型收窄为异步生成器函数,否则回退到 `AnyAsyncGeneratorFunction`。
430
+ */
196
431
  export type CastAsyncGeneratorFunction<T> = T extends AnyAsyncGeneratorFunction ? T : AnyAsyncGeneratorFunction
197
432
 
198
433
  /**
199
434
  * Predicate whether the target is `never`.
200
435
  */
201
436
  export type IsNever<T> = [T] extends [never] ? true : false
437
+ /**
438
+ * 当目标类型是 `never` 时返回 `TRUE`,否则返回 `FALSE`。
439
+ */
202
440
  export type IfNever<T, TRUE = true, FALSE = never> = IsNever<T> extends true ? TRUE : FALSE
441
+ /**
442
+ * 将目标类型收窄为 `never`,否则回退到 `never`。
443
+ */
203
444
  export type CastNever<T> = T extends never ? T : never
204
445
 
205
446
  /**
206
447
  * Predicate whether the target is `any`.
448
+ *
207
449
  * @see {@link https://stackoverflow.com/questions/49927523/disallow-call-with-any/49928360#49928360}
208
450
  */
209
451
  export type IsAny<T> = 0 extends (1 & T) ? true : false
452
+ /**
453
+ * 当目标类型是 `any` 时返回 `TRUE`,否则返回 `FALSE`。
454
+ */
210
455
  export type IfAny<T, TRUE = true, FALSE = never> = IsAny<T> extends true ? TRUE : FALSE
456
+ /**
457
+ * 将目标类型收窄为 `any`。
458
+ */
211
459
  export type CastAny<T> = T extends any ? T : any
212
460
 
213
461
  /**
214
462
  * Predicate whether the target is `unknown`.
463
+ *
215
464
  * @see {@link https://www.typescriptlang.org/docs/handbook/type-compatibility.html#any-unknown-object-void-undefined-null-and-never-assignability}
216
465
  */
217
466
  export type IsUnknown<T> = IsNever<T> extends true
@@ -225,7 +474,13 @@ export type IsUnknown<T> = IsNever<T> extends true
225
474
  )
226
475
  : false
227
476
  )
477
+ /**
478
+ * 当目标类型是 `unknown` 时返回 `TRUE`,否则返回 `FALSE`。
479
+ */
228
480
  export type IfUnknown<T, TRUE = true, FALSE = never> = IsUnknown<T> extends true ? TRUE : FALSE
481
+ /**
482
+ * 将目标类型收窄为 `unknown`,否则回退到 `unknown`。
483
+ */
229
484
  export type CastUnknown<T> = T extends unknown ? T : unknown
230
485
 
231
486
  type InternalIsUnion<T, U> =
@@ -239,9 +494,17 @@ type InternalIsUnion<T, U> =
239
494
  /**
240
495
  * Predicate whether the target is `Union` type.
241
496
  *
497
+ * 判断目标类型是否为联合类型。
498
+ *
242
499
  * @see {@link https://www.typescriptlang.org/docs/handbook/2/conditional-types.html#distributive-conditional-types}
243
500
  */
244
501
  export type IsUnion<T> = InternalIsUnion<T, T>;
502
+ /**
503
+ * 当目标类型是联合类型时返回 `TRUE`,否则返回 `FALSE`。
504
+ */
245
505
  export type IfUnion<T, TRUE = true, FALSE = never> = IsUnion<T> extends true ? TRUE : FALSE
246
506
 
507
+ /**
508
+ * 表示一个空接口。
509
+ */
247
510
  export interface EmptyInterface { }
@@ -22,23 +22,58 @@ import type { UnionComplement, UnionDifference, UnionIntersection } from "./unio
22
22
  */
23
23
  export type StrictOmit<T, K extends keyof T> = Omit<T, K>
24
24
 
25
+ /**
26
+ * 表示键为字符串的记录类型。
27
+ */
25
28
  export type StringRecord<T> = Record<string, T>
29
+ /**
30
+ * 表示键为数字的记录类型。
31
+ */
26
32
  export type NumberRecord<T> = Record<number, T>
33
+ /**
34
+ * 表示键为符号的记录类型。
35
+ */
27
36
  export type SymbolRecord<T> = Record<symbol, T>
37
+ /**
38
+ * 表示键可以是字符串、数字或符号的记录类型。
39
+ */
28
40
  export type HybridRecord<T> = Record<string | number | symbol, T>
41
+ /**
42
+ * 表示值类型为 `any` 的字符串键记录类型。
43
+ */
29
44
  export type AnyStringRecord = StringRecord<any>
45
+ /**
46
+ * 表示值类型为 `any` 的数字键记录类型。
47
+ */
30
48
  export type AnyNumberRecord = NumberRecord<any>
49
+ /**
50
+ * 表示值类型为 `any` 的符号键记录类型。
51
+ */
31
52
  export type AnySymbolRecord = SymbolRecord<any>
53
+ /**
54
+ * 表示值类型为 `any` 的混合键记录类型。
55
+ */
32
56
  export type AnyHybridRecord = Record<string | number | symbol, any>
57
+ /**
58
+ * 表示任意常见记录类型的联合。
59
+ */
33
60
  export type AnyRecord = AnyStringRecord | AnyNumberRecord | AnySymbolRecord
34
61
 
62
+ /**
63
+ * 为对象类型附加一个依赖其键集合的品牌标记。
64
+ */
35
65
  export type ObjectExact<A extends object> = A & { __brand: keyof A };
36
66
 
37
67
  /**
68
+ * 重新映射对象类型,使其在编辑器中以展开后的结构显示。
69
+ *
38
70
  * @see {@link https://stackoverflow.com/questions/78453542/intersection-with-object-in-prettify-helper-type}
39
71
  * @see {@link https://github.com/mylesmmurphy/prettify-ts}
40
72
  */
41
73
  export type ObjectPrettify<Target extends AnyHybridRecord> = Pick<Target, keyof Target>
74
+ /**
75
+ * 通过条件分发重新构造对象类型,以获得更易读的展开结果。
76
+ */
42
77
  export type ObjectPrettify2<Target extends AnyHybridRecord> = Target extends infer O ? { [K in keyof O]: O[K] } : never
43
78
 
44
79
  // ============================================================================
@@ -71,6 +106,8 @@ export type ObjectNonEmpty<Target extends AnyStringRecord> = keyof Target extend
71
106
  // ============================================================================
72
107
 
73
108
  /**
109
+ * Get the keys of an object type.
110
+ *
74
111
  * @example
75
112
  * ```
76
113
  * interface Props { name: string, age: number, visible: boolean }
@@ -4,8 +4,13 @@
4
4
  // Primitives
5
5
  // ============================================================================
6
6
 
7
+ /**
8
+ * 表示既保留字面量自动补全体验,又允许回退到任意字符串的字符串类型。
9
+ */
7
10
  export type StringAutoCompletable = string & {}
8
11
  /**
12
+ * 为一组选项字符串补充自动补全,同时允许传入其它字符串。
13
+ *
9
14
  * @see {@link https://x.com/mattpocockuk/status/1822917991232569660}
10
15
  */
11
16
  export type StringWithAutoCompleteOptions<Options extends string> = Options | StringAutoCompletable
@@ -64,9 +69,9 @@ export type AlphanumericCharacter = UppercaseLetter | LowercaseLetter | DigitCha
64
69
  * @example
65
70
  * ```
66
71
  * // Expect: true
67
- * type Example1 = IsNumber<'123'>
72
+ * type Example1 = StringIsNumber<'123'>
68
73
  * // Expect: false
69
- * type Example2 = IsNumber<'12a'>
74
+ * type Example2 = StringIsNumber<'12a'>
70
75
  * ```
71
76
  */
72
77
  export type StringIsNumber<S extends string> =
package/src/type/tuple.ts CHANGED
@@ -1405,8 +1405,8 @@ export type TuplePartition<T extends readonly unknown[], P, Matches extends read
1405
1405
  * type Example2 = TupleGroupBy<[]>
1406
1406
  * ```
1407
1407
  */
1408
- export type TupleGroupBy<T extends readonly (readonly [PropertyKey, unknown])[], Acc extends Record<PropertyKey, unknown[]> = Record<never, never>> =
1409
- T extends readonly [infer First extends readonly [PropertyKey, unknown], ...infer Rest extends readonly (readonly [PropertyKey, unknown])[]]
1408
+ export type TupleGroupBy<T extends ReadonlyArray<readonly [PropertyKey, unknown]>, Acc extends Record<PropertyKey, unknown[]> = Record<never, never>> =
1409
+ T extends readonly [infer First extends readonly [PropertyKey, unknown], ...infer Rest extends ReadonlyArray<readonly [PropertyKey, unknown]>]
1410
1410
  ? TupleGroupBy<Rest, {
1411
1411
  [K in keyof Acc | First[0]]: K extends First[0]
1412
1412
  ? (K extends keyof Acc ? [...Acc[K], First[1]] : [First[1]])
@@ -2249,7 +2249,7 @@ export type TupleToObject<T extends readonly PropertyKey[]> = {
2249
2249
  * type Example2 = TupleToRecord<[]>
2250
2250
  * ```
2251
2251
  */
2252
- export type TupleToRecord<T extends readonly (readonly [PropertyKey, unknown])[]> = {
2252
+ export type TupleToRecord<T extends ReadonlyArray<readonly [PropertyKey, unknown]>> = {
2253
2253
  [K in T[number]as K extends readonly [infer Key extends PropertyKey, unknown] ? Key : never]: K extends readonly [PropertyKey, infer Value] ? Value : never
2254
2254
  }
2255
2255
 
@@ -2264,8 +2264,8 @@ export type TupleToRecord<T extends readonly (readonly [PropertyKey, unknown])[]
2264
2264
  * type Example2 = TupleToString<[], '-'>
2265
2265
  * ```
2266
2266
  */
2267
- export type TupleToString<T extends readonly (string | number | boolean)[], Sep extends string = ''> =
2268
- T extends readonly [infer First extends string | number | boolean, ...infer Rest extends (string | number | boolean)[]]
2267
+ export type TupleToString<T extends ReadonlyArray<string | number | boolean>, Sep extends string = ''> =
2268
+ T extends readonly [infer First extends string | number | boolean, ...infer Rest extends Array<string | number | boolean>]
2269
2269
  ? Rest extends []
2270
2270
  ? `${First}`
2271
2271
  : `${First}${Sep}${TupleToString<Rest, Sep>}`
@@ -2313,7 +2313,7 @@ export type TupleToIntersection<T extends readonly unknown[]> =
2313
2313
  * type Example2 = TupleToMap<[]>
2314
2314
  * ```
2315
2315
  */
2316
- export type TupleToMap<T extends readonly (readonly [PropertyKey, unknown])[]> = Map<
2316
+ export type TupleToMap<T extends ReadonlyArray<readonly [PropertyKey, unknown]>> = Map<
2317
2317
  T[number] extends readonly [infer Key extends PropertyKey, unknown] ? Key : never,
2318
2318
  T[number] extends readonly [PropertyKey, infer Value] ? Value : never
2319
2319
  >