@xylabs/object 5.0.83 → 5.0.86
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 +642 -780
- package/dist/neutral/AsObjectFactory.d.ts +1 -0
- package/dist/neutral/AsObjectFactory.d.ts.map +1 -1
- package/dist/neutral/AsTypeFactory.d.ts +4 -0
- package/dist/neutral/AsTypeFactory.d.ts.map +1 -1
- package/dist/neutral/IsObjectFactory.d.ts +8 -0
- package/dist/neutral/IsObjectFactory.d.ts.map +1 -1
- package/dist/neutral/JsonObject.d.ts +13 -0
- package/dist/neutral/JsonObject.d.ts.map +1 -1
- package/dist/neutral/ObjectWrapper.d.ts +1 -0
- package/dist/neutral/ObjectWrapper.d.ts.map +1 -1
- package/dist/neutral/OmitStartsWith.d.ts +4 -0
- package/dist/neutral/OmitStartsWith.d.ts.map +1 -1
- package/dist/neutral/Optional.d.ts +1 -0
- package/dist/neutral/Optional.d.ts.map +1 -1
- package/dist/neutral/Override.d.ts +1 -0
- package/dist/neutral/Override.d.ts.map +1 -1
- package/dist/neutral/PickStartsWith.d.ts +2 -0
- package/dist/neutral/PickStartsWith.d.ts.map +1 -1
- package/dist/neutral/Simplify.d.ts +1 -0
- package/dist/neutral/Simplify.d.ts.map +1 -1
- package/dist/neutral/StringKeyObject.d.ts +1 -0
- package/dist/neutral/StringKeyObject.d.ts.map +1 -1
- package/dist/neutral/Validator.d.ts +2 -0
- package/dist/neutral/Validator.d.ts.map +1 -1
- package/dist/neutral/WithAdditional.d.ts +1 -0
- package/dist/neutral/WithAdditional.d.ts.map +1 -1
- package/dist/neutral/asObject.d.ts +1 -0
- package/dist/neutral/asObject.d.ts.map +1 -1
- package/dist/neutral/index-un-deprecated.mjs +6 -0
- package/dist/neutral/index-un-deprecated.mjs.map +1 -1
- package/dist/neutral/index.mjs +6 -0
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/neutral/omitBy.d.ts +15 -0
- package/dist/neutral/omitBy.d.ts.map +1 -1
- package/dist/neutral/pickBy.d.ts +15 -0
- package/dist/neutral/pickBy.d.ts.map +1 -1
- package/dist/neutral/removeFields.d.ts +6 -0
- package/dist/neutral/removeFields.d.ts.map +1 -1
- package/dist/neutral/toSafeJson.d.ts +34 -0
- package/dist/neutral/toSafeJson.d.ts.map +1 -1
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
|
|
16
16
|
Base functionality used throughout XY Labs TypeScript/JavaScript libraries
|
|
17
17
|
|
|
18
|
+
|
|
19
|
+
|
|
18
20
|
## Reference
|
|
19
21
|
|
|
20
22
|
**@xylabs/object**
|
|
@@ -23,9 +25,11 @@ Base functionality used throughout XY Labs TypeScript/JavaScript libraries
|
|
|
23
25
|
|
|
24
26
|
## Modules
|
|
25
27
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
| Module | Description |
|
|
29
|
+
| ------ | ------ |
|
|
30
|
+
| [index-deprecated](#index-deprecated/README) | - |
|
|
31
|
+
| [index-un-deprecated](#index-un-deprecated/README) | - |
|
|
32
|
+
| [index](#index/README) | - |
|
|
29
33
|
|
|
30
34
|
### index
|
|
31
35
|
|
|
@@ -39,11 +43,13 @@ Base functionality used throughout XY Labs TypeScript/JavaScript libraries
|
|
|
39
43
|
|
|
40
44
|
***
|
|
41
45
|
|
|
42
|
-
|
|
46
|
+
Factory class for creating type-guard functions that validate objects against a given shape and optional additional checks.
|
|
43
47
|
|
|
44
|
-
|
|
48
|
+
## Type Parameters
|
|
45
49
|
|
|
46
|
-
|
|
50
|
+
| Type Parameter |
|
|
51
|
+
| ------ |
|
|
52
|
+
| `T` *extends* `TypedObject` |
|
|
47
53
|
|
|
48
54
|
## Constructors
|
|
49
55
|
|
|
@@ -62,52 +68,55 @@ new IsObjectFactory<T>(): IsObjectFactory<T>;
|
|
|
62
68
|
### create()
|
|
63
69
|
|
|
64
70
|
```ts
|
|
65
|
-
create(shape
|
|
71
|
+
create(shape?: ObjectTypeShape, additionalChecks?: TypeCheck<TypedObject>[]): TypeCheck<T>;
|
|
66
72
|
```
|
|
67
73
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
#### shape?
|
|
74
|
+
Creates a type-guard function that validates an object matches the given shape and passes additional checks.
|
|
71
75
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
#### additionalChecks?
|
|
76
|
+
### Parameters
|
|
75
77
|
|
|
76
|
-
|
|
78
|
+
| Parameter | Type | Description |
|
|
79
|
+
| ------ | ------ | ------ |
|
|
80
|
+
| `shape?` | `ObjectTypeShape` | An optional map of property names to expected types. |
|
|
81
|
+
| `additionalChecks?` | [`TypeCheck`](#../type-aliases/TypeCheck)\<`TypedObject`\>[] | Optional extra type-check functions to run after shape validation. |
|
|
77
82
|
|
|
78
83
|
### Returns
|
|
79
84
|
|
|
80
85
|
[`TypeCheck`](#../type-aliases/TypeCheck)\<`T`\>
|
|
81
86
|
|
|
87
|
+
A type-guard function for type T.
|
|
88
|
+
|
|
82
89
|
### <a id="ObjectWrapper"></a>ObjectWrapper
|
|
83
90
|
|
|
84
91
|
[**@xylabs/object**](#../../README)
|
|
85
92
|
|
|
86
93
|
***
|
|
87
94
|
|
|
95
|
+
Abstract base class that wraps an object and provides typed access to it.
|
|
96
|
+
|
|
88
97
|
## Extended by
|
|
89
98
|
|
|
90
99
|
- [`ValidatorBase`](#ValidatorBase)
|
|
91
100
|
|
|
92
101
|
## Type Parameters
|
|
93
102
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
`T` *extends* [`EmptyObject`](#../type-aliases/EmptyObject)
|
|
103
|
+
| Type Parameter | Default type |
|
|
104
|
+
| ------ | ------ |
|
|
105
|
+
| `T` *extends* [`EmptyObject`](#../type-aliases/EmptyObject) | [`EmptyObject`](#../type-aliases/EmptyObject) |
|
|
97
106
|
|
|
98
107
|
## Constructors
|
|
99
108
|
|
|
100
109
|
### Constructor
|
|
101
110
|
|
|
102
111
|
```ts
|
|
103
|
-
new ObjectWrapper<T>(obj): ObjectWrapper<T>;
|
|
112
|
+
new ObjectWrapper<T>(obj: T): ObjectWrapper<T>;
|
|
104
113
|
```
|
|
105
114
|
|
|
106
115
|
### Parameters
|
|
107
116
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
`T`
|
|
117
|
+
| Parameter | Type |
|
|
118
|
+
| ------ | ------ |
|
|
119
|
+
| `obj` | `T` |
|
|
111
120
|
|
|
112
121
|
### Returns
|
|
113
122
|
|
|
@@ -115,11 +124,9 @@ new ObjectWrapper<T>(obj): ObjectWrapper<T>;
|
|
|
115
124
|
|
|
116
125
|
## Properties
|
|
117
126
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
readonly obj: T;
|
|
122
|
-
```
|
|
127
|
+
| Property | Modifier | Type |
|
|
128
|
+
| ------ | ------ | ------ |
|
|
129
|
+
| <a id="obj"></a> `obj` | `readonly` | `T` |
|
|
123
130
|
|
|
124
131
|
## Accessors
|
|
125
132
|
|
|
@@ -141,15 +148,17 @@ get protected stringKeyObj(): StringKeyObject;
|
|
|
141
148
|
|
|
142
149
|
***
|
|
143
150
|
|
|
151
|
+
Abstract base class for validators that wraps a partial object and provides a validation method.
|
|
152
|
+
|
|
144
153
|
## Extends
|
|
145
154
|
|
|
146
155
|
- [`ObjectWrapper`](#ObjectWrapper)\<`Partial`\<`T`\>\>
|
|
147
156
|
|
|
148
157
|
## Type Parameters
|
|
149
158
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
`T` *extends* [`EmptyObject`](#../type-aliases/EmptyObject)
|
|
159
|
+
| Type Parameter | Default type |
|
|
160
|
+
| ------ | ------ |
|
|
161
|
+
| `T` *extends* [`EmptyObject`](#../type-aliases/EmptyObject) | [`AnyObject`](#../type-aliases/AnyObject) |
|
|
153
162
|
|
|
154
163
|
## Implements
|
|
155
164
|
|
|
@@ -160,14 +169,14 @@ get protected stringKeyObj(): StringKeyObject;
|
|
|
160
169
|
### Constructor
|
|
161
170
|
|
|
162
171
|
```ts
|
|
163
|
-
new ValidatorBase<T>(obj): ValidatorBase<T>;
|
|
172
|
+
new ValidatorBase<T>(obj: T): ValidatorBase<T>;
|
|
164
173
|
```
|
|
165
174
|
|
|
166
175
|
### Parameters
|
|
167
176
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
`T`
|
|
177
|
+
| Parameter | Type |
|
|
178
|
+
| ------ | ------ |
|
|
179
|
+
| `obj` | `T` |
|
|
171
180
|
|
|
172
181
|
### Returns
|
|
173
182
|
|
|
@@ -179,15 +188,9 @@ new ValidatorBase<T>(obj): ValidatorBase<T>;
|
|
|
179
188
|
|
|
180
189
|
## Properties
|
|
181
190
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
readonly obj: T;
|
|
186
|
-
```
|
|
187
|
-
|
|
188
|
-
### Inherited from
|
|
189
|
-
|
|
190
|
-
[`ObjectWrapper`](#ObjectWrapper).[`obj`](ObjectWrapper.md#obj)
|
|
191
|
+
| Property | Modifier | Type | Inherited from |
|
|
192
|
+
| ------ | ------ | ------ | ------ |
|
|
193
|
+
| <a id="obj"></a> `obj` | `readonly` | `T` | [`ObjectWrapper`](#ObjectWrapper).[`obj`](ObjectWrapper.md#obj) |
|
|
191
194
|
|
|
192
195
|
## Accessors
|
|
193
196
|
|
|
@@ -212,14 +215,14 @@ get protected stringKeyObj(): StringKeyObject;
|
|
|
212
215
|
### validate()
|
|
213
216
|
|
|
214
217
|
```ts
|
|
215
|
-
abstract validate(payload): Promisable<Error[]>;
|
|
218
|
+
abstract validate(payload: T): Promisable<Error[]>;
|
|
216
219
|
```
|
|
217
220
|
|
|
218
221
|
### Parameters
|
|
219
222
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
`T`
|
|
223
|
+
| Parameter | Type |
|
|
224
|
+
| ------ | ------ |
|
|
225
|
+
| `payload` | `T` |
|
|
223
226
|
|
|
224
227
|
### Returns
|
|
225
228
|
|
|
@@ -238,38 +241,36 @@ abstract validate(payload): Promisable<Error[]>;
|
|
|
238
241
|
***
|
|
239
242
|
|
|
240
243
|
```ts
|
|
241
|
-
function createDeepMerge(options): <T>(...objects) => MergeAll<T>;
|
|
244
|
+
function createDeepMerge(options: MergeOptions): <T>(...objects: T) => MergeAll<T>;
|
|
242
245
|
```
|
|
243
246
|
|
|
244
247
|
Creates a deep merge function with the specified options.
|
|
245
248
|
|
|
246
249
|
## Parameters
|
|
247
250
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
`MergeOptions`
|
|
251
|
-
|
|
252
|
-
Options for merging.
|
|
251
|
+
| Parameter | Type | Description |
|
|
252
|
+
| ------ | ------ | ------ |
|
|
253
|
+
| `options` | `MergeOptions` | Options for merging. |
|
|
253
254
|
|
|
254
255
|
## Returns
|
|
255
256
|
|
|
256
257
|
A deep merge function configured for the specified options.
|
|
257
258
|
|
|
258
259
|
```ts
|
|
259
|
-
<T>(...objects): MergeAll<T>;
|
|
260
|
+
<T>(...objects: T): MergeAll<T>;
|
|
260
261
|
```
|
|
261
262
|
|
|
262
263
|
### Type Parameters
|
|
263
264
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
`T` *extends* [`AnyObject`](#../type-aliases/AnyObject)[]
|
|
265
|
+
| Type Parameter |
|
|
266
|
+
| ------ |
|
|
267
|
+
| `T` *extends* [`AnyObject`](#../type-aliases/AnyObject)[] |
|
|
267
268
|
|
|
268
269
|
### Parameters
|
|
269
270
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
...`T`
|
|
271
|
+
| Parameter | Type |
|
|
272
|
+
| ------ | ------ |
|
|
273
|
+
| ...`objects` | `T` |
|
|
273
274
|
|
|
274
275
|
### Returns
|
|
275
276
|
|
|
@@ -284,14 +285,16 @@ A deep merge function configured for the specified options.
|
|
|
284
285
|
## Call Signature
|
|
285
286
|
|
|
286
287
|
```ts
|
|
287
|
-
function isObject(value): value is object;
|
|
288
|
+
function isObject(value: unknown): value is object;
|
|
288
289
|
```
|
|
289
290
|
|
|
290
|
-
|
|
291
|
+
Type guard that checks whether a value is a plain object (not null and not an array).
|
|
291
292
|
|
|
292
|
-
###
|
|
293
|
+
### Parameters
|
|
293
294
|
|
|
294
|
-
|
|
295
|
+
| Parameter | Type |
|
|
296
|
+
| ------ | ------ |
|
|
297
|
+
| `value` | `unknown` |
|
|
295
298
|
|
|
296
299
|
### Returns
|
|
297
300
|
|
|
@@ -300,20 +303,22 @@ function isObject(value): value is object;
|
|
|
300
303
|
## Call Signature
|
|
301
304
|
|
|
302
305
|
```ts
|
|
303
|
-
function isObject<T>(value): value is Extract<T, object>;
|
|
306
|
+
function isObject<T>(value: T): value is Extract<T, object>;
|
|
304
307
|
```
|
|
305
308
|
|
|
306
|
-
|
|
309
|
+
Type guard that checks whether a value is a plain object (not null and not an array).
|
|
307
310
|
|
|
308
|
-
###
|
|
311
|
+
### Type Parameters
|
|
309
312
|
|
|
310
|
-
|
|
313
|
+
| Type Parameter |
|
|
314
|
+
| ------ |
|
|
315
|
+
| `T` *extends* `object` |
|
|
311
316
|
|
|
312
317
|
### Parameters
|
|
313
318
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
`T`
|
|
319
|
+
| Parameter | Type |
|
|
320
|
+
| ------ | ------ |
|
|
321
|
+
| `value` | `T` |
|
|
317
322
|
|
|
318
323
|
### Returns
|
|
319
324
|
|
|
@@ -326,18 +331,15 @@ function isObject<T>(value): value is Extract<T, object>;
|
|
|
326
331
|
***
|
|
327
332
|
|
|
328
333
|
```ts
|
|
329
|
-
function isType(value, expectedType): boolean;
|
|
334
|
+
function isType(value: unknown, expectedType: FieldType): boolean;
|
|
330
335
|
```
|
|
331
336
|
|
|
332
337
|
## Parameters
|
|
333
338
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
`unknown`
|
|
337
|
-
|
|
338
|
-
### expectedType
|
|
339
|
-
|
|
340
|
-
`FieldType`
|
|
339
|
+
| Parameter | Type |
|
|
340
|
+
| ------ | ------ |
|
|
341
|
+
| `value` | `unknown` |
|
|
342
|
+
| `expectedType` | `FieldType` |
|
|
341
343
|
|
|
342
344
|
## Returns
|
|
343
345
|
|
|
@@ -355,35 +357,33 @@ use from @xylabs/typeof instead
|
|
|
355
357
|
|
|
356
358
|
```ts
|
|
357
359
|
function omitBy<T>(
|
|
358
|
-
obj,
|
|
359
|
-
predicate,
|
|
360
|
-
maxDepth
|
|
360
|
+
obj: T,
|
|
361
|
+
predicate: OmitByPredicate,
|
|
362
|
+
maxDepth?: number): Partial<T>;
|
|
361
363
|
```
|
|
362
364
|
|
|
363
|
-
|
|
365
|
+
Creates a new object excluding properties that satisfy the predicate, with optional recursive depth.
|
|
364
366
|
|
|
365
|
-
|
|
367
|
+
## Type Parameters
|
|
366
368
|
|
|
367
|
-
|
|
369
|
+
| Type Parameter |
|
|
370
|
+
| ------ |
|
|
371
|
+
| `T` *extends* `object` |
|
|
368
372
|
|
|
369
373
|
## Parameters
|
|
370
374
|
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
`T`
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
[`OmitByPredicate`](#../type-aliases/OmitByPredicate)
|
|
378
|
-
|
|
379
|
-
### maxDepth?
|
|
380
|
-
|
|
381
|
-
`number` = `1`
|
|
375
|
+
| Parameter | Type | Default value | Description |
|
|
376
|
+
| ------ | ------ | ------ | ------ |
|
|
377
|
+
| `obj` | `T` | `undefined` | The source object to omit properties from. |
|
|
378
|
+
| `predicate` | [`OmitByPredicate`](#../type-aliases/OmitByPredicate) | `undefined` | A function that returns true for properties to exclude. |
|
|
379
|
+
| `maxDepth` | `number` | `1` | Maximum recursion depth for nested objects. |
|
|
382
380
|
|
|
383
381
|
## Returns
|
|
384
382
|
|
|
385
383
|
`Partial`\<`T`\>
|
|
386
384
|
|
|
385
|
+
A partial copy of the object without matching properties.
|
|
386
|
+
|
|
387
387
|
### <a id="omitByPrefix"></a>omitByPrefix
|
|
388
388
|
|
|
389
389
|
[**@xylabs/object**](#../../README)
|
|
@@ -392,39 +392,34 @@ maxDepth?): Partial<T>;
|
|
|
392
392
|
|
|
393
393
|
```ts
|
|
394
394
|
function omitByPrefix<T, P>(
|
|
395
|
-
payload,
|
|
396
|
-
prefix,
|
|
397
|
-
maxDepth
|
|
395
|
+
payload: T,
|
|
396
|
+
prefix: P,
|
|
397
|
+
maxDepth?: number): DeepOmitStartsWith<T, P>;
|
|
398
398
|
```
|
|
399
399
|
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
### T
|
|
403
|
-
|
|
404
|
-
`T` *extends* `object`
|
|
400
|
+
Omits all properties whose keys start with the given prefix, recursively through nested objects.
|
|
405
401
|
|
|
406
|
-
|
|
402
|
+
## Type Parameters
|
|
407
403
|
|
|
408
|
-
|
|
404
|
+
| Type Parameter |
|
|
405
|
+
| ------ |
|
|
406
|
+
| `T` *extends* `object` |
|
|
407
|
+
| `P` *extends* `string` |
|
|
409
408
|
|
|
410
409
|
## Parameters
|
|
411
410
|
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
`T`
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
`P`
|
|
419
|
-
|
|
420
|
-
### maxDepth?
|
|
421
|
-
|
|
422
|
-
`number` = `100`
|
|
411
|
+
| Parameter | Type | Default value | Description |
|
|
412
|
+
| ------ | ------ | ------ | ------ |
|
|
413
|
+
| `payload` | `T` | `undefined` | The source object. |
|
|
414
|
+
| `prefix` | `P` | `undefined` | The string prefix to match keys against. |
|
|
415
|
+
| `maxDepth` | `number` | `100` | Maximum recursion depth. |
|
|
423
416
|
|
|
424
417
|
## Returns
|
|
425
418
|
|
|
426
419
|
[`DeepOmitStartsWith`](#../type-aliases/DeepOmitStartsWith)\<`T`, `P`\>
|
|
427
420
|
|
|
421
|
+
A new object without properties that have matching prefixed keys.
|
|
422
|
+
|
|
428
423
|
### <a id="pickBy"></a>pickBy
|
|
429
424
|
|
|
430
425
|
[**@xylabs/object**](#../../README)
|
|
@@ -433,35 +428,33 @@ maxDepth?): DeepOmitStartsWith<T, P>;
|
|
|
433
428
|
|
|
434
429
|
```ts
|
|
435
430
|
function pickBy<T>(
|
|
436
|
-
obj,
|
|
437
|
-
predicate,
|
|
438
|
-
maxDepth
|
|
431
|
+
obj: T,
|
|
432
|
+
predicate: PickByPredicate,
|
|
433
|
+
maxDepth?: number): Partial<T>;
|
|
439
434
|
```
|
|
440
435
|
|
|
441
|
-
|
|
436
|
+
Creates a new object containing only the properties that satisfy the predicate, with optional recursive depth.
|
|
442
437
|
|
|
443
|
-
|
|
438
|
+
## Type Parameters
|
|
444
439
|
|
|
445
|
-
|
|
440
|
+
| Type Parameter |
|
|
441
|
+
| ------ |
|
|
442
|
+
| `T` *extends* `object` |
|
|
446
443
|
|
|
447
444
|
## Parameters
|
|
448
445
|
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
`T`
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
[`PickByPredicate`](#../type-aliases/PickByPredicate)
|
|
456
|
-
|
|
457
|
-
### maxDepth?
|
|
458
|
-
|
|
459
|
-
`number` = `1`
|
|
446
|
+
| Parameter | Type | Default value | Description |
|
|
447
|
+
| ------ | ------ | ------ | ------ |
|
|
448
|
+
| `obj` | `T` | `undefined` | The source object to pick properties from. |
|
|
449
|
+
| `predicate` | [`PickByPredicate`](#../type-aliases/PickByPredicate) | `undefined` | A function that returns true for properties to include. |
|
|
450
|
+
| `maxDepth` | `number` | `1` | Maximum recursion depth for nested objects. |
|
|
460
451
|
|
|
461
452
|
## Returns
|
|
462
453
|
|
|
463
454
|
`Partial`\<`T`\>
|
|
464
455
|
|
|
456
|
+
A partial copy of the object with only matching properties.
|
|
457
|
+
|
|
465
458
|
### <a id="pickByPrefix"></a>pickByPrefix
|
|
466
459
|
|
|
467
460
|
[**@xylabs/object**](#../../README)
|
|
@@ -470,39 +463,34 @@ maxDepth?): Partial<T>;
|
|
|
470
463
|
|
|
471
464
|
```ts
|
|
472
465
|
function pickByPrefix<T, P>(
|
|
473
|
-
payload,
|
|
474
|
-
prefix,
|
|
475
|
-
maxDepth
|
|
466
|
+
payload: T,
|
|
467
|
+
prefix: P,
|
|
468
|
+
maxDepth?: number): DeepPickStartsWith<T, P>;
|
|
476
469
|
```
|
|
477
470
|
|
|
478
|
-
|
|
471
|
+
Picks all properties whose keys start with the given prefix, recursively through nested objects.
|
|
479
472
|
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
`T` *extends* `object`
|
|
483
|
-
|
|
484
|
-
### P
|
|
473
|
+
## Type Parameters
|
|
485
474
|
|
|
486
|
-
|
|
475
|
+
| Type Parameter |
|
|
476
|
+
| ------ |
|
|
477
|
+
| `T` *extends* `object` |
|
|
478
|
+
| `P` *extends* `string` |
|
|
487
479
|
|
|
488
480
|
## Parameters
|
|
489
481
|
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
`T`
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
`P`
|
|
497
|
-
|
|
498
|
-
### maxDepth?
|
|
499
|
-
|
|
500
|
-
`number` = `100`
|
|
482
|
+
| Parameter | Type | Default value | Description |
|
|
483
|
+
| ------ | ------ | ------ | ------ |
|
|
484
|
+
| `payload` | `T` | `undefined` | The source object. |
|
|
485
|
+
| `prefix` | `P` | `undefined` | The string prefix to match keys against. |
|
|
486
|
+
| `maxDepth` | `number` | `100` | Maximum recursion depth. |
|
|
501
487
|
|
|
502
488
|
## Returns
|
|
503
489
|
|
|
504
490
|
[`DeepPickStartsWith`](#../type-aliases/DeepPickStartsWith)\<`T`, `P`\>
|
|
505
491
|
|
|
492
|
+
A new object containing only properties with matching prefixed keys.
|
|
493
|
+
|
|
506
494
|
### <a id="removeFields"></a>removeFields
|
|
507
495
|
|
|
508
496
|
[**@xylabs/object**](#../../README)
|
|
@@ -510,33 +498,31 @@ maxDepth?): DeepPickStartsWith<T, P>;
|
|
|
510
498
|
***
|
|
511
499
|
|
|
512
500
|
```ts
|
|
513
|
-
function removeFields<T, K>(obj, fields): Omit<T, K>;
|
|
501
|
+
function removeFields<T, K>(obj: T, fields: K[]): Omit<T, K>;
|
|
514
502
|
```
|
|
515
503
|
|
|
516
|
-
|
|
504
|
+
Returns a shallow copy of the object with the specified fields removed.
|
|
517
505
|
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
`T` *extends* `object`
|
|
521
|
-
|
|
522
|
-
### K
|
|
506
|
+
## Type Parameters
|
|
523
507
|
|
|
524
|
-
|
|
508
|
+
| Type Parameter |
|
|
509
|
+
| ------ |
|
|
510
|
+
| `T` *extends* `object` |
|
|
511
|
+
| `K` *extends* `string` \| `number` \| `symbol` |
|
|
525
512
|
|
|
526
513
|
## Parameters
|
|
527
514
|
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
`T`
|
|
531
|
-
|
|
532
|
-
### fields
|
|
533
|
-
|
|
534
|
-
`K`[]
|
|
515
|
+
| Parameter | Type | Description |
|
|
516
|
+
| ------ | ------ | ------ |
|
|
517
|
+
| `obj` | `T` | The source object. |
|
|
518
|
+
| `fields` | `K`[] | An array of keys to remove. |
|
|
535
519
|
|
|
536
520
|
## Returns
|
|
537
521
|
|
|
538
522
|
`Omit`\<`T`, `K`\>
|
|
539
523
|
|
|
524
|
+
A new object without the specified fields.
|
|
525
|
+
|
|
540
526
|
### <a id="toSafeJson"></a>toSafeJson
|
|
541
527
|
|
|
542
528
|
[**@xylabs/object**](#../../README)
|
|
@@ -544,23 +530,24 @@ function removeFields<T, K>(obj, fields): Omit<T, K>;
|
|
|
544
530
|
***
|
|
545
531
|
|
|
546
532
|
```ts
|
|
547
|
-
function toSafeJson(value, maxDepth
|
|
533
|
+
function toSafeJson(value: unknown, maxDepth?: number): unknown;
|
|
548
534
|
```
|
|
549
535
|
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
### value
|
|
536
|
+
Converts a value to a JSON-safe representation, handling circular references and non-serializable types.
|
|
553
537
|
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
### maxDepth?
|
|
538
|
+
## Parameters
|
|
557
539
|
|
|
558
|
-
|
|
540
|
+
| Parameter | Type | Default value | Description |
|
|
541
|
+
| ------ | ------ | ------ | ------ |
|
|
542
|
+
| `value` | `unknown` | `undefined` | The value to convert. |
|
|
543
|
+
| `maxDepth` | `number` | `3` | Maximum recursion depth. |
|
|
559
544
|
|
|
560
545
|
## Returns
|
|
561
546
|
|
|
562
547
|
`unknown`
|
|
563
548
|
|
|
549
|
+
A JSON-safe value.
|
|
550
|
+
|
|
564
551
|
### <a id="toSafeJsonArray"></a>toSafeJsonArray
|
|
565
552
|
|
|
566
553
|
[**@xylabs/object**](#../../README)
|
|
@@ -569,29 +556,27 @@ function toSafeJson(value, maxDepth?): unknown;
|
|
|
569
556
|
|
|
570
557
|
```ts
|
|
571
558
|
function toSafeJsonArray(
|
|
572
|
-
value,
|
|
573
|
-
cycleList
|
|
574
|
-
maxDepth
|
|
559
|
+
value: unknown[],
|
|
560
|
+
cycleList?: unknown[],
|
|
561
|
+
maxDepth?: number): unknown[];
|
|
575
562
|
```
|
|
576
563
|
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
### value
|
|
580
|
-
|
|
581
|
-
`unknown`[]
|
|
582
|
-
|
|
583
|
-
### cycleList?
|
|
584
|
-
|
|
585
|
-
`unknown`[]
|
|
564
|
+
Converts an array to a JSON-safe array, handling circular references and depth limits.
|
|
586
565
|
|
|
587
|
-
|
|
566
|
+
## Parameters
|
|
588
567
|
|
|
589
|
-
|
|
568
|
+
| Parameter | Type | Default value | Description |
|
|
569
|
+
| ------ | ------ | ------ | ------ |
|
|
570
|
+
| `value` | `unknown`[] | `undefined` | The array to convert. |
|
|
571
|
+
| `cycleList?` | `unknown`[] | `undefined` | Tracks visited objects to detect circular references. |
|
|
572
|
+
| `maxDepth?` | `number` | `3` | Maximum recursion depth before truncating. |
|
|
590
573
|
|
|
591
574
|
## Returns
|
|
592
575
|
|
|
593
576
|
`unknown`[]
|
|
594
577
|
|
|
578
|
+
A JSON-safe array representation.
|
|
579
|
+
|
|
595
580
|
### <a id="toSafeJsonObject"></a>toSafeJsonObject
|
|
596
581
|
|
|
597
582
|
[**@xylabs/object**](#../../README)
|
|
@@ -600,29 +585,27 @@ function toSafeJsonArray(
|
|
|
600
585
|
|
|
601
586
|
```ts
|
|
602
587
|
function toSafeJsonObject(
|
|
603
|
-
value,
|
|
604
|
-
cycleList
|
|
605
|
-
maxDepth
|
|
588
|
+
value: object,
|
|
589
|
+
cycleList?: unknown[],
|
|
590
|
+
maxDepth?: number): JsonObject;
|
|
606
591
|
```
|
|
607
592
|
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
### value
|
|
611
|
-
|
|
612
|
-
`object`
|
|
593
|
+
Converts an object to a JSON-safe object, handling circular references and depth limits.
|
|
613
594
|
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
`unknown`[]
|
|
617
|
-
|
|
618
|
-
### maxDepth?
|
|
595
|
+
## Parameters
|
|
619
596
|
|
|
620
|
-
|
|
597
|
+
| Parameter | Type | Default value | Description |
|
|
598
|
+
| ------ | ------ | ------ | ------ |
|
|
599
|
+
| `value` | `object` | `undefined` | The object to convert. |
|
|
600
|
+
| `cycleList?` | `unknown`[] | `undefined` | Tracks visited objects to detect circular references. |
|
|
601
|
+
| `maxDepth?` | `number` | `3` | Maximum recursion depth before truncating. |
|
|
621
602
|
|
|
622
603
|
## Returns
|
|
623
604
|
|
|
624
605
|
[`JsonObject`](#../type-aliases/JsonObject)
|
|
625
606
|
|
|
607
|
+
A JSON-safe object representation.
|
|
608
|
+
|
|
626
609
|
### <a id="toSafeJsonString"></a>toSafeJsonString
|
|
627
610
|
|
|
628
611
|
[**@xylabs/object**](#../../README)
|
|
@@ -630,23 +613,24 @@ function toSafeJsonObject(
|
|
|
630
613
|
***
|
|
631
614
|
|
|
632
615
|
```ts
|
|
633
|
-
function toSafeJsonString(value, maxDepth
|
|
616
|
+
function toSafeJsonString(value: unknown, maxDepth?: number): string;
|
|
634
617
|
```
|
|
635
618
|
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
### value
|
|
639
|
-
|
|
640
|
-
`unknown`
|
|
619
|
+
Converts a value to a pretty-printed JSON string, safely handling circular references and non-JSON types.
|
|
641
620
|
|
|
642
|
-
|
|
621
|
+
## Parameters
|
|
643
622
|
|
|
644
|
-
|
|
623
|
+
| Parameter | Type | Default value | Description |
|
|
624
|
+
| ------ | ------ | ------ | ------ |
|
|
625
|
+
| `value` | `unknown` | `undefined` | The value to serialize. |
|
|
626
|
+
| `maxDepth` | `number` | `3` | Maximum recursion depth. |
|
|
645
627
|
|
|
646
628
|
## Returns
|
|
647
629
|
|
|
648
630
|
`string`
|
|
649
631
|
|
|
632
|
+
A formatted JSON string.
|
|
633
|
+
|
|
650
634
|
### <a id="toSafeJsonValue"></a>toSafeJsonValue
|
|
651
635
|
|
|
652
636
|
[**@xylabs/object**](#../../README)
|
|
@@ -655,29 +639,28 @@ function toSafeJsonString(value, maxDepth?): string;
|
|
|
655
639
|
|
|
656
640
|
```ts
|
|
657
641
|
function toSafeJsonValue(
|
|
658
|
-
value,
|
|
659
|
-
cycleList
|
|
660
|
-
maxDepth
|
|
642
|
+
value: unknown,
|
|
643
|
+
cycleList?: unknown[],
|
|
644
|
+
maxDepth?: number): unknown;
|
|
661
645
|
```
|
|
662
646
|
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
### value
|
|
647
|
+
Converts an unknown value to a JSON-safe value, replacing circular references with '[Circular]' and
|
|
648
|
+
non-JSON types with descriptive placeholder strings.
|
|
666
649
|
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
### cycleList?
|
|
670
|
-
|
|
671
|
-
`unknown`[]
|
|
672
|
-
|
|
673
|
-
### maxDepth?
|
|
650
|
+
## Parameters
|
|
674
651
|
|
|
675
|
-
|
|
652
|
+
| Parameter | Type | Default value | Description |
|
|
653
|
+
| ------ | ------ | ------ | ------ |
|
|
654
|
+
| `value` | `unknown` | `undefined` | The value to convert. |
|
|
655
|
+
| `cycleList?` | `unknown`[] | `undefined` | Tracks visited objects to detect circular references. |
|
|
656
|
+
| `maxDepth?` | `number` | `3` | Maximum recursion depth before truncating with '[MaxDepth]'. |
|
|
676
657
|
|
|
677
658
|
## Returns
|
|
678
659
|
|
|
679
660
|
`unknown`
|
|
680
661
|
|
|
662
|
+
A JSON-safe representation of the value.
|
|
663
|
+
|
|
681
664
|
### interfaces
|
|
682
665
|
|
|
683
666
|
### <a id="ObjectTypeConfig"></a>ObjectTypeConfig
|
|
@@ -686,21 +669,17 @@ function toSafeJsonValue(
|
|
|
686
669
|
|
|
687
670
|
***
|
|
688
671
|
|
|
672
|
+
Configuration options for object type checking.
|
|
673
|
+
|
|
689
674
|
## Extends
|
|
690
675
|
|
|
691
676
|
- [`TypeCheckConfig`](#TypeCheckConfig)
|
|
692
677
|
|
|
693
678
|
## Properties
|
|
694
679
|
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
optional log: boolean | Logger;
|
|
699
|
-
```
|
|
700
|
-
|
|
701
|
-
### Inherited from
|
|
702
|
-
|
|
703
|
-
[`TypeCheckConfig`](#TypeCheckConfig).[`log`](TypeCheckConfig.md#log)
|
|
680
|
+
| Property | Type | Inherited from |
|
|
681
|
+
| ------ | ------ | ------ |
|
|
682
|
+
| <a id="log"></a> `log?` | `boolean` \| `Logger` | [`TypeCheckConfig`](#TypeCheckConfig).[`log`](TypeCheckConfig.md#log) |
|
|
704
683
|
|
|
705
684
|
### <a id="TypeCheckConfig"></a>TypeCheckConfig
|
|
706
685
|
|
|
@@ -708,6 +687,8 @@ optional log: boolean | Logger;
|
|
|
708
687
|
|
|
709
688
|
***
|
|
710
689
|
|
|
690
|
+
Configuration options for type check functions, with optional logging.
|
|
691
|
+
|
|
711
692
|
## Extended by
|
|
712
693
|
|
|
713
694
|
- [`ObjectTypeConfig`](#ObjectTypeConfig)
|
|
@@ -716,11 +697,9 @@ optional log: boolean | Logger;
|
|
|
716
697
|
|
|
717
698
|
## Properties
|
|
718
699
|
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
optional log: boolean | Logger;
|
|
723
|
-
```
|
|
700
|
+
| Property | Type |
|
|
701
|
+
| ------ | ------ |
|
|
702
|
+
| <a id="log"></a> `log?` | `boolean` \| `Logger` |
|
|
724
703
|
|
|
725
704
|
### <a id="TypeCheckOptionalConfig"></a>TypeCheckOptionalConfig
|
|
726
705
|
|
|
@@ -728,29 +707,18 @@ optional log: boolean | Logger;
|
|
|
728
707
|
|
|
729
708
|
***
|
|
730
709
|
|
|
710
|
+
Type check configuration that marks the value as optional, returning undefined on failure.
|
|
711
|
+
|
|
731
712
|
## Extends
|
|
732
713
|
|
|
733
714
|
- [`TypeCheckConfig`](#TypeCheckConfig)
|
|
734
715
|
|
|
735
716
|
## Properties
|
|
736
717
|
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
```
|
|
742
|
-
|
|
743
|
-
### Inherited from
|
|
744
|
-
|
|
745
|
-
[`TypeCheckConfig`](#TypeCheckConfig).[`log`](TypeCheckConfig.md#log)
|
|
746
|
-
|
|
747
|
-
***
|
|
748
|
-
|
|
749
|
-
### required
|
|
750
|
-
|
|
751
|
-
```ts
|
|
752
|
-
required: false;
|
|
753
|
-
```
|
|
718
|
+
| Property | Type | Inherited from |
|
|
719
|
+
| ------ | ------ | ------ |
|
|
720
|
+
| <a id="log"></a> `log?` | `boolean` \| `Logger` | [`TypeCheckConfig`](#TypeCheckConfig).[`log`](TypeCheckConfig.md#log) |
|
|
721
|
+
| <a id="required"></a> `required` | `false` | - |
|
|
754
722
|
|
|
755
723
|
### <a id="TypeCheckRequiredConfig"></a>TypeCheckRequiredConfig
|
|
756
724
|
|
|
@@ -758,29 +726,18 @@ required: false;
|
|
|
758
726
|
|
|
759
727
|
***
|
|
760
728
|
|
|
729
|
+
Type check configuration that marks the value as required, causing assertions on failure.
|
|
730
|
+
|
|
761
731
|
## Extends
|
|
762
732
|
|
|
763
733
|
- [`TypeCheckConfig`](#TypeCheckConfig)
|
|
764
734
|
|
|
765
735
|
## Properties
|
|
766
736
|
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
```
|
|
772
|
-
|
|
773
|
-
### Inherited from
|
|
774
|
-
|
|
775
|
-
[`TypeCheckConfig`](#TypeCheckConfig).[`log`](TypeCheckConfig.md#log)
|
|
776
|
-
|
|
777
|
-
***
|
|
778
|
-
|
|
779
|
-
### required
|
|
780
|
-
|
|
781
|
-
```ts
|
|
782
|
-
required: true;
|
|
783
|
-
```
|
|
737
|
+
| Property | Type | Inherited from |
|
|
738
|
+
| ------ | ------ | ------ |
|
|
739
|
+
| <a id="log"></a> `log?` | `boolean` \| `Logger` | [`TypeCheckConfig`](#TypeCheckConfig).[`log`](TypeCheckConfig.md#log) |
|
|
740
|
+
| <a id="required"></a> `required` | `true` | - |
|
|
784
741
|
|
|
785
742
|
### <a id="Validator"></a>Validator
|
|
786
743
|
|
|
@@ -788,25 +745,27 @@ required: true;
|
|
|
788
745
|
|
|
789
746
|
***
|
|
790
747
|
|
|
791
|
-
|
|
748
|
+
Interface for validating objects and returning any errors found.
|
|
792
749
|
|
|
793
|
-
|
|
750
|
+
## Type Parameters
|
|
794
751
|
|
|
795
|
-
|
|
752
|
+
| Type Parameter | Default type |
|
|
753
|
+
| ------ | ------ |
|
|
754
|
+
| `T` *extends* [`EmptyObject`](#../type-aliases/EmptyObject) | [`AnyObject`](#../type-aliases/AnyObject) |
|
|
796
755
|
|
|
797
756
|
## Methods
|
|
798
757
|
|
|
799
758
|
### validate()
|
|
800
759
|
|
|
801
760
|
```ts
|
|
802
|
-
validate(payload): Promisable<Error[]>;
|
|
761
|
+
validate(payload: T): Promisable<Error[]>;
|
|
803
762
|
```
|
|
804
763
|
|
|
805
764
|
### Parameters
|
|
806
765
|
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
`T`
|
|
766
|
+
| Parameter | Type |
|
|
767
|
+
| ------ | ------ |
|
|
768
|
+
| `payload` | `T` |
|
|
810
769
|
|
|
811
770
|
### Returns
|
|
812
771
|
|
|
@@ -834,26 +793,28 @@ will result in a type that includes the universal set of field names
|
|
|
834
793
|
***
|
|
835
794
|
|
|
836
795
|
```ts
|
|
837
|
-
type AsOptionalTypeFunction<T> = <TType>(value) => TType | undefined;
|
|
796
|
+
type AsOptionalTypeFunction<T> = <TType>(value: AnyNonPromise) => TType | undefined;
|
|
838
797
|
```
|
|
839
798
|
|
|
840
|
-
|
|
799
|
+
A simplified type-narrowing function that returns T or undefined, without assertion support.
|
|
841
800
|
|
|
842
|
-
|
|
801
|
+
## Type Parameters
|
|
843
802
|
|
|
844
|
-
|
|
803
|
+
| Type Parameter | Default type |
|
|
804
|
+
| ------ | ------ |
|
|
805
|
+
| `T` *extends* `AnyNonPromise` | `AnyNonPromise` |
|
|
845
806
|
|
|
846
807
|
## Type Parameters
|
|
847
808
|
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
`TType` *extends* `AnyNonPromise`
|
|
809
|
+
| Type Parameter |
|
|
810
|
+
| ------ |
|
|
811
|
+
| `TType` *extends* `AnyNonPromise` |
|
|
851
812
|
|
|
852
813
|
## Parameters
|
|
853
814
|
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
`AnyNonPromise`
|
|
815
|
+
| Parameter | Type |
|
|
816
|
+
| ------ | ------ |
|
|
817
|
+
| `value` | `AnyNonPromise` |
|
|
857
818
|
|
|
858
819
|
## Returns
|
|
859
820
|
|
|
@@ -867,38 +828,44 @@ type AsOptionalTypeFunction<T> = <TType>(value) => TType | undefined;
|
|
|
867
828
|
|
|
868
829
|
```ts
|
|
869
830
|
type AsTypeFunction<T> = {
|
|
870
|
-
<TType> (value): TType | undefined;
|
|
871
|
-
<TType> (value, config): TType;
|
|
872
|
-
<TType> (value, config
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
<TType> (value, assert
|
|
831
|
+
<TType> (value: AnyNonPromise): TType | undefined;
|
|
832
|
+
<TType> (value: AnyNonPromise, config: TypeCheckRequiredConfig): TType;
|
|
833
|
+
<TType> (value: AnyNonPromise, config:
|
|
834
|
+
| TypeCheckConfig
|
|
835
|
+
| TypeCheckOptionalConfig): TType | undefined;
|
|
836
|
+
<TType> (value: AnyNonPromise, assert: StringOrAlertFunction<TType>): TType | undefined;
|
|
837
|
+
<TType> (value: AnyNonPromise, assert: StringOrAlertFunction<TType>, config: TypeCheckRequiredConfig): TType;
|
|
838
|
+
<TType> (value: AnyNonPromise, assert: StringOrAlertFunction<TType>, config:
|
|
839
|
+
| TypeCheckConfig
|
|
840
|
+
| TypeCheckOptionalConfig): TType | undefined;
|
|
876
841
|
};
|
|
877
842
|
```
|
|
878
843
|
|
|
879
|
-
|
|
844
|
+
A type-narrowing function that attempts to cast a value to T, with optional assertion and configuration overloads.
|
|
880
845
|
|
|
881
|
-
|
|
846
|
+
## Type Parameters
|
|
882
847
|
|
|
883
|
-
|
|
848
|
+
| Type Parameter | Default type |
|
|
849
|
+
| ------ | ------ |
|
|
850
|
+
| `T` *extends* `AnyNonPromise` | `AnyNonPromise` |
|
|
884
851
|
|
|
885
852
|
## Call Signature
|
|
886
853
|
|
|
887
854
|
```ts
|
|
888
|
-
<TType>(value): TType | undefined;
|
|
855
|
+
<TType>(value: AnyNonPromise): TType | undefined;
|
|
889
856
|
```
|
|
890
857
|
|
|
891
858
|
### Type Parameters
|
|
892
859
|
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
`TType` *extends* `AnyNonPromise`
|
|
860
|
+
| Type Parameter |
|
|
861
|
+
| ------ |
|
|
862
|
+
| `TType` *extends* `AnyNonPromise` |
|
|
896
863
|
|
|
897
864
|
### Parameters
|
|
898
865
|
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
`AnyNonPromise`
|
|
866
|
+
| Parameter | Type |
|
|
867
|
+
| ------ | ------ |
|
|
868
|
+
| `value` | `AnyNonPromise` |
|
|
902
869
|
|
|
903
870
|
### Returns
|
|
904
871
|
|
|
@@ -907,24 +874,21 @@ type AsTypeFunction<T> = {
|
|
|
907
874
|
## Call Signature
|
|
908
875
|
|
|
909
876
|
```ts
|
|
910
|
-
<TType>(value, config): TType;
|
|
877
|
+
<TType>(value: AnyNonPromise, config: TypeCheckRequiredConfig): TType;
|
|
911
878
|
```
|
|
912
879
|
|
|
913
880
|
### Type Parameters
|
|
914
881
|
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
`TType` *extends* `AnyNonPromise`
|
|
882
|
+
| Type Parameter |
|
|
883
|
+
| ------ |
|
|
884
|
+
| `TType` *extends* `AnyNonPromise` |
|
|
918
885
|
|
|
919
886
|
### Parameters
|
|
920
887
|
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
`AnyNonPromise`
|
|
924
|
-
|
|
925
|
-
### config
|
|
926
|
-
|
|
927
|
-
[`TypeCheckRequiredConfig`](#../interfaces/TypeCheckRequiredConfig)
|
|
888
|
+
| Parameter | Type |
|
|
889
|
+
| ------ | ------ |
|
|
890
|
+
| `value` | `AnyNonPromise` |
|
|
891
|
+
| `config` | [`TypeCheckRequiredConfig`](#../interfaces/TypeCheckRequiredConfig) |
|
|
928
892
|
|
|
929
893
|
### Returns
|
|
930
894
|
|
|
@@ -933,24 +897,23 @@ type AsTypeFunction<T> = {
|
|
|
933
897
|
## Call Signature
|
|
934
898
|
|
|
935
899
|
```ts
|
|
936
|
-
<TType>(value, config
|
|
900
|
+
<TType>(value: AnyNonPromise, config:
|
|
901
|
+
| TypeCheckConfig
|
|
902
|
+
| TypeCheckOptionalConfig): TType | undefined;
|
|
937
903
|
```
|
|
938
904
|
|
|
939
905
|
### Type Parameters
|
|
940
906
|
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
`TType` *extends* `AnyNonPromise`
|
|
907
|
+
| Type Parameter |
|
|
908
|
+
| ------ |
|
|
909
|
+
| `TType` *extends* `AnyNonPromise` |
|
|
944
910
|
|
|
945
911
|
### Parameters
|
|
946
912
|
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
`AnyNonPromise`
|
|
950
|
-
|
|
951
|
-
### config
|
|
952
|
-
|
|
953
|
-
[`TypeCheckConfig`](#../interfaces/TypeCheckConfig) | [`TypeCheckOptionalConfig`](#../interfaces/TypeCheckOptionalConfig)
|
|
913
|
+
| Parameter | Type |
|
|
914
|
+
| ------ | ------ |
|
|
915
|
+
| `value` | `AnyNonPromise` |
|
|
916
|
+
| `config` | \| [`TypeCheckConfig`](#../interfaces/TypeCheckConfig) \| [`TypeCheckOptionalConfig`](#../interfaces/TypeCheckOptionalConfig) |
|
|
954
917
|
|
|
955
918
|
### Returns
|
|
956
919
|
|
|
@@ -959,24 +922,21 @@ type AsTypeFunction<T> = {
|
|
|
959
922
|
## Call Signature
|
|
960
923
|
|
|
961
924
|
```ts
|
|
962
|
-
<TType>(value, assert): TType | undefined;
|
|
925
|
+
<TType>(value: AnyNonPromise, assert: StringOrAlertFunction<TType>): TType | undefined;
|
|
963
926
|
```
|
|
964
927
|
|
|
965
928
|
### Type Parameters
|
|
966
929
|
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
`TType` *extends* `AnyNonPromise`
|
|
930
|
+
| Type Parameter |
|
|
931
|
+
| ------ |
|
|
932
|
+
| `TType` *extends* `AnyNonPromise` |
|
|
970
933
|
|
|
971
934
|
### Parameters
|
|
972
935
|
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
`AnyNonPromise`
|
|
976
|
-
|
|
977
|
-
### assert
|
|
978
|
-
|
|
979
|
-
[`StringOrAlertFunction`](#StringOrAlertFunction)\<`TType`\>
|
|
936
|
+
| Parameter | Type |
|
|
937
|
+
| ------ | ------ |
|
|
938
|
+
| `value` | `AnyNonPromise` |
|
|
939
|
+
| `assert` | [`StringOrAlertFunction`](#StringOrAlertFunction)\<`TType`\> |
|
|
980
940
|
|
|
981
941
|
### Returns
|
|
982
942
|
|
|
@@ -986,30 +946,24 @@ type AsTypeFunction<T> = {
|
|
|
986
946
|
|
|
987
947
|
```ts
|
|
988
948
|
<TType>(
|
|
989
|
-
value,
|
|
990
|
-
assert
|
|
991
|
-
config): TType;
|
|
949
|
+
value: AnyNonPromise,
|
|
950
|
+
assert: StringOrAlertFunction<TType>,
|
|
951
|
+
config: TypeCheckRequiredConfig): TType;
|
|
992
952
|
```
|
|
993
953
|
|
|
994
954
|
### Type Parameters
|
|
995
955
|
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
`TType` *extends* `AnyNonPromise`
|
|
956
|
+
| Type Parameter |
|
|
957
|
+
| ------ |
|
|
958
|
+
| `TType` *extends* `AnyNonPromise` |
|
|
999
959
|
|
|
1000
960
|
### Parameters
|
|
1001
961
|
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
`AnyNonPromise`
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
[`StringOrAlertFunction`](#StringOrAlertFunction)\<`TType`\>
|
|
1009
|
-
|
|
1010
|
-
### config
|
|
1011
|
-
|
|
1012
|
-
[`TypeCheckRequiredConfig`](#../interfaces/TypeCheckRequiredConfig)
|
|
962
|
+
| Parameter | Type |
|
|
963
|
+
| ------ | ------ |
|
|
964
|
+
| `value` | `AnyNonPromise` |
|
|
965
|
+
| `assert` | [`StringOrAlertFunction`](#StringOrAlertFunction)\<`TType`\> |
|
|
966
|
+
| `config` | [`TypeCheckRequiredConfig`](#../interfaces/TypeCheckRequiredConfig) |
|
|
1013
967
|
|
|
1014
968
|
### Returns
|
|
1015
969
|
|
|
@@ -1019,30 +973,26 @@ type AsTypeFunction<T> = {
|
|
|
1019
973
|
|
|
1020
974
|
```ts
|
|
1021
975
|
<TType>(
|
|
1022
|
-
value,
|
|
1023
|
-
assert
|
|
1024
|
-
config
|
|
976
|
+
value: AnyNonPromise,
|
|
977
|
+
assert: StringOrAlertFunction<TType>,
|
|
978
|
+
config:
|
|
979
|
+
| TypeCheckConfig
|
|
980
|
+
| TypeCheckOptionalConfig): TType | undefined;
|
|
1025
981
|
```
|
|
1026
982
|
|
|
1027
983
|
### Type Parameters
|
|
1028
984
|
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
`TType` *extends* `AnyNonPromise`
|
|
985
|
+
| Type Parameter |
|
|
986
|
+
| ------ |
|
|
987
|
+
| `TType` *extends* `AnyNonPromise` |
|
|
1032
988
|
|
|
1033
989
|
### Parameters
|
|
1034
990
|
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
`AnyNonPromise`
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
[`StringOrAlertFunction`](#StringOrAlertFunction)\<`TType`\>
|
|
1042
|
-
|
|
1043
|
-
### config
|
|
1044
|
-
|
|
1045
|
-
[`TypeCheckConfig`](#../interfaces/TypeCheckConfig) | [`TypeCheckOptionalConfig`](#../interfaces/TypeCheckOptionalConfig)
|
|
991
|
+
| Parameter | Type |
|
|
992
|
+
| ------ | ------ |
|
|
993
|
+
| `value` | `AnyNonPromise` |
|
|
994
|
+
| `assert` | [`StringOrAlertFunction`](#StringOrAlertFunction)\<`TType`\> |
|
|
995
|
+
| `config` | \| [`TypeCheckConfig`](#../interfaces/TypeCheckConfig) \| [`TypeCheckOptionalConfig`](#../interfaces/TypeCheckOptionalConfig) |
|
|
1046
996
|
|
|
1047
997
|
### Returns
|
|
1048
998
|
|
|
@@ -1055,24 +1005,23 @@ type AsTypeFunction<T> = {
|
|
|
1055
1005
|
***
|
|
1056
1006
|
|
|
1057
1007
|
```ts
|
|
1058
|
-
type Compare<T> = (a, b) => number;
|
|
1008
|
+
type Compare<T> = (a: T, b: T) => number;
|
|
1059
1009
|
```
|
|
1060
1010
|
|
|
1011
|
+
A comparator function that returns a negative number if a < b, zero if a == b, and a positive number if a > b.
|
|
1012
|
+
|
|
1061
1013
|
## Type Parameters
|
|
1062
1014
|
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
`T`
|
|
1015
|
+
| Type Parameter |
|
|
1016
|
+
| ------ |
|
|
1017
|
+
| `T` |
|
|
1066
1018
|
|
|
1067
1019
|
## Parameters
|
|
1068
1020
|
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
`T`
|
|
1072
|
-
|
|
1073
|
-
### b
|
|
1074
|
-
|
|
1075
|
-
`T`
|
|
1021
|
+
| Parameter | Type |
|
|
1022
|
+
| ------ | ------ |
|
|
1023
|
+
| `a` | `T` |
|
|
1024
|
+
| `b` | `T` |
|
|
1076
1025
|
|
|
1077
1026
|
## Returns
|
|
1078
1027
|
|
|
@@ -1088,15 +1037,14 @@ type Compare<T> = (a, b) => number;
|
|
|
1088
1037
|
type DeepOmitStartsWith<T, Prefix> = T extends infer U[] ? DeepOmitStartsWith<U, Prefix>[] : T extends object ? { [K in keyof T as K extends string ? K extends `${Prefix}${string}` ? never : K : K]: DeepOmitStartsWith<T[K], Prefix> } : T;
|
|
1089
1038
|
```
|
|
1090
1039
|
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
### T
|
|
1094
|
-
|
|
1095
|
-
`T`
|
|
1040
|
+
Recursively omits keys that start with the given prefix, including in nested objects and arrays.
|
|
1096
1041
|
|
|
1097
|
-
|
|
1042
|
+
## Type Parameters
|
|
1098
1043
|
|
|
1099
|
-
|
|
1044
|
+
| Type Parameter |
|
|
1045
|
+
| ------ |
|
|
1046
|
+
| `T` |
|
|
1047
|
+
| `Prefix` *extends* `string` |
|
|
1100
1048
|
|
|
1101
1049
|
### <a id="DeepPickStartsWith"></a>DeepPickStartsWith
|
|
1102
1050
|
|
|
@@ -1108,15 +1056,14 @@ type DeepOmitStartsWith<T, Prefix> = T extends infer U[] ? DeepOmitStartsWith<U,
|
|
|
1108
1056
|
type DeepPickStartsWith<T, Prefix> = T extends infer U[] ? DeepPickStartsWith<U, Prefix>[] : T extends object ? { [K in keyof T as K extends string ? K extends `${Prefix}${string}` ? K : never : K]: DeepPickStartsWith<T[K], Prefix> } : T;
|
|
1109
1057
|
```
|
|
1110
1058
|
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
### T
|
|
1059
|
+
Recursively picks only the keys that start with the given prefix, including in nested objects and arrays.
|
|
1114
1060
|
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
### Prefix
|
|
1061
|
+
## Type Parameters
|
|
1118
1062
|
|
|
1119
|
-
|
|
1063
|
+
| Type Parameter |
|
|
1064
|
+
| ------ |
|
|
1065
|
+
| `T` |
|
|
1066
|
+
| `Prefix` *extends* `string` |
|
|
1120
1067
|
|
|
1121
1068
|
### <a id="DeepRestrictToJson"></a>DeepRestrictToJson
|
|
1122
1069
|
|
|
@@ -1128,11 +1075,13 @@ type DeepPickStartsWith<T, Prefix> = T extends infer U[] ? DeepPickStartsWith<U,
|
|
|
1128
1075
|
type DeepRestrictToJson<T> = { [K in keyof T as K extends string ? K : never]: T[K] extends (infer U)[] ? DeepRestrictToJson<U>[] : T[K] extends object ? DeepRestrictToJson<T[K]> : T[K] extends JsonValue ? T[K] : never };
|
|
1129
1076
|
```
|
|
1130
1077
|
|
|
1131
|
-
|
|
1078
|
+
Recursively restricts an object type to only JSON-compatible values, excluding non-serializable types.
|
|
1132
1079
|
|
|
1133
|
-
|
|
1080
|
+
## Type Parameters
|
|
1134
1081
|
|
|
1135
|
-
|
|
1082
|
+
| Type Parameter |
|
|
1083
|
+
| ------ |
|
|
1084
|
+
| `T` |
|
|
1136
1085
|
|
|
1137
1086
|
### <a id="DeepRestrictToStringKeys"></a>DeepRestrictToStringKeys
|
|
1138
1087
|
|
|
@@ -1144,11 +1093,13 @@ type DeepRestrictToJson<T> = { [K in keyof T as K extends string ? K : never]: T
|
|
|
1144
1093
|
type DeepRestrictToStringKeys<T> = { [K in keyof T as K extends string ? K : never]: T[K] extends (infer U)[] ? DeepRestrictToStringKeys<U>[] : T[K] extends object ? DeepRestrictToStringKeys<T[K]> : T[K] };
|
|
1145
1094
|
```
|
|
1146
1095
|
|
|
1096
|
+
Recursively removes all non-string keys from an object type, including in nested objects and arrays.
|
|
1097
|
+
|
|
1147
1098
|
## Type Parameters
|
|
1148
1099
|
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
`T`
|
|
1100
|
+
| Type Parameter |
|
|
1101
|
+
| ------ |
|
|
1102
|
+
| `T` |
|
|
1152
1103
|
|
|
1153
1104
|
### <a id="EmptyObject"></a>EmptyObject
|
|
1154
1105
|
|
|
@@ -1157,7 +1108,7 @@ type DeepRestrictToStringKeys<T> = { [K in keyof T as K extends string ? K : nev
|
|
|
1157
1108
|
***
|
|
1158
1109
|
|
|
1159
1110
|
```ts
|
|
1160
|
-
type EmptyObject<T> = Exclude<{ [K in keyof T]?: never }, unknown[] | (...args) => unknown | null>;
|
|
1111
|
+
type EmptyObject<T> = Exclude<{ [K in keyof T]?: never }, unknown[] | (...args: unknown[]) => unknown | null>;
|
|
1161
1112
|
```
|
|
1162
1113
|
|
|
1163
1114
|
An empty object, which means that it does enforce the set of field names, defaulting to an empty set until
|
|
@@ -1165,9 +1116,9 @@ extended from, which then adds only those additional fields
|
|
|
1165
1116
|
|
|
1166
1117
|
## Type Parameters
|
|
1167
1118
|
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
`T` *extends* `object`
|
|
1119
|
+
| Type Parameter | Default type |
|
|
1120
|
+
| ------ | ------ |
|
|
1121
|
+
| `T` *extends* `object` | `object` |
|
|
1171
1122
|
|
|
1172
1123
|
### <a id="JsonArray"></a>JsonArray
|
|
1173
1124
|
|
|
@@ -1179,6 +1130,8 @@ extended from, which then adds only those additional fields
|
|
|
1179
1130
|
type JsonArray = z.infer<typeof JsonArrayZod>;
|
|
1180
1131
|
```
|
|
1181
1132
|
|
|
1133
|
+
A JSON array containing JSON values.
|
|
1134
|
+
|
|
1182
1135
|
### <a id="JsonObject"></a>JsonObject
|
|
1183
1136
|
|
|
1184
1137
|
[**@xylabs/object**](#../../README)
|
|
@@ -1189,6 +1142,8 @@ type JsonArray = z.infer<typeof JsonArrayZod>;
|
|
|
1189
1142
|
type JsonObject = z.infer<typeof JsonObjectZod>;
|
|
1190
1143
|
```
|
|
1191
1144
|
|
|
1145
|
+
A JSON object with string keys and JSON values.
|
|
1146
|
+
|
|
1192
1147
|
### <a id="JsonValue"></a>JsonValue
|
|
1193
1148
|
|
|
1194
1149
|
[**@xylabs/object**](#../../README)
|
|
@@ -1199,6 +1154,8 @@ type JsonObject = z.infer<typeof JsonObjectZod>;
|
|
|
1199
1154
|
type JsonValue = z.infer<typeof JsonValueZod>;
|
|
1200
1155
|
```
|
|
1201
1156
|
|
|
1157
|
+
A recursive JSON value: string, number, boolean, null, array, or object.
|
|
1158
|
+
|
|
1202
1159
|
### <a id="OmitByPredicate"></a>OmitByPredicate
|
|
1203
1160
|
|
|
1204
1161
|
[**@xylabs/object**](#../../README)
|
|
@@ -1206,24 +1163,23 @@ type JsonValue = z.infer<typeof JsonValueZod>;
|
|
|
1206
1163
|
***
|
|
1207
1164
|
|
|
1208
1165
|
```ts
|
|
1209
|
-
type OmitByPredicate<T> = (value, key) => boolean;
|
|
1166
|
+
type OmitByPredicate<T> = (value: T[keyof T], key: keyof T) => boolean;
|
|
1210
1167
|
```
|
|
1211
1168
|
|
|
1212
|
-
|
|
1169
|
+
A predicate function used to determine which properties to omit from an object.
|
|
1213
1170
|
|
|
1214
|
-
|
|
1171
|
+
## Type Parameters
|
|
1215
1172
|
|
|
1216
|
-
|
|
1173
|
+
| Type Parameter | Default type |
|
|
1174
|
+
| ------ | ------ |
|
|
1175
|
+
| `T` *extends* [`EmptyObject`](#EmptyObject) | `Record`\<`string`, `unknown`\> |
|
|
1217
1176
|
|
|
1218
1177
|
## Parameters
|
|
1219
1178
|
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
`T`\[keyof `T`\]
|
|
1223
|
-
|
|
1224
|
-
### key
|
|
1225
|
-
|
|
1226
|
-
keyof `T`
|
|
1179
|
+
| Parameter | Type |
|
|
1180
|
+
| ------ | ------ |
|
|
1181
|
+
| `value` | `T`\[keyof `T`\] |
|
|
1182
|
+
| `key` | keyof `T` |
|
|
1227
1183
|
|
|
1228
1184
|
## Returns
|
|
1229
1185
|
|
|
@@ -1239,15 +1195,14 @@ keyof `T`
|
|
|
1239
1195
|
type OmitStartsWith<T, Prefix> = { [K in keyof T as K extends `${Prefix}${string}` ? never : K]: T[K] };
|
|
1240
1196
|
```
|
|
1241
1197
|
|
|
1242
|
-
|
|
1198
|
+
Omits the keys of T that start with the given prefix.
|
|
1243
1199
|
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
`T`
|
|
1247
|
-
|
|
1248
|
-
### Prefix
|
|
1200
|
+
## Type Parameters
|
|
1249
1201
|
|
|
1250
|
-
|
|
1202
|
+
| Type Parameter |
|
|
1203
|
+
| ------ |
|
|
1204
|
+
| `T` |
|
|
1205
|
+
| `Prefix` *extends* `string` |
|
|
1251
1206
|
|
|
1252
1207
|
### <a id="Optional"></a>Optional
|
|
1253
1208
|
|
|
@@ -1259,15 +1214,14 @@ type OmitStartsWith<T, Prefix> = { [K in keyof T as K extends `${Prefix}${string
|
|
|
1259
1214
|
type Optional<T, F> = Omit<T, F> & Partial<Pick<T, F>>;
|
|
1260
1215
|
```
|
|
1261
1216
|
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
### T
|
|
1265
|
-
|
|
1266
|
-
`T` *extends* `object`
|
|
1217
|
+
Makes the specified fields of T optional while keeping the rest required.
|
|
1267
1218
|
|
|
1268
|
-
|
|
1219
|
+
## Type Parameters
|
|
1269
1220
|
|
|
1270
|
-
|
|
1221
|
+
| Type Parameter |
|
|
1222
|
+
| ------ |
|
|
1223
|
+
| `T` *extends* `object` |
|
|
1224
|
+
| `F` *extends* keyof `T` |
|
|
1271
1225
|
|
|
1272
1226
|
### <a id="Override"></a>Override
|
|
1273
1227
|
|
|
@@ -1279,15 +1233,14 @@ type Optional<T, F> = Omit<T, F> & Partial<Pick<T, F>>;
|
|
|
1279
1233
|
type Override<T1, T2> = Omit<T1, keyof T2> & T2;
|
|
1280
1234
|
```
|
|
1281
1235
|
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
### T1
|
|
1285
|
-
|
|
1286
|
-
`T1`
|
|
1236
|
+
Overrides properties of T1 with those from T2.
|
|
1287
1237
|
|
|
1288
|
-
|
|
1238
|
+
## Type Parameters
|
|
1289
1239
|
|
|
1290
|
-
|
|
1240
|
+
| Type Parameter |
|
|
1241
|
+
| ------ |
|
|
1242
|
+
| `T1` |
|
|
1243
|
+
| `T2` |
|
|
1291
1244
|
|
|
1292
1245
|
### <a id="PartialRecord"></a>PartialRecord
|
|
1293
1246
|
|
|
@@ -1301,13 +1254,10 @@ type PartialRecord<K, T> = { [P in K]?: T };
|
|
|
1301
1254
|
|
|
1302
1255
|
## Type Parameters
|
|
1303
1256
|
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
`K` *extends* keyof `any`
|
|
1307
|
-
|
|
1308
|
-
### T
|
|
1309
|
-
|
|
1310
|
-
`T`
|
|
1257
|
+
| Type Parameter |
|
|
1258
|
+
| ------ |
|
|
1259
|
+
| `K` *extends* keyof `any` |
|
|
1260
|
+
| `T` |
|
|
1311
1261
|
|
|
1312
1262
|
## Deprecated
|
|
1313
1263
|
|
|
@@ -1320,24 +1270,23 @@ use Partial<Record<>> instead
|
|
|
1320
1270
|
***
|
|
1321
1271
|
|
|
1322
1272
|
```ts
|
|
1323
|
-
type PickByPredicate<T> = (value, key) => boolean;
|
|
1273
|
+
type PickByPredicate<T> = (value: T[keyof T], key: keyof T) => boolean;
|
|
1324
1274
|
```
|
|
1325
1275
|
|
|
1326
|
-
|
|
1276
|
+
A predicate function used to determine which properties to pick from an object.
|
|
1327
1277
|
|
|
1328
|
-
|
|
1278
|
+
## Type Parameters
|
|
1329
1279
|
|
|
1330
|
-
|
|
1280
|
+
| Type Parameter | Default type |
|
|
1281
|
+
| ------ | ------ |
|
|
1282
|
+
| `T` *extends* [`EmptyObject`](#EmptyObject) | `Record`\<`string`, `unknown`\> |
|
|
1331
1283
|
|
|
1332
1284
|
## Parameters
|
|
1333
1285
|
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
`T`\[keyof `T`\]
|
|
1337
|
-
|
|
1338
|
-
### key
|
|
1339
|
-
|
|
1340
|
-
keyof `T`
|
|
1286
|
+
| Parameter | Type |
|
|
1287
|
+
| ------ | ------ |
|
|
1288
|
+
| `value` | `T`\[keyof `T`\] |
|
|
1289
|
+
| `key` | keyof `T` |
|
|
1341
1290
|
|
|
1342
1291
|
## Returns
|
|
1343
1292
|
|
|
@@ -1353,15 +1302,14 @@ keyof `T`
|
|
|
1353
1302
|
type PickStartsWith<T, Prefix> = { [K in keyof T as K extends `${Prefix}${string}` ? K : never]: T[K] };
|
|
1354
1303
|
```
|
|
1355
1304
|
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
### T
|
|
1359
|
-
|
|
1360
|
-
`T`
|
|
1305
|
+
Picks only the keys of T that start with the given prefix.
|
|
1361
1306
|
|
|
1362
|
-
|
|
1307
|
+
## Type Parameters
|
|
1363
1308
|
|
|
1364
|
-
|
|
1309
|
+
| Type Parameter |
|
|
1310
|
+
| ------ |
|
|
1311
|
+
| `T` |
|
|
1312
|
+
| `Prefix` *extends* `string` |
|
|
1365
1313
|
|
|
1366
1314
|
### <a id="Simplify"></a>Simplify
|
|
1367
1315
|
|
|
@@ -1370,14 +1318,17 @@ type PickStartsWith<T, Prefix> = { [K in keyof T as K extends `${Prefix}${string
|
|
|
1370
1318
|
***
|
|
1371
1319
|
|
|
1372
1320
|
```ts
|
|
1373
|
-
type Simplify<T> = { [K in keyof T]: T[K] } &
|
|
1321
|
+
type Simplify<T> = { [K in keyof T]: T[K] } & {
|
|
1322
|
+
};
|
|
1374
1323
|
```
|
|
1375
1324
|
|
|
1376
|
-
|
|
1325
|
+
Flattens an intersection or complex mapped type into a single object type for better readability.
|
|
1377
1326
|
|
|
1378
|
-
|
|
1327
|
+
## Type Parameters
|
|
1379
1328
|
|
|
1380
|
-
|
|
1329
|
+
| Type Parameter |
|
|
1330
|
+
| ------ |
|
|
1331
|
+
| `T` |
|
|
1381
1332
|
|
|
1382
1333
|
### <a id="StringKeyObject"></a>StringKeyObject
|
|
1383
1334
|
|
|
@@ -1386,14 +1337,18 @@ type Simplify<T> = { [K in keyof T]: T[K] } & object;
|
|
|
1386
1337
|
***
|
|
1387
1338
|
|
|
1388
1339
|
```ts
|
|
1389
|
-
type StringKeyObject<T> =
|
|
1340
|
+
type StringKeyObject<T> = {
|
|
1341
|
+
[key: string]: T;
|
|
1342
|
+
};
|
|
1390
1343
|
```
|
|
1391
1344
|
|
|
1392
|
-
|
|
1345
|
+
An object type with string keys and values of type T.
|
|
1393
1346
|
|
|
1394
|
-
|
|
1347
|
+
## Type Parameters
|
|
1395
1348
|
|
|
1396
|
-
|
|
1349
|
+
| Type Parameter | Default type |
|
|
1350
|
+
| ------ | ------ |
|
|
1351
|
+
| `T` | `unknown` |
|
|
1397
1352
|
|
|
1398
1353
|
## Index Signature
|
|
1399
1354
|
|
|
@@ -1411,11 +1366,13 @@ type StringKeyObject<T> = object;
|
|
|
1411
1366
|
type StringOrAlertFunction<T> = string | AssertExMessageFunc<T>;
|
|
1412
1367
|
```
|
|
1413
1368
|
|
|
1414
|
-
|
|
1369
|
+
A string message or function that produces an assertion error message for a failed type check.
|
|
1415
1370
|
|
|
1416
|
-
|
|
1371
|
+
## Type Parameters
|
|
1417
1372
|
|
|
1418
|
-
|
|
1373
|
+
| Type Parameter |
|
|
1374
|
+
| ------ |
|
|
1375
|
+
| `T` *extends* `AnyNonPromise` |
|
|
1419
1376
|
|
|
1420
1377
|
### <a id="TypeCheck"></a>TypeCheck
|
|
1421
1378
|
|
|
@@ -1425,29 +1382,34 @@ type StringOrAlertFunction<T> = string | AssertExMessageFunc<T>;
|
|
|
1425
1382
|
|
|
1426
1383
|
```ts
|
|
1427
1384
|
type TypeCheck<T> = {
|
|
1428
|
-
(obj): obj is T;
|
|
1429
|
-
(obj, config): obj is T;
|
|
1430
|
-
(obj, config
|
|
1385
|
+
(obj: AnyNonPromise): obj is T;
|
|
1386
|
+
(obj: AnyNonPromise, config: TypeCheckConfig): obj is T;
|
|
1387
|
+
(obj: AnyNonPromise, config:
|
|
1388
|
+
| number
|
|
1389
|
+
| TypeCheckConfig
|
|
1390
|
+
| undefined): obj is T;
|
|
1431
1391
|
};
|
|
1432
1392
|
```
|
|
1433
1393
|
|
|
1434
|
-
|
|
1394
|
+
A type guard function that checks whether a value conforms to type T, with optional configuration.
|
|
1435
1395
|
|
|
1436
|
-
|
|
1396
|
+
## Type Parameters
|
|
1437
1397
|
|
|
1438
|
-
|
|
1398
|
+
| Type Parameter |
|
|
1399
|
+
| ------ |
|
|
1400
|
+
| `T` *extends* `TypedValue` |
|
|
1439
1401
|
|
|
1440
1402
|
## Call Signature
|
|
1441
1403
|
|
|
1442
1404
|
```ts
|
|
1443
|
-
(obj): obj is T;
|
|
1405
|
+
(obj: AnyNonPromise): obj is T;
|
|
1444
1406
|
```
|
|
1445
1407
|
|
|
1446
1408
|
### Parameters
|
|
1447
1409
|
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
`AnyNonPromise`
|
|
1410
|
+
| Parameter | Type |
|
|
1411
|
+
| ------ | ------ |
|
|
1412
|
+
| `obj` | `AnyNonPromise` |
|
|
1451
1413
|
|
|
1452
1414
|
### Returns
|
|
1453
1415
|
|
|
@@ -1456,18 +1418,15 @@ type TypeCheck<T> = {
|
|
|
1456
1418
|
## Call Signature
|
|
1457
1419
|
|
|
1458
1420
|
```ts
|
|
1459
|
-
(obj, config): obj is T;
|
|
1421
|
+
(obj: AnyNonPromise, config: TypeCheckConfig): obj is T;
|
|
1460
1422
|
```
|
|
1461
1423
|
|
|
1462
1424
|
### Parameters
|
|
1463
1425
|
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
`AnyNonPromise`
|
|
1467
|
-
|
|
1468
|
-
### config
|
|
1469
|
-
|
|
1470
|
-
[`TypeCheckConfig`](#../interfaces/TypeCheckConfig)
|
|
1426
|
+
| Parameter | Type |
|
|
1427
|
+
| ------ | ------ |
|
|
1428
|
+
| `obj` | `AnyNonPromise` |
|
|
1429
|
+
| `config` | [`TypeCheckConfig`](#../interfaces/TypeCheckConfig) |
|
|
1471
1430
|
|
|
1472
1431
|
### Returns
|
|
1473
1432
|
|
|
@@ -1476,18 +1435,18 @@ type TypeCheck<T> = {
|
|
|
1476
1435
|
## Call Signature
|
|
1477
1436
|
|
|
1478
1437
|
```ts
|
|
1479
|
-
(obj, config
|
|
1438
|
+
(obj: AnyNonPromise, config:
|
|
1439
|
+
| number
|
|
1440
|
+
| TypeCheckConfig
|
|
1441
|
+
| undefined): obj is T;
|
|
1480
1442
|
```
|
|
1481
1443
|
|
|
1482
1444
|
### Parameters
|
|
1483
1445
|
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
`AnyNonPromise`
|
|
1487
|
-
|
|
1488
|
-
### config
|
|
1489
|
-
|
|
1490
|
-
`number` | [`TypeCheckConfig`](#../interfaces/TypeCheckConfig) | `undefined`
|
|
1446
|
+
| Parameter | Type |
|
|
1447
|
+
| ------ | ------ |
|
|
1448
|
+
| `obj` | `AnyNonPromise` |
|
|
1449
|
+
| `config` | \| `number` \| [`TypeCheckConfig`](#../interfaces/TypeCheckConfig) \| `undefined` |
|
|
1491
1450
|
|
|
1492
1451
|
### Returns
|
|
1493
1452
|
|
|
@@ -1503,15 +1462,14 @@ type TypeCheck<T> = {
|
|
|
1503
1462
|
type WithAdditional<T, TAdditional> = TAdditional extends EmptyObject ? T & TAdditional : T;
|
|
1504
1463
|
```
|
|
1505
1464
|
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
### T
|
|
1465
|
+
Intersects T with TAdditional if TAdditional is an object, otherwise returns T unchanged.
|
|
1509
1466
|
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
### TAdditional
|
|
1467
|
+
## Type Parameters
|
|
1513
1468
|
|
|
1514
|
-
|
|
1469
|
+
| Type Parameter | Default type |
|
|
1470
|
+
| ------ | ------ |
|
|
1471
|
+
| `T` *extends* [`EmptyObject`](#EmptyObject) \| `void` | - |
|
|
1472
|
+
| `TAdditional` *extends* [`EmptyObject`](#EmptyObject) \| `void` | `void` |
|
|
1515
1473
|
|
|
1516
1474
|
### variables
|
|
1517
1475
|
|
|
@@ -1522,66 +1480,20 @@ type WithAdditional<T, TAdditional> = TAdditional extends EmptyObject ? T & TAdd
|
|
|
1522
1480
|
***
|
|
1523
1481
|
|
|
1524
1482
|
```ts
|
|
1525
|
-
const AsObjectFactory:
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
### create()
|
|
1531
|
-
|
|
1532
|
-
```ts
|
|
1533
|
-
create: <T>(typeCheck) => AsTypeFunction<T>;
|
|
1534
|
-
```
|
|
1535
|
-
|
|
1536
|
-
### Type Parameters
|
|
1537
|
-
|
|
1538
|
-
#### T
|
|
1539
|
-
|
|
1540
|
-
`T` *extends* `TypedObject`
|
|
1541
|
-
|
|
1542
|
-
### Parameters
|
|
1543
|
-
|
|
1544
|
-
#### typeCheck
|
|
1545
|
-
|
|
1546
|
-
[`TypeCheck`](#../type-aliases/TypeCheck)\<`T`\>
|
|
1547
|
-
|
|
1548
|
-
### Returns
|
|
1549
|
-
|
|
1550
|
-
[`AsTypeFunction`](#../type-aliases/AsTypeFunction)\<`T`\>
|
|
1551
|
-
|
|
1552
|
-
### createOptional()
|
|
1553
|
-
|
|
1554
|
-
```ts
|
|
1555
|
-
createOptional: <T>(typeCheck) => (value) => T | undefined;
|
|
1556
|
-
```
|
|
1557
|
-
|
|
1558
|
-
### Type Parameters
|
|
1559
|
-
|
|
1560
|
-
#### T
|
|
1561
|
-
|
|
1562
|
-
`T` *extends* `TypedObject`
|
|
1563
|
-
|
|
1564
|
-
### Parameters
|
|
1565
|
-
|
|
1566
|
-
#### typeCheck
|
|
1567
|
-
|
|
1568
|
-
[`TypeCheck`](#../type-aliases/TypeCheck)\<`T`\>
|
|
1569
|
-
|
|
1570
|
-
### Returns
|
|
1571
|
-
|
|
1572
|
-
```ts
|
|
1573
|
-
(value): T | undefined;
|
|
1483
|
+
const AsObjectFactory: {
|
|
1484
|
+
create: <T>(typeCheck: TypeCheck<T>) => AsTypeFunction<T>;
|
|
1485
|
+
createOptional: <T>(typeCheck: TypeCheck<T>) => (value: AnyNonPromise) => T | undefined;
|
|
1486
|
+
};
|
|
1574
1487
|
```
|
|
1575
1488
|
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
##### value
|
|
1489
|
+
Factory for creating type-narrowing functions for TypedObject types.
|
|
1579
1490
|
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
#### Returns
|
|
1491
|
+
## Type Declaration
|
|
1583
1492
|
|
|
1584
|
-
|
|
1493
|
+
| Name | Type |
|
|
1494
|
+
| ------ | ------ |
|
|
1495
|
+
| <a id="property-create"></a> `create()` | \<`T`\>(`typeCheck`: [`TypeCheck`](#../type-aliases/TypeCheck)\<`T`\>) => [`AsTypeFunction`](#../type-aliases/AsTypeFunction)\<`T`\> |
|
|
1496
|
+
| <a id="property-createoptional"></a> `createOptional()` | \<`T`\>(`typeCheck`: [`TypeCheck`](#../type-aliases/TypeCheck)\<`T`\>) => (`value`: `AnyNonPromise`) => `T` \| `undefined` |
|
|
1585
1497
|
|
|
1586
1498
|
### <a id="AsTypeFactory"></a>AsTypeFactory
|
|
1587
1499
|
|
|
@@ -1590,66 +1502,21 @@ createOptional: <T>(typeCheck) => (value) => T | undefined;
|
|
|
1590
1502
|
***
|
|
1591
1503
|
|
|
1592
1504
|
```ts
|
|
1593
|
-
const AsTypeFactory:
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
### create()
|
|
1599
|
-
|
|
1600
|
-
```ts
|
|
1601
|
-
create: <T>(typeCheck) => AsTypeFunction<T>;
|
|
1602
|
-
```
|
|
1603
|
-
|
|
1604
|
-
### Type Parameters
|
|
1605
|
-
|
|
1606
|
-
#### T
|
|
1607
|
-
|
|
1608
|
-
`T` *extends* `AnyNonPromise`
|
|
1609
|
-
|
|
1610
|
-
### Parameters
|
|
1611
|
-
|
|
1612
|
-
#### typeCheck
|
|
1613
|
-
|
|
1614
|
-
[`TypeCheck`](#../type-aliases/TypeCheck)\<`T`\>
|
|
1615
|
-
|
|
1616
|
-
### Returns
|
|
1617
|
-
|
|
1618
|
-
[`AsTypeFunction`](#../type-aliases/AsTypeFunction)\<`T`\>
|
|
1619
|
-
|
|
1620
|
-
### createOptional()
|
|
1621
|
-
|
|
1622
|
-
```ts
|
|
1623
|
-
createOptional: <T>(typeCheck) => (value) => T | undefined;
|
|
1624
|
-
```
|
|
1625
|
-
|
|
1626
|
-
### Type Parameters
|
|
1627
|
-
|
|
1628
|
-
#### T
|
|
1629
|
-
|
|
1630
|
-
`T` *extends* `AnyNonPromise`
|
|
1631
|
-
|
|
1632
|
-
### Parameters
|
|
1633
|
-
|
|
1634
|
-
#### typeCheck
|
|
1635
|
-
|
|
1636
|
-
[`TypeCheck`](#../type-aliases/TypeCheck)\<`T`\>
|
|
1637
|
-
|
|
1638
|
-
### Returns
|
|
1639
|
-
|
|
1640
|
-
```ts
|
|
1641
|
-
(value): T | undefined;
|
|
1505
|
+
const AsTypeFactory: {
|
|
1506
|
+
create: <T>(typeCheck: TypeCheck<T>) => AsTypeFunction<T>;
|
|
1507
|
+
createOptional: <T>(typeCheck: TypeCheck<T>) => (value: AnyNonPromise) => T | undefined;
|
|
1508
|
+
};
|
|
1642
1509
|
```
|
|
1643
1510
|
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
##### value
|
|
1511
|
+
Factory for creating type-narrowing 'as' functions that cast a value to T or return undefined.
|
|
1512
|
+
Supports optional assertion messages and configuration for required/optional behavior.
|
|
1647
1513
|
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
#### Returns
|
|
1514
|
+
## Type Declaration
|
|
1651
1515
|
|
|
1652
|
-
|
|
1516
|
+
| Name | Type |
|
|
1517
|
+
| ------ | ------ |
|
|
1518
|
+
| <a id="property-create"></a> `create()` | \<`T`\>(`typeCheck`: [`TypeCheck`](#../type-aliases/TypeCheck)\<`T`\>) => [`AsTypeFunction`](#../type-aliases/AsTypeFunction)\<`T`\> |
|
|
1519
|
+
| <a id="property-createoptional"></a> `createOptional()` | \<`T`\>(`typeCheck`: [`TypeCheck`](#../type-aliases/TypeCheck)\<`T`\>) => (`value`: `AnyNonPromise`) => `T` \| `undefined` |
|
|
1653
1520
|
|
|
1654
1521
|
### <a id="JsonObjectZod"></a>JsonObjectZod
|
|
1655
1522
|
|
|
@@ -1661,6 +1528,8 @@ createOptional: <T>(typeCheck) => (value) => T | undefined;
|
|
|
1661
1528
|
const JsonObjectZod: ZodRecord<ZodString, ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>>;
|
|
1662
1529
|
```
|
|
1663
1530
|
|
|
1531
|
+
Zod schema for a JSON object with string keys and recursive JSON values.
|
|
1532
|
+
|
|
1664
1533
|
### <a id="asAnyObject"></a>asAnyObject
|
|
1665
1534
|
|
|
1666
1535
|
[**@xylabs/object**](#../../README)
|
|
@@ -1671,6 +1540,8 @@ const JsonObjectZod: ZodRecord<ZodString, ZodType<unknown, unknown, $ZodTypeInte
|
|
|
1671
1540
|
const asAnyObject: AsTypeFunction<AnyObject>;
|
|
1672
1541
|
```
|
|
1673
1542
|
|
|
1543
|
+
Type-narrowing function that casts a value to AnyObject if it is a plain object, or returns undefined.
|
|
1544
|
+
|
|
1674
1545
|
### <a id="asJsonArray"></a>asJsonArray
|
|
1675
1546
|
|
|
1676
1547
|
[**@xylabs/object**](#../../README)
|
|
@@ -1679,28 +1550,30 @@ const asAnyObject: AsTypeFunction<AnyObject>;
|
|
|
1679
1550
|
|
|
1680
1551
|
```ts
|
|
1681
1552
|
const asJsonArray: {
|
|
1682
|
-
<T> (value): T & unknown[] | undefined;
|
|
1683
|
-
<T> (value, assert): T & unknown[];
|
|
1553
|
+
<T> (value: T): T & unknown[] | undefined;
|
|
1554
|
+
<T> (value: T, assert: ZodFactoryConfig): T & unknown[];
|
|
1684
1555
|
};
|
|
1685
1556
|
```
|
|
1686
1557
|
|
|
1558
|
+
Casts a value to JsonArray or returns undefined if it does not conform.
|
|
1559
|
+
|
|
1687
1560
|
## Call Signature
|
|
1688
1561
|
|
|
1689
1562
|
```ts
|
|
1690
|
-
<T>(value): T & unknown[] | undefined;
|
|
1563
|
+
<T>(value: T): T & unknown[] | undefined;
|
|
1691
1564
|
```
|
|
1692
1565
|
|
|
1693
1566
|
### Type Parameters
|
|
1694
1567
|
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
`T`
|
|
1568
|
+
| Type Parameter |
|
|
1569
|
+
| ------ |
|
|
1570
|
+
| `T` |
|
|
1698
1571
|
|
|
1699
1572
|
### Parameters
|
|
1700
1573
|
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
`T`
|
|
1574
|
+
| Parameter | Type |
|
|
1575
|
+
| ------ | ------ |
|
|
1576
|
+
| `value` | `T` |
|
|
1704
1577
|
|
|
1705
1578
|
### Returns
|
|
1706
1579
|
|
|
@@ -1709,24 +1582,21 @@ const asJsonArray: {
|
|
|
1709
1582
|
## Call Signature
|
|
1710
1583
|
|
|
1711
1584
|
```ts
|
|
1712
|
-
<T>(value, assert): T & unknown[];
|
|
1585
|
+
<T>(value: T, assert: ZodFactoryConfig): T & unknown[];
|
|
1713
1586
|
```
|
|
1714
1587
|
|
|
1715
1588
|
### Type Parameters
|
|
1716
1589
|
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
`T`
|
|
1590
|
+
| Type Parameter |
|
|
1591
|
+
| ------ |
|
|
1592
|
+
| `T` |
|
|
1720
1593
|
|
|
1721
1594
|
### Parameters
|
|
1722
1595
|
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
`T`
|
|
1726
|
-
|
|
1727
|
-
### assert
|
|
1728
|
-
|
|
1729
|
-
`ZodFactoryConfig`
|
|
1596
|
+
| Parameter | Type |
|
|
1597
|
+
| ------ | ------ |
|
|
1598
|
+
| `value` | `T` |
|
|
1599
|
+
| `assert` | `ZodFactoryConfig` |
|
|
1730
1600
|
|
|
1731
1601
|
### Returns
|
|
1732
1602
|
|
|
@@ -1740,28 +1610,30 @@ const asJsonArray: {
|
|
|
1740
1610
|
|
|
1741
1611
|
```ts
|
|
1742
1612
|
const asJsonObject: {
|
|
1743
|
-
<T> (value): T & Record<string, unknown> | undefined;
|
|
1744
|
-
<T> (value, assert): T & Record<string, unknown>;
|
|
1613
|
+
<T> (value: T): T & Record<string, unknown> | undefined;
|
|
1614
|
+
<T> (value: T, assert: ZodFactoryConfig): T & Record<string, unknown>;
|
|
1745
1615
|
};
|
|
1746
1616
|
```
|
|
1747
1617
|
|
|
1618
|
+
Casts a value to JsonObject or returns undefined if it does not conform.
|
|
1619
|
+
|
|
1748
1620
|
## Call Signature
|
|
1749
1621
|
|
|
1750
1622
|
```ts
|
|
1751
|
-
<T>(value): T & Record<string, unknown> | undefined;
|
|
1623
|
+
<T>(value: T): T & Record<string, unknown> | undefined;
|
|
1752
1624
|
```
|
|
1753
1625
|
|
|
1754
1626
|
### Type Parameters
|
|
1755
1627
|
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
`T`
|
|
1628
|
+
| Type Parameter |
|
|
1629
|
+
| ------ |
|
|
1630
|
+
| `T` |
|
|
1759
1631
|
|
|
1760
1632
|
### Parameters
|
|
1761
1633
|
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
`T`
|
|
1634
|
+
| Parameter | Type |
|
|
1635
|
+
| ------ | ------ |
|
|
1636
|
+
| `value` | `T` |
|
|
1765
1637
|
|
|
1766
1638
|
### Returns
|
|
1767
1639
|
|
|
@@ -1770,24 +1642,21 @@ const asJsonObject: {
|
|
|
1770
1642
|
## Call Signature
|
|
1771
1643
|
|
|
1772
1644
|
```ts
|
|
1773
|
-
<T>(value, assert): T & Record<string, unknown>;
|
|
1645
|
+
<T>(value: T, assert: ZodFactoryConfig): T & Record<string, unknown>;
|
|
1774
1646
|
```
|
|
1775
1647
|
|
|
1776
1648
|
### Type Parameters
|
|
1777
1649
|
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
`T`
|
|
1650
|
+
| Type Parameter |
|
|
1651
|
+
| ------ |
|
|
1652
|
+
| `T` |
|
|
1781
1653
|
|
|
1782
1654
|
### Parameters
|
|
1783
1655
|
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
`T`
|
|
1787
|
-
|
|
1788
|
-
### assert
|
|
1789
|
-
|
|
1790
|
-
`ZodFactoryConfig`
|
|
1656
|
+
| Parameter | Type |
|
|
1657
|
+
| ------ | ------ |
|
|
1658
|
+
| `value` | `T` |
|
|
1659
|
+
| `assert` | `ZodFactoryConfig` |
|
|
1791
1660
|
|
|
1792
1661
|
### Returns
|
|
1793
1662
|
|
|
@@ -1801,28 +1670,30 @@ const asJsonObject: {
|
|
|
1801
1670
|
|
|
1802
1671
|
```ts
|
|
1803
1672
|
const asJsonValue: {
|
|
1804
|
-
<T> (value): T | undefined;
|
|
1805
|
-
<T> (value, assert): T;
|
|
1673
|
+
<T> (value: T): T | undefined;
|
|
1674
|
+
<T> (value: T, assert: ZodFactoryConfig): T;
|
|
1806
1675
|
};
|
|
1807
1676
|
```
|
|
1808
1677
|
|
|
1678
|
+
Casts a value to JsonValue or returns undefined if it does not conform.
|
|
1679
|
+
|
|
1809
1680
|
## Call Signature
|
|
1810
1681
|
|
|
1811
1682
|
```ts
|
|
1812
|
-
<T>(value): T | undefined;
|
|
1683
|
+
<T>(value: T): T | undefined;
|
|
1813
1684
|
```
|
|
1814
1685
|
|
|
1815
1686
|
### Type Parameters
|
|
1816
1687
|
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
`T`
|
|
1688
|
+
| Type Parameter |
|
|
1689
|
+
| ------ |
|
|
1690
|
+
| `T` |
|
|
1820
1691
|
|
|
1821
1692
|
### Parameters
|
|
1822
1693
|
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
`T`
|
|
1694
|
+
| Parameter | Type |
|
|
1695
|
+
| ------ | ------ |
|
|
1696
|
+
| `value` | `T` |
|
|
1826
1697
|
|
|
1827
1698
|
### Returns
|
|
1828
1699
|
|
|
@@ -1831,24 +1702,21 @@ const asJsonValue: {
|
|
|
1831
1702
|
## Call Signature
|
|
1832
1703
|
|
|
1833
1704
|
```ts
|
|
1834
|
-
<T>(value, assert): T;
|
|
1705
|
+
<T>(value: T, assert: ZodFactoryConfig): T;
|
|
1835
1706
|
```
|
|
1836
1707
|
|
|
1837
1708
|
### Type Parameters
|
|
1838
1709
|
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
`T`
|
|
1710
|
+
| Type Parameter |
|
|
1711
|
+
| ------ |
|
|
1712
|
+
| `T` |
|
|
1842
1713
|
|
|
1843
1714
|
### Parameters
|
|
1844
1715
|
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
`T`
|
|
1848
|
-
|
|
1849
|
-
### assert
|
|
1850
|
-
|
|
1851
|
-
`ZodFactoryConfig`
|
|
1716
|
+
| Parameter | Type |
|
|
1717
|
+
| ------ | ------ |
|
|
1718
|
+
| `value` | `T` |
|
|
1719
|
+
| `assert` | `ZodFactoryConfig` |
|
|
1852
1720
|
|
|
1853
1721
|
### Returns
|
|
1854
1722
|
|
|
@@ -1861,31 +1729,22 @@ const asJsonValue: {
|
|
|
1861
1729
|
***
|
|
1862
1730
|
|
|
1863
1731
|
```ts
|
|
1864
|
-
const deepMerge: <T>(...objects) => MergeAll<T>;
|
|
1732
|
+
const deepMerge: <T>(...objects: T) => MergeAll<T>;
|
|
1865
1733
|
```
|
|
1866
1734
|
|
|
1867
1735
|
Deeply merges multiple objects into a new object.
|
|
1868
1736
|
|
|
1869
1737
|
## Type Parameters
|
|
1870
1738
|
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
`T` *extends* [`AnyObject`](#../type-aliases/AnyObject)[]
|
|
1739
|
+
| Type Parameter |
|
|
1740
|
+
| ------ |
|
|
1741
|
+
| `T` *extends* [`AnyObject`](#../type-aliases/AnyObject)[] |
|
|
1874
1742
|
|
|
1875
1743
|
## Parameters
|
|
1876
1744
|
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
...`T`
|
|
1880
|
-
|
|
1881
|
-
Multiple objects to merge deeply.
|
|
1882
|
-
The function merges properties from all objects into a new object.
|
|
1883
|
-
If a property exists in multiple objects, the last object's value will be used.
|
|
1884
|
-
If a property is an object, it will be merged recursively.
|
|
1885
|
-
If a property is an array, it will be overwritten by the last object's value.
|
|
1886
|
-
If a property is a primitive value, it will be overwritten by the last object's value.
|
|
1887
|
-
If a property is undefined in the source, it will be skipped.
|
|
1888
|
-
If a property is a symbol, it will be merged as well.
|
|
1745
|
+
| Parameter | Type | Description |
|
|
1746
|
+
| ------ | ------ | ------ |
|
|
1747
|
+
| ...`objects` | `T` | Multiple objects to merge deeply. The function merges properties from all objects into a new object. If a property exists in multiple objects, the last object's value will be used. If a property is an object, it will be merged recursively. If a property is an array, it will be overwritten by the last object's value. If a property is a primitive value, it will be overwritten by the last object's value. If a property is undefined in the source, it will be skipped. If a property is a symbol, it will be merged as well. |
|
|
1889
1748
|
|
|
1890
1749
|
## Returns
|
|
1891
1750
|
|
|
@@ -1900,20 +1759,22 @@ A new object with the merged properties.
|
|
|
1900
1759
|
***
|
|
1901
1760
|
|
|
1902
1761
|
```ts
|
|
1903
|
-
const isJsonArray: <T>(value) => value is T & unknown[];
|
|
1762
|
+
const isJsonArray: <T>(value: T) => value is T & unknown[];
|
|
1904
1763
|
```
|
|
1905
1764
|
|
|
1906
|
-
|
|
1765
|
+
Type guard that checks if a value is a valid JSON array.
|
|
1907
1766
|
|
|
1908
|
-
|
|
1767
|
+
## Type Parameters
|
|
1909
1768
|
|
|
1910
|
-
|
|
1769
|
+
| Type Parameter |
|
|
1770
|
+
| ------ |
|
|
1771
|
+
| `T` |
|
|
1911
1772
|
|
|
1912
1773
|
## Parameters
|
|
1913
1774
|
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
`T`
|
|
1775
|
+
| Parameter | Type |
|
|
1776
|
+
| ------ | ------ |
|
|
1777
|
+
| `value` | `T` |
|
|
1917
1778
|
|
|
1918
1779
|
## Returns
|
|
1919
1780
|
|
|
@@ -1926,20 +1787,22 @@ const isJsonArray: <T>(value) => value is T & unknown[];
|
|
|
1926
1787
|
***
|
|
1927
1788
|
|
|
1928
1789
|
```ts
|
|
1929
|
-
const isJsonObject: <T>(value) => value is T & Record<string, unknown>;
|
|
1790
|
+
const isJsonObject: <T>(value: T) => value is T & Record<string, unknown>;
|
|
1930
1791
|
```
|
|
1931
1792
|
|
|
1932
|
-
|
|
1793
|
+
Type guard that checks if a value is a valid JSON object.
|
|
1933
1794
|
|
|
1934
|
-
|
|
1795
|
+
## Type Parameters
|
|
1935
1796
|
|
|
1936
|
-
|
|
1797
|
+
| Type Parameter |
|
|
1798
|
+
| ------ |
|
|
1799
|
+
| `T` |
|
|
1937
1800
|
|
|
1938
1801
|
## Parameters
|
|
1939
1802
|
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
`T`
|
|
1803
|
+
| Parameter | Type |
|
|
1804
|
+
| ------ | ------ |
|
|
1805
|
+
| `value` | `T` |
|
|
1943
1806
|
|
|
1944
1807
|
## Returns
|
|
1945
1808
|
|
|
@@ -1952,20 +1815,22 @@ const isJsonObject: <T>(value) => value is T & Record<string, unknown>;
|
|
|
1952
1815
|
***
|
|
1953
1816
|
|
|
1954
1817
|
```ts
|
|
1955
|
-
const isJsonValue: <T>(value) => value is T;
|
|
1818
|
+
const isJsonValue: <T>(value: T) => value is T;
|
|
1956
1819
|
```
|
|
1957
1820
|
|
|
1958
|
-
|
|
1821
|
+
Type guard that checks if a value is a valid JSON value.
|
|
1959
1822
|
|
|
1960
|
-
|
|
1823
|
+
## Type Parameters
|
|
1961
1824
|
|
|
1962
|
-
|
|
1825
|
+
| Type Parameter |
|
|
1826
|
+
| ------ |
|
|
1827
|
+
| `T` |
|
|
1963
1828
|
|
|
1964
1829
|
## Parameters
|
|
1965
1830
|
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
`T`
|
|
1831
|
+
| Parameter | Type |
|
|
1832
|
+
| ------ | ------ |
|
|
1833
|
+
| `value` | `T` |
|
|
1969
1834
|
|
|
1970
1835
|
## Returns
|
|
1971
1836
|
|
|
@@ -1979,28 +1844,30 @@ const isJsonValue: <T>(value) => value is T;
|
|
|
1979
1844
|
|
|
1980
1845
|
```ts
|
|
1981
1846
|
const toJsonArray: {
|
|
1982
|
-
<T> (value): T & unknown[] | undefined;
|
|
1983
|
-
<T> (value, assert): T & unknown[];
|
|
1847
|
+
<T> (value: T): T & unknown[] | undefined;
|
|
1848
|
+
<T> (value: T, assert: ZodFactoryConfig): T & unknown[];
|
|
1984
1849
|
};
|
|
1985
1850
|
```
|
|
1986
1851
|
|
|
1852
|
+
Parses a value into a JsonArray, throwing if it does not conform.
|
|
1853
|
+
|
|
1987
1854
|
## Call Signature
|
|
1988
1855
|
|
|
1989
1856
|
```ts
|
|
1990
|
-
<T>(value): T & unknown[] | undefined;
|
|
1857
|
+
<T>(value: T): T & unknown[] | undefined;
|
|
1991
1858
|
```
|
|
1992
1859
|
|
|
1993
1860
|
### Type Parameters
|
|
1994
1861
|
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
`T`
|
|
1862
|
+
| Type Parameter |
|
|
1863
|
+
| ------ |
|
|
1864
|
+
| `T` |
|
|
1998
1865
|
|
|
1999
1866
|
### Parameters
|
|
2000
1867
|
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
`T`
|
|
1868
|
+
| Parameter | Type |
|
|
1869
|
+
| ------ | ------ |
|
|
1870
|
+
| `value` | `T` |
|
|
2004
1871
|
|
|
2005
1872
|
### Returns
|
|
2006
1873
|
|
|
@@ -2009,24 +1876,21 @@ const toJsonArray: {
|
|
|
2009
1876
|
## Call Signature
|
|
2010
1877
|
|
|
2011
1878
|
```ts
|
|
2012
|
-
<T>(value, assert): T & unknown[];
|
|
1879
|
+
<T>(value: T, assert: ZodFactoryConfig): T & unknown[];
|
|
2013
1880
|
```
|
|
2014
1881
|
|
|
2015
1882
|
### Type Parameters
|
|
2016
1883
|
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
`T`
|
|
1884
|
+
| Type Parameter |
|
|
1885
|
+
| ------ |
|
|
1886
|
+
| `T` |
|
|
2020
1887
|
|
|
2021
1888
|
### Parameters
|
|
2022
1889
|
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
`T`
|
|
2026
|
-
|
|
2027
|
-
### assert
|
|
2028
|
-
|
|
2029
|
-
`ZodFactoryConfig`
|
|
1890
|
+
| Parameter | Type |
|
|
1891
|
+
| ------ | ------ |
|
|
1892
|
+
| `value` | `T` |
|
|
1893
|
+
| `assert` | `ZodFactoryConfig` |
|
|
2030
1894
|
|
|
2031
1895
|
### Returns
|
|
2032
1896
|
|
|
@@ -2040,28 +1904,30 @@ const toJsonArray: {
|
|
|
2040
1904
|
|
|
2041
1905
|
```ts
|
|
2042
1906
|
const toJsonObject: {
|
|
2043
|
-
<T> (value): T & Record<string, unknown> | undefined;
|
|
2044
|
-
<T> (value, assert): T & Record<string, unknown>;
|
|
1907
|
+
<T> (value: T): T & Record<string, unknown> | undefined;
|
|
1908
|
+
<T> (value: T, assert: ZodFactoryConfig): T & Record<string, unknown>;
|
|
2045
1909
|
};
|
|
2046
1910
|
```
|
|
2047
1911
|
|
|
1912
|
+
Parses a value into a JsonObject, throwing if it does not conform.
|
|
1913
|
+
|
|
2048
1914
|
## Call Signature
|
|
2049
1915
|
|
|
2050
1916
|
```ts
|
|
2051
|
-
<T>(value): T & Record<string, unknown> | undefined;
|
|
1917
|
+
<T>(value: T): T & Record<string, unknown> | undefined;
|
|
2052
1918
|
```
|
|
2053
1919
|
|
|
2054
1920
|
### Type Parameters
|
|
2055
1921
|
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
`T`
|
|
1922
|
+
| Type Parameter |
|
|
1923
|
+
| ------ |
|
|
1924
|
+
| `T` |
|
|
2059
1925
|
|
|
2060
1926
|
### Parameters
|
|
2061
1927
|
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
`T`
|
|
1928
|
+
| Parameter | Type |
|
|
1929
|
+
| ------ | ------ |
|
|
1930
|
+
| `value` | `T` |
|
|
2065
1931
|
|
|
2066
1932
|
### Returns
|
|
2067
1933
|
|
|
@@ -2070,24 +1936,21 @@ const toJsonObject: {
|
|
|
2070
1936
|
## Call Signature
|
|
2071
1937
|
|
|
2072
1938
|
```ts
|
|
2073
|
-
<T>(value, assert): T & Record<string, unknown>;
|
|
1939
|
+
<T>(value: T, assert: ZodFactoryConfig): T & Record<string, unknown>;
|
|
2074
1940
|
```
|
|
2075
1941
|
|
|
2076
1942
|
### Type Parameters
|
|
2077
1943
|
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
`T`
|
|
1944
|
+
| Type Parameter |
|
|
1945
|
+
| ------ |
|
|
1946
|
+
| `T` |
|
|
2081
1947
|
|
|
2082
1948
|
### Parameters
|
|
2083
1949
|
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
`T`
|
|
2087
|
-
|
|
2088
|
-
### assert
|
|
2089
|
-
|
|
2090
|
-
`ZodFactoryConfig`
|
|
1950
|
+
| Parameter | Type |
|
|
1951
|
+
| ------ | ------ |
|
|
1952
|
+
| `value` | `T` |
|
|
1953
|
+
| `assert` | `ZodFactoryConfig` |
|
|
2091
1954
|
|
|
2092
1955
|
### Returns
|
|
2093
1956
|
|
|
@@ -2101,28 +1964,30 @@ const toJsonObject: {
|
|
|
2101
1964
|
|
|
2102
1965
|
```ts
|
|
2103
1966
|
const toJsonValue: {
|
|
2104
|
-
<T> (value): T | undefined;
|
|
2105
|
-
<T> (value, assert): T;
|
|
1967
|
+
<T> (value: T): T | undefined;
|
|
1968
|
+
<T> (value: T, assert: ZodFactoryConfig): T;
|
|
2106
1969
|
};
|
|
2107
1970
|
```
|
|
2108
1971
|
|
|
1972
|
+
Parses a value into a JsonValue, throwing if it does not conform.
|
|
1973
|
+
|
|
2109
1974
|
## Call Signature
|
|
2110
1975
|
|
|
2111
1976
|
```ts
|
|
2112
|
-
<T>(value): T | undefined;
|
|
1977
|
+
<T>(value: T): T | undefined;
|
|
2113
1978
|
```
|
|
2114
1979
|
|
|
2115
1980
|
### Type Parameters
|
|
2116
1981
|
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
`T`
|
|
1982
|
+
| Type Parameter |
|
|
1983
|
+
| ------ |
|
|
1984
|
+
| `T` |
|
|
2120
1985
|
|
|
2121
1986
|
### Parameters
|
|
2122
1987
|
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
`T`
|
|
1988
|
+
| Parameter | Type |
|
|
1989
|
+
| ------ | ------ |
|
|
1990
|
+
| `value` | `T` |
|
|
2126
1991
|
|
|
2127
1992
|
### Returns
|
|
2128
1993
|
|
|
@@ -2131,24 +1996,21 @@ const toJsonValue: {
|
|
|
2131
1996
|
## Call Signature
|
|
2132
1997
|
|
|
2133
1998
|
```ts
|
|
2134
|
-
<T>(value, assert): T;
|
|
1999
|
+
<T>(value: T, assert: ZodFactoryConfig): T;
|
|
2135
2000
|
```
|
|
2136
2001
|
|
|
2137
2002
|
### Type Parameters
|
|
2138
2003
|
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
`T`
|
|
2004
|
+
| Type Parameter |
|
|
2005
|
+
| ------ |
|
|
2006
|
+
| `T` |
|
|
2142
2007
|
|
|
2143
2008
|
### Parameters
|
|
2144
2009
|
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
`T`
|
|
2148
|
-
|
|
2149
|
-
### assert
|
|
2150
|
-
|
|
2151
|
-
`ZodFactoryConfig`
|
|
2010
|
+
| Parameter | Type |
|
|
2011
|
+
| ------ | ------ |
|
|
2012
|
+
| `value` | `T` |
|
|
2013
|
+
| `assert` | `ZodFactoryConfig` |
|
|
2152
2014
|
|
|
2153
2015
|
### Returns
|
|
2154
2016
|
|