@ls-stack/utils 3.18.0 → 3.19.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 +1 -15
- package/docs/README.md +72 -0
- package/docs/_media/modules.md +52 -0
- package/docs/arrayUtils/-internal-.md +17 -0
- package/docs/arrayUtils/README.md +423 -0
- package/docs/assertions/-internal-.md +63 -0
- package/docs/assertions/README.md +565 -0
- package/docs/asyncQueue/-internal-.md +815 -0
- package/docs/asyncQueue/README.md +75 -0
- package/docs/awaitDebounce.md +66 -0
- package/docs/cache/-internal-.md +168 -0
- package/docs/cache/README.md +360 -0
- package/docs/castValues.md +47 -0
- package/docs/concurrentCalls/-internal-.md +416 -0
- package/docs/concurrentCalls/README.md +77 -0
- package/docs/consoleFmt.md +91 -0
- package/docs/conversions.md +27 -0
- package/docs/createThrottleController/-internal-.md +73 -0
- package/docs/createThrottleController/README.md +31 -0
- package/docs/debounce.md +188 -0
- package/docs/dedent.md +117 -0
- package/docs/deepEqual.md +94 -0
- package/docs/enhancedMap.md +358 -0
- package/docs/exhaustiveMatch/-internal-.md +39 -0
- package/docs/exhaustiveMatch/README.md +146 -0
- package/docs/getAutoIncrementId.md +93 -0
- package/docs/getCompositeKey.md +39 -0
- package/docs/getValueStableKey.md +57 -0
- package/docs/hash.md +31 -0
- package/docs/interpolate/-internal-.md +61 -0
- package/docs/interpolate/README.md +62 -0
- package/docs/levenshtein.md +93 -0
- package/docs/main.md +21 -0
- package/docs/mathUtils.md +137 -0
- package/docs/modules.md +52 -0
- package/docs/objUtils.md +237 -0
- package/docs/parallelAsyncCalls/-internal-.md +347 -0
- package/docs/parallelAsyncCalls/README.md +45 -0
- package/docs/promiseUtils/-internal-.md +69 -0
- package/docs/promiseUtils/README.md +31 -0
- package/docs/retryOnError.md +67 -0
- package/docs/runShellCmd/-internal-.md +111 -0
- package/docs/runShellCmd/README.md +201 -0
- package/docs/safeJson.md +51 -0
- package/docs/saferTyping.md +228 -0
- package/docs/serializeXML.md +100 -0
- package/docs/shallowEqual.md +33 -0
- package/docs/sleep.md +27 -0
- package/docs/stringUtils/-internal-.md +17 -0
- package/docs/stringUtils/README.md +166 -0
- package/docs/testUtils.md +315 -0
- package/docs/throttle/-internal-.md +47 -0
- package/docs/throttle/README.md +178 -0
- package/docs/time.md +274 -0
- package/docs/timers.md +256 -0
- package/docs/tsResult/-internal-.md +327 -0
- package/docs/tsResult/README.md +696 -0
- package/docs/typeGuards.md +399 -0
- package/docs/typingFnUtils/-internal-.md +27 -0
- package/docs/typingFnUtils/README.md +293 -0
- package/docs/typingTestUtils.md +172 -0
- package/docs/typingUtils.md +111 -0
- package/docs/yamlStringify.md +45 -0
- package/lib/arrayUtils.js +3 -3
- package/lib/assertions.js +2 -2
- package/lib/awaitDebounce.cjs +106 -0
- package/lib/awaitDebounce.d.cts +38 -0
- package/lib/awaitDebounce.d.ts +38 -0
- package/lib/awaitDebounce.js +28 -0
- package/lib/cache.js +2 -2
- package/lib/{chunk-NH2LCAQS.js → chunk-6FIBVC2P.js} +1 -1
- package/lib/{chunk-GKOTKAIV.js → chunk-7CQPOM5I.js} +1 -1
- package/lib/{chunk-WS4WEVHU.js → chunk-C2SVCIWE.js} +1 -1
- package/lib/{chunk-SSKW673U.js → chunk-JF2MDHOJ.js} +5 -1
- package/lib/chunk-NW5H5EW7.js +100 -0
- package/lib/{chunk-DMW5Q4T2.js → chunk-SRVMMYSW.js} +1 -1
- package/lib/concurrentCalls.js +3 -3
- package/lib/createThrottleController.js +3 -3
- package/lib/debounce.js +4 -95
- package/lib/enhancedMap.js +3 -3
- package/lib/getAutoIncrementId.cjs +44 -0
- package/lib/getAutoIncrementId.d.cts +44 -0
- package/lib/getAutoIncrementId.d.ts +44 -0
- package/lib/getAutoIncrementId.js +18 -0
- package/lib/getCompositeKey.js +3 -3
- package/lib/getValueStableKey.js +3 -3
- package/lib/interpolate.js +2 -2
- package/lib/parallelAsyncCalls.js +2 -2
- package/lib/runShellCmd.d.cts +50 -0
- package/lib/runShellCmd.d.ts +50 -0
- package/lib/serializeXML.cjs +7 -2
- package/lib/serializeXML.d.cts +1 -1
- package/lib/serializeXML.d.ts +1 -1
- package/lib/serializeXML.js +7 -5
- package/lib/testUtils.js +3 -3
- package/lib/throttle.cjs +250 -0
- package/lib/throttle.d.cts +89 -0
- package/lib/throttle.d.ts +89 -0
- package/lib/throttle.js +38 -0
- package/lib/tsResult.js +2 -2
- package/lib/typeGuards.cjs +7 -2
- package/lib/typeGuards.d.cts +2 -1
- package/lib/typeGuards.d.ts +2 -1
- package/lib/typeGuards.js +5 -3
- package/lib/typingFnUtils.cjs +5 -1
- package/lib/typingFnUtils.d.cts +1 -1
- package/lib/typingFnUtils.d.ts +1 -1
- package/lib/typingFnUtils.js +5 -1
- package/lib/yamlStringify.js +5 -5
- package/package.json +22 -12
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
[**@ls-stack/utils**](README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@ls-stack/utils](modules.md) / typeGuards
|
|
6
|
+
|
|
7
|
+
# typeGuards
|
|
8
|
+
|
|
9
|
+
## Type Aliases
|
|
10
|
+
|
|
11
|
+
### NonEmptyArray\<T\>
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
type NonEmptyArray<T> = [T, ...T[]];
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Defined in: [packages/utils/src/typeGuards.ts:128](https://github.com/lucasols/utils/blob/main/packages/utils/src/typeGuards.ts#L128)
|
|
18
|
+
|
|
19
|
+
#### Type Parameters
|
|
20
|
+
|
|
21
|
+
##### T
|
|
22
|
+
|
|
23
|
+
`T`
|
|
24
|
+
|
|
25
|
+
## Functions
|
|
26
|
+
|
|
27
|
+
### arrayHasAtLeastXItems()
|
|
28
|
+
|
|
29
|
+
#### Call Signature
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
function arrayHasAtLeastXItems<T>(array, minLength): array is [T, ...T[]];
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Defined in: [packages/utils/src/typeGuards.ts:136](https://github.com/lucasols/utils/blob/main/packages/utils/src/typeGuards.ts#L136)
|
|
36
|
+
|
|
37
|
+
##### Type Parameters
|
|
38
|
+
|
|
39
|
+
###### T
|
|
40
|
+
|
|
41
|
+
`T`
|
|
42
|
+
|
|
43
|
+
##### Parameters
|
|
44
|
+
|
|
45
|
+
###### array
|
|
46
|
+
|
|
47
|
+
`T`[]
|
|
48
|
+
|
|
49
|
+
###### minLength
|
|
50
|
+
|
|
51
|
+
`1`
|
|
52
|
+
|
|
53
|
+
##### Returns
|
|
54
|
+
|
|
55
|
+
`array is [T, ...T[]]`
|
|
56
|
+
|
|
57
|
+
#### Call Signature
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
function arrayHasAtLeastXItems<T>(array, minLength): array is [T, T, ...T[]];
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Defined in: [packages/utils/src/typeGuards.ts:140](https://github.com/lucasols/utils/blob/main/packages/utils/src/typeGuards.ts#L140)
|
|
64
|
+
|
|
65
|
+
##### Type Parameters
|
|
66
|
+
|
|
67
|
+
###### T
|
|
68
|
+
|
|
69
|
+
`T`
|
|
70
|
+
|
|
71
|
+
##### Parameters
|
|
72
|
+
|
|
73
|
+
###### array
|
|
74
|
+
|
|
75
|
+
`T`[]
|
|
76
|
+
|
|
77
|
+
###### minLength
|
|
78
|
+
|
|
79
|
+
`2`
|
|
80
|
+
|
|
81
|
+
##### Returns
|
|
82
|
+
|
|
83
|
+
`array is [T, T, ...T[]]`
|
|
84
|
+
|
|
85
|
+
#### Call Signature
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
function arrayHasAtLeastXItems<T>(array, minLength): array is [T, T, T, ...T[]];
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Defined in: [packages/utils/src/typeGuards.ts:144](https://github.com/lucasols/utils/blob/main/packages/utils/src/typeGuards.ts#L144)
|
|
92
|
+
|
|
93
|
+
##### Type Parameters
|
|
94
|
+
|
|
95
|
+
###### T
|
|
96
|
+
|
|
97
|
+
`T`
|
|
98
|
+
|
|
99
|
+
##### Parameters
|
|
100
|
+
|
|
101
|
+
###### array
|
|
102
|
+
|
|
103
|
+
`T`[]
|
|
104
|
+
|
|
105
|
+
###### minLength
|
|
106
|
+
|
|
107
|
+
`3`
|
|
108
|
+
|
|
109
|
+
##### Returns
|
|
110
|
+
|
|
111
|
+
`array is [T, T, T, ...T[]]`
|
|
112
|
+
|
|
113
|
+
#### Call Signature
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
function arrayHasAtLeastXItems<T>(array, minLength): array is [T, T, T, T, ...T[]];
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Defined in: [packages/utils/src/typeGuards.ts:148](https://github.com/lucasols/utils/blob/main/packages/utils/src/typeGuards.ts#L148)
|
|
120
|
+
|
|
121
|
+
##### Type Parameters
|
|
122
|
+
|
|
123
|
+
###### T
|
|
124
|
+
|
|
125
|
+
`T`
|
|
126
|
+
|
|
127
|
+
##### Parameters
|
|
128
|
+
|
|
129
|
+
###### array
|
|
130
|
+
|
|
131
|
+
`T`[]
|
|
132
|
+
|
|
133
|
+
###### minLength
|
|
134
|
+
|
|
135
|
+
`4`
|
|
136
|
+
|
|
137
|
+
##### Returns
|
|
138
|
+
|
|
139
|
+
`array is [T, T, T, T, ...T[]]`
|
|
140
|
+
|
|
141
|
+
#### Call Signature
|
|
142
|
+
|
|
143
|
+
```ts
|
|
144
|
+
function arrayHasAtLeastXItems<T>(array, minLength): array is [T, T, T, T, T, ...T[]];
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Defined in: [packages/utils/src/typeGuards.ts:152](https://github.com/lucasols/utils/blob/main/packages/utils/src/typeGuards.ts#L152)
|
|
148
|
+
|
|
149
|
+
##### Type Parameters
|
|
150
|
+
|
|
151
|
+
###### T
|
|
152
|
+
|
|
153
|
+
`T`
|
|
154
|
+
|
|
155
|
+
##### Parameters
|
|
156
|
+
|
|
157
|
+
###### array
|
|
158
|
+
|
|
159
|
+
`T`[]
|
|
160
|
+
|
|
161
|
+
###### minLength
|
|
162
|
+
|
|
163
|
+
`5`
|
|
164
|
+
|
|
165
|
+
##### Returns
|
|
166
|
+
|
|
167
|
+
`array is [T, T, T, T, T, ...T[]]`
|
|
168
|
+
|
|
169
|
+
***
|
|
170
|
+
|
|
171
|
+
### isFunction()
|
|
172
|
+
|
|
173
|
+
```ts
|
|
174
|
+
function isFunction(value): value is (args: any[]) => any;
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
Defined in: [packages/utils/src/typeGuards.ts:51](https://github.com/lucasols/utils/blob/main/packages/utils/src/typeGuards.ts#L51)
|
|
178
|
+
|
|
179
|
+
Type guard to check if a value is a function.
|
|
180
|
+
|
|
181
|
+
Returns true if the value is a function of any kind (regular function,
|
|
182
|
+
arrow function, method, constructor, etc.).
|
|
183
|
+
|
|
184
|
+
#### Parameters
|
|
185
|
+
|
|
186
|
+
##### value
|
|
187
|
+
|
|
188
|
+
`unknown`
|
|
189
|
+
|
|
190
|
+
The value to check
|
|
191
|
+
|
|
192
|
+
#### Returns
|
|
193
|
+
|
|
194
|
+
`value is (args: any[]) => any`
|
|
195
|
+
|
|
196
|
+
True if the value is a function, false otherwise
|
|
197
|
+
|
|
198
|
+
#### Example
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
if (isFunction(value)) {
|
|
202
|
+
// TypeScript knows value is (...args: any[]) => any
|
|
203
|
+
const result = value();
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
isFunction(() => {}); // true
|
|
207
|
+
isFunction(function() {}); // true
|
|
208
|
+
isFunction(Math.max); // true
|
|
209
|
+
isFunction('string'); // false
|
|
210
|
+
isFunction({}); // false
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
***
|
|
214
|
+
|
|
215
|
+
### isNonEmptyArray()
|
|
216
|
+
|
|
217
|
+
```ts
|
|
218
|
+
function isNonEmptyArray<T>(value): value is NonEmptyArray<T>;
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
Defined in: [packages/utils/src/typeGuards.ts:130](https://github.com/lucasols/utils/blob/main/packages/utils/src/typeGuards.ts#L130)
|
|
222
|
+
|
|
223
|
+
#### Type Parameters
|
|
224
|
+
|
|
225
|
+
##### T
|
|
226
|
+
|
|
227
|
+
`T`
|
|
228
|
+
|
|
229
|
+
#### Parameters
|
|
230
|
+
|
|
231
|
+
##### value
|
|
232
|
+
|
|
233
|
+
`T`[] | readonly `T`[]
|
|
234
|
+
|
|
235
|
+
#### Returns
|
|
236
|
+
|
|
237
|
+
`value is NonEmptyArray<T>`
|
|
238
|
+
|
|
239
|
+
***
|
|
240
|
+
|
|
241
|
+
### isObject()
|
|
242
|
+
|
|
243
|
+
```ts
|
|
244
|
+
function isObject(value): value is Record<string, unknown>;
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
Defined in: [packages/utils/src/typeGuards.ts:24](https://github.com/lucasols/utils/blob/main/packages/utils/src/typeGuards.ts#L24)
|
|
248
|
+
|
|
249
|
+
Type guard to check if a value is a plain object (not null, not an array).
|
|
250
|
+
|
|
251
|
+
Returns true if the value is an object that is not null and not an array.
|
|
252
|
+
This is useful for distinguishing between objects and other types.
|
|
253
|
+
|
|
254
|
+
#### Parameters
|
|
255
|
+
|
|
256
|
+
##### value
|
|
257
|
+
|
|
258
|
+
`unknown`
|
|
259
|
+
|
|
260
|
+
The value to check
|
|
261
|
+
|
|
262
|
+
#### Returns
|
|
263
|
+
|
|
264
|
+
`value is Record<string, unknown>`
|
|
265
|
+
|
|
266
|
+
True if the value is a plain object, false otherwise
|
|
267
|
+
|
|
268
|
+
#### Example
|
|
269
|
+
|
|
270
|
+
```typescript
|
|
271
|
+
if (isObject(value)) {
|
|
272
|
+
// TypeScript knows value is Record<string, unknown>
|
|
273
|
+
console.log(value.someProperty);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
isObject({}); // true
|
|
277
|
+
isObject({ a: 1 }); // true
|
|
278
|
+
isObject(null); // false
|
|
279
|
+
isObject([]); // false
|
|
280
|
+
isObject('string'); // false
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
***
|
|
284
|
+
|
|
285
|
+
### isPlainObject()
|
|
286
|
+
|
|
287
|
+
```ts
|
|
288
|
+
function isPlainObject(value): value is Record<string, unknown>;
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
Defined in: [packages/utils/src/typeGuards.ts:109](https://github.com/lucasols/utils/blob/main/packages/utils/src/typeGuards.ts#L109)
|
|
292
|
+
|
|
293
|
+
Type guard to check if a value is a plain object (created by Object literal or Object constructor).
|
|
294
|
+
|
|
295
|
+
Returns true if the value is a plain object - an object created by the Object
|
|
296
|
+
constructor or object literal syntax. This excludes instances of classes,
|
|
297
|
+
built-in objects like Date, RegExp, etc.
|
|
298
|
+
|
|
299
|
+
#### Parameters
|
|
300
|
+
|
|
301
|
+
##### value
|
|
302
|
+
|
|
303
|
+
`any`
|
|
304
|
+
|
|
305
|
+
The value to check
|
|
306
|
+
|
|
307
|
+
#### Returns
|
|
308
|
+
|
|
309
|
+
`value is Record<string, unknown>`
|
|
310
|
+
|
|
311
|
+
True if the value is a plain object, false otherwise
|
|
312
|
+
|
|
313
|
+
#### Example
|
|
314
|
+
|
|
315
|
+
```typescript
|
|
316
|
+
if (isPlainObject(value)) {
|
|
317
|
+
// TypeScript knows value is Record<string, unknown>
|
|
318
|
+
console.log(Object.keys(value));
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
isPlainObject({}); // true
|
|
322
|
+
isPlainObject({ a: 1 }); // true
|
|
323
|
+
isPlainObject(Object.create(null)); // true
|
|
324
|
+
isPlainObject(new Date()); // false
|
|
325
|
+
isPlainObject(/regex/); // false
|
|
326
|
+
isPlainObject(new MyClass()); // false
|
|
327
|
+
isPlainObject([]); // false
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
***
|
|
331
|
+
|
|
332
|
+
### isPromise()
|
|
333
|
+
|
|
334
|
+
```ts
|
|
335
|
+
function isPromise(value): value is Promise<unknown>;
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
Defined in: [packages/utils/src/typeGuards.ts:79](https://github.com/lucasols/utils/blob/main/packages/utils/src/typeGuards.ts#L79)
|
|
339
|
+
|
|
340
|
+
Type guard to check if a value is a Promise or thenable object.
|
|
341
|
+
|
|
342
|
+
Returns true if the value is an object with a `then` method that is a function.
|
|
343
|
+
This covers both native Promises and thenable objects that implement the
|
|
344
|
+
Promise interface.
|
|
345
|
+
|
|
346
|
+
#### Parameters
|
|
347
|
+
|
|
348
|
+
##### value
|
|
349
|
+
|
|
350
|
+
`unknown`
|
|
351
|
+
|
|
352
|
+
The value to check
|
|
353
|
+
|
|
354
|
+
#### Returns
|
|
355
|
+
|
|
356
|
+
`value is Promise<unknown>`
|
|
357
|
+
|
|
358
|
+
True if the value is a Promise or thenable, false otherwise
|
|
359
|
+
|
|
360
|
+
#### Example
|
|
361
|
+
|
|
362
|
+
```typescript
|
|
363
|
+
if (isPromise(value)) {
|
|
364
|
+
// TypeScript knows value is Promise<unknown>
|
|
365
|
+
const result = await value;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
isPromise(Promise.resolve()); // true
|
|
369
|
+
isPromise(new Promise(() => {})); // true
|
|
370
|
+
isPromise({ then: () => {} }); // true
|
|
371
|
+
isPromise({ then: 'not a function' }); // false
|
|
372
|
+
isPromise('string'); // false
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
***
|
|
376
|
+
|
|
377
|
+
### isTruthy()
|
|
378
|
+
|
|
379
|
+
```ts
|
|
380
|
+
function isTruthy<T>(value): value is Exclude<T, undefined | null | false | "" | 0 | 0n>;
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
Defined in: [packages/utils/src/typeGuards.ts:163](https://github.com/lucasols/utils/blob/main/packages/utils/src/typeGuards.ts#L163)
|
|
384
|
+
|
|
385
|
+
#### Type Parameters
|
|
386
|
+
|
|
387
|
+
##### T
|
|
388
|
+
|
|
389
|
+
`T`
|
|
390
|
+
|
|
391
|
+
#### Parameters
|
|
392
|
+
|
|
393
|
+
##### value
|
|
394
|
+
|
|
395
|
+
`T`
|
|
396
|
+
|
|
397
|
+
#### Returns
|
|
398
|
+
|
|
399
|
+
value is Exclude\<T, undefined \| null \| false \| "" \| 0 \| 0n\>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
[**@ls-stack/utils**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@ls-stack/utils](../modules.md) / [typingFnUtils](README.md) / \<internal\>
|
|
6
|
+
|
|
7
|
+
# \<internal\>
|
|
8
|
+
|
|
9
|
+
## Type Aliases
|
|
10
|
+
|
|
11
|
+
### UnionDiff\<T, U\>
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
type UnionDiff<T, U> = [T] extends [U] ? [U] extends [T] ? null : object : [U] extends [T] ? object : object;
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Defined in: [packages/utils/src/typingFnUtils.ts:77](https://github.com/lucasols/utils/blob/main/packages/utils/src/typingFnUtils.ts#L77)
|
|
18
|
+
|
|
19
|
+
#### Type Parameters
|
|
20
|
+
|
|
21
|
+
##### T
|
|
22
|
+
|
|
23
|
+
`T`
|
|
24
|
+
|
|
25
|
+
##### U
|
|
26
|
+
|
|
27
|
+
`U`
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
[**@ls-stack/utils**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@ls-stack/utils](../modules.md) / typingFnUtils
|
|
6
|
+
|
|
7
|
+
# typingFnUtils
|
|
8
|
+
|
|
9
|
+
## Modules
|
|
10
|
+
|
|
11
|
+
- [\<internal\>](-internal-.md)
|
|
12
|
+
|
|
13
|
+
## Variables
|
|
14
|
+
|
|
15
|
+
### ~~isSubTypeOf()~~
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
const isSubTypeOf: <BaseType, SubType>() => unknown = typeOnRightExtendsLeftType;
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Defined in: [packages/utils/src/typingFnUtils.ts:65](https://github.com/lucasols/utils/blob/main/packages/utils/src/typingFnUtils.ts#L65)
|
|
22
|
+
|
|
23
|
+
Type helper to check if a type is a subtype of another type.
|
|
24
|
+
|
|
25
|
+
#### Type Parameters
|
|
26
|
+
|
|
27
|
+
##### BaseType
|
|
28
|
+
|
|
29
|
+
`BaseType`
|
|
30
|
+
|
|
31
|
+
The base type to check against
|
|
32
|
+
|
|
33
|
+
##### SubType
|
|
34
|
+
|
|
35
|
+
`SubType`
|
|
36
|
+
|
|
37
|
+
The type that should extend BaseType
|
|
38
|
+
|
|
39
|
+
#### Returns
|
|
40
|
+
|
|
41
|
+
`unknown`
|
|
42
|
+
|
|
43
|
+
Returns undefined, only used for type checking
|
|
44
|
+
|
|
45
|
+
#### Deprecated
|
|
46
|
+
|
|
47
|
+
use typeOnRightExtendsLeftType instead
|
|
48
|
+
|
|
49
|
+
## Functions
|
|
50
|
+
|
|
51
|
+
### asNonPartial()
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
function asNonPartial<T>(obj): NonPartial<T>;
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Defined in: [packages/utils/src/typingFnUtils.ts:3](https://github.com/lucasols/utils/blob/main/packages/utils/src/typingFnUtils.ts#L3)
|
|
58
|
+
|
|
59
|
+
#### Type Parameters
|
|
60
|
+
|
|
61
|
+
##### T
|
|
62
|
+
|
|
63
|
+
`T` *extends* `Record`\<`string`, `unknown`\>
|
|
64
|
+
|
|
65
|
+
#### Parameters
|
|
66
|
+
|
|
67
|
+
##### obj
|
|
68
|
+
|
|
69
|
+
`T`
|
|
70
|
+
|
|
71
|
+
#### Returns
|
|
72
|
+
|
|
73
|
+
[`NonPartial`](../typingUtils.md#nonpartial)\<`T`\>
|
|
74
|
+
|
|
75
|
+
***
|
|
76
|
+
|
|
77
|
+
### asType()
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
function asType<T>(value): T;
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Defined in: [packages/utils/src/typingFnUtils.ts:28](https://github.com/lucasols/utils/blob/main/packages/utils/src/typingFnUtils.ts#L28)
|
|
84
|
+
|
|
85
|
+
a safe way to cast types, use to substitute the `as Type`
|
|
86
|
+
|
|
87
|
+
#### Type Parameters
|
|
88
|
+
|
|
89
|
+
##### T
|
|
90
|
+
|
|
91
|
+
`T` = `unknown`
|
|
92
|
+
|
|
93
|
+
#### Parameters
|
|
94
|
+
|
|
95
|
+
##### value
|
|
96
|
+
|
|
97
|
+
`T`
|
|
98
|
+
|
|
99
|
+
#### Returns
|
|
100
|
+
|
|
101
|
+
`T`
|
|
102
|
+
|
|
103
|
+
***
|
|
104
|
+
|
|
105
|
+
### isObjKey()
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
function isObjKey<T>(key, obj): key is keyof T;
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Defined in: [packages/utils/src/typingFnUtils.ts:70](https://github.com/lucasols/utils/blob/main/packages/utils/src/typingFnUtils.ts#L70)
|
|
112
|
+
|
|
113
|
+
Type helper to narrow a string to a key of an object.
|
|
114
|
+
|
|
115
|
+
#### Type Parameters
|
|
116
|
+
|
|
117
|
+
##### T
|
|
118
|
+
|
|
119
|
+
`T` *extends* `Record`\<`string`, `unknown`\>
|
|
120
|
+
|
|
121
|
+
#### Parameters
|
|
122
|
+
|
|
123
|
+
##### key
|
|
124
|
+
|
|
125
|
+
`unknown`
|
|
126
|
+
|
|
127
|
+
##### obj
|
|
128
|
+
|
|
129
|
+
`T`
|
|
130
|
+
|
|
131
|
+
#### Returns
|
|
132
|
+
|
|
133
|
+
`key is keyof T`
|
|
134
|
+
|
|
135
|
+
***
|
|
136
|
+
|
|
137
|
+
### narrowStringToUnion()
|
|
138
|
+
|
|
139
|
+
```ts
|
|
140
|
+
function narrowStringToUnion<T>(key, union): undefined | T;
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Defined in: [packages/utils/src/typingFnUtils.ts:33](https://github.com/lucasols/utils/blob/main/packages/utils/src/typingFnUtils.ts#L33)
|
|
144
|
+
|
|
145
|
+
narrow a string to a union of strings
|
|
146
|
+
|
|
147
|
+
#### Type Parameters
|
|
148
|
+
|
|
149
|
+
##### T
|
|
150
|
+
|
|
151
|
+
`T` *extends* `string`
|
|
152
|
+
|
|
153
|
+
#### Parameters
|
|
154
|
+
|
|
155
|
+
##### key
|
|
156
|
+
|
|
157
|
+
`undefined` | `null` | `string`
|
|
158
|
+
|
|
159
|
+
##### union
|
|
160
|
+
|
|
161
|
+
`Set`\<`T`\> | `T`[] | readonly `T`[]
|
|
162
|
+
|
|
163
|
+
#### Returns
|
|
164
|
+
|
|
165
|
+
`undefined` \| `T`
|
|
166
|
+
|
|
167
|
+
***
|
|
168
|
+
|
|
169
|
+
### typedObjectEntries()
|
|
170
|
+
|
|
171
|
+
```ts
|
|
172
|
+
function typedObjectEntries<T>(obj): NonNullable<{ [K in string | number | symbol]: [K, T[K]] }[keyof T]>[];
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
Defined in: [packages/utils/src/typingFnUtils.ts:10](https://github.com/lucasols/utils/blob/main/packages/utils/src/typingFnUtils.ts#L10)
|
|
176
|
+
|
|
177
|
+
a wrapper to Object.entries with a better typing inference
|
|
178
|
+
|
|
179
|
+
#### Type Parameters
|
|
180
|
+
|
|
181
|
+
##### T
|
|
182
|
+
|
|
183
|
+
`T` *extends* `Record`\<`string`, `unknown`\>
|
|
184
|
+
|
|
185
|
+
#### Parameters
|
|
186
|
+
|
|
187
|
+
##### obj
|
|
188
|
+
|
|
189
|
+
`T`
|
|
190
|
+
|
|
191
|
+
#### Returns
|
|
192
|
+
|
|
193
|
+
`NonNullable`\<\{ \[K in string \| number \| symbol\]: \[K, T\[K\]\] \}\[keyof `T`\]\>[]
|
|
194
|
+
|
|
195
|
+
***
|
|
196
|
+
|
|
197
|
+
### typedObjectKeys()
|
|
198
|
+
|
|
199
|
+
```ts
|
|
200
|
+
function typedObjectKeys<T>(obj): keyof T[];
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
Defined in: [packages/utils/src/typingFnUtils.ts:21](https://github.com/lucasols/utils/blob/main/packages/utils/src/typingFnUtils.ts#L21)
|
|
204
|
+
|
|
205
|
+
a wrapper to Object.keys with a better typing inference
|
|
206
|
+
|
|
207
|
+
#### Type Parameters
|
|
208
|
+
|
|
209
|
+
##### T
|
|
210
|
+
|
|
211
|
+
`T` *extends* `Record`\<`string`, `unknown`\>
|
|
212
|
+
|
|
213
|
+
#### Parameters
|
|
214
|
+
|
|
215
|
+
##### obj
|
|
216
|
+
|
|
217
|
+
`T`
|
|
218
|
+
|
|
219
|
+
#### Returns
|
|
220
|
+
|
|
221
|
+
keyof `T`[]
|
|
222
|
+
|
|
223
|
+
***
|
|
224
|
+
|
|
225
|
+
### typeOnRightExtendsLeftType()
|
|
226
|
+
|
|
227
|
+
```ts
|
|
228
|
+
function typeOnRightExtendsLeftType<BaseType, SubType>(): unknown;
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
Defined in: [packages/utils/src/typingFnUtils.ts:57](https://github.com/lucasols/utils/blob/main/packages/utils/src/typingFnUtils.ts#L57)
|
|
232
|
+
|
|
233
|
+
Type helper to check if a type is a subtype of another type.
|
|
234
|
+
|
|
235
|
+
#### Type Parameters
|
|
236
|
+
|
|
237
|
+
##### BaseType
|
|
238
|
+
|
|
239
|
+
`BaseType`
|
|
240
|
+
|
|
241
|
+
The base type to check against
|
|
242
|
+
|
|
243
|
+
##### SubType
|
|
244
|
+
|
|
245
|
+
`SubType`
|
|
246
|
+
|
|
247
|
+
The type that should extend BaseType
|
|
248
|
+
|
|
249
|
+
#### Returns
|
|
250
|
+
|
|
251
|
+
`unknown`
|
|
252
|
+
|
|
253
|
+
Returns undefined, only used for type checking
|
|
254
|
+
|
|
255
|
+
***
|
|
256
|
+
|
|
257
|
+
### unionsAreTheSame()
|
|
258
|
+
|
|
259
|
+
```ts
|
|
260
|
+
function unionsAreTheSame<T, U>(_diff): void;
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
Defined in: [packages/utils/src/typingFnUtils.ts:93](https://github.com/lucasols/utils/blob/main/packages/utils/src/typingFnUtils.ts#L93)
|
|
264
|
+
|
|
265
|
+
Type helper to compare two union types and determine their relationship.
|
|
266
|
+
|
|
267
|
+
#### Type Parameters
|
|
268
|
+
|
|
269
|
+
##### T
|
|
270
|
+
|
|
271
|
+
`T`
|
|
272
|
+
|
|
273
|
+
The first union type (left side)
|
|
274
|
+
|
|
275
|
+
##### U
|
|
276
|
+
|
|
277
|
+
`U`
|
|
278
|
+
|
|
279
|
+
The second union type (right side)
|
|
280
|
+
|
|
281
|
+
#### Parameters
|
|
282
|
+
|
|
283
|
+
##### \_diff
|
|
284
|
+
|
|
285
|
+
[`UnionDiff`](-internal-.md#uniondiff)\<`T`, `U`\>
|
|
286
|
+
|
|
287
|
+
null if unions are identical, or an object describing the errors
|
|
288
|
+
|
|
289
|
+
#### Returns
|
|
290
|
+
|
|
291
|
+
`void`
|
|
292
|
+
|
|
293
|
+
void - This function is only used for type checking
|