@xylabs/object 5.0.83 → 5.0.84
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 +192 -0
- 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
|
@@ -39,6 +39,8 @@ Base functionality used throughout XY Labs TypeScript/JavaScript libraries
|
|
|
39
39
|
|
|
40
40
|
***
|
|
41
41
|
|
|
42
|
+
Factory class for creating type-guard functions that validate objects against a given shape and optional additional checks.
|
|
43
|
+
|
|
42
44
|
## Type Parameters
|
|
43
45
|
|
|
44
46
|
### T
|
|
@@ -65,26 +67,36 @@ new IsObjectFactory<T>(): IsObjectFactory<T>;
|
|
|
65
67
|
create(shape?, additionalChecks?): TypeCheck<T>;
|
|
66
68
|
```
|
|
67
69
|
|
|
70
|
+
Creates a type-guard function that validates an object matches the given shape and passes additional checks.
|
|
71
|
+
|
|
68
72
|
### Parameters
|
|
69
73
|
|
|
70
74
|
#### shape?
|
|
71
75
|
|
|
72
76
|
`ObjectTypeShape`
|
|
73
77
|
|
|
78
|
+
An optional map of property names to expected types.
|
|
79
|
+
|
|
74
80
|
#### additionalChecks?
|
|
75
81
|
|
|
76
82
|
[`TypeCheck`](#../type-aliases/TypeCheck)\<`TypedObject`\>[]
|
|
77
83
|
|
|
84
|
+
Optional extra type-check functions to run after shape validation.
|
|
85
|
+
|
|
78
86
|
### Returns
|
|
79
87
|
|
|
80
88
|
[`TypeCheck`](#../type-aliases/TypeCheck)\<`T`\>
|
|
81
89
|
|
|
90
|
+
A type-guard function for type T.
|
|
91
|
+
|
|
82
92
|
### <a id="ObjectWrapper"></a>ObjectWrapper
|
|
83
93
|
|
|
84
94
|
[**@xylabs/object**](#../../README)
|
|
85
95
|
|
|
86
96
|
***
|
|
87
97
|
|
|
98
|
+
Abstract base class that wraps an object and provides typed access to it.
|
|
99
|
+
|
|
88
100
|
## Extended by
|
|
89
101
|
|
|
90
102
|
- [`ValidatorBase`](#ValidatorBase)
|
|
@@ -141,6 +153,8 @@ get protected stringKeyObj(): StringKeyObject;
|
|
|
141
153
|
|
|
142
154
|
***
|
|
143
155
|
|
|
156
|
+
Abstract base class for validators that wraps a partial object and provides a validation method.
|
|
157
|
+
|
|
144
158
|
## Extends
|
|
145
159
|
|
|
146
160
|
- [`ObjectWrapper`](#ObjectWrapper)\<`Partial`\<`T`\>\>
|
|
@@ -287,6 +301,8 @@ A deep merge function configured for the specified options.
|
|
|
287
301
|
function isObject(value): value is object;
|
|
288
302
|
```
|
|
289
303
|
|
|
304
|
+
Type guard that checks whether a value is a plain object (not null and not an array).
|
|
305
|
+
|
|
290
306
|
### Parameters
|
|
291
307
|
|
|
292
308
|
### value
|
|
@@ -303,6 +319,8 @@ function isObject(value): value is object;
|
|
|
303
319
|
function isObject<T>(value): value is Extract<T, object>;
|
|
304
320
|
```
|
|
305
321
|
|
|
322
|
+
Type guard that checks whether a value is a plain object (not null and not an array).
|
|
323
|
+
|
|
306
324
|
### Type Parameters
|
|
307
325
|
|
|
308
326
|
### T
|
|
@@ -360,6 +378,8 @@ function omitBy<T>(
|
|
|
360
378
|
maxDepth?): Partial<T>;
|
|
361
379
|
```
|
|
362
380
|
|
|
381
|
+
Creates a new object excluding properties that satisfy the predicate, with optional recursive depth.
|
|
382
|
+
|
|
363
383
|
## Type Parameters
|
|
364
384
|
|
|
365
385
|
### T
|
|
@@ -372,18 +392,26 @@ maxDepth?): Partial<T>;
|
|
|
372
392
|
|
|
373
393
|
`T`
|
|
374
394
|
|
|
395
|
+
The source object to omit properties from.
|
|
396
|
+
|
|
375
397
|
### predicate
|
|
376
398
|
|
|
377
399
|
[`OmitByPredicate`](#../type-aliases/OmitByPredicate)
|
|
378
400
|
|
|
401
|
+
A function that returns true for properties to exclude.
|
|
402
|
+
|
|
379
403
|
### maxDepth?
|
|
380
404
|
|
|
381
405
|
`number` = `1`
|
|
382
406
|
|
|
407
|
+
Maximum recursion depth for nested objects.
|
|
408
|
+
|
|
383
409
|
## Returns
|
|
384
410
|
|
|
385
411
|
`Partial`\<`T`\>
|
|
386
412
|
|
|
413
|
+
A partial copy of the object without matching properties.
|
|
414
|
+
|
|
387
415
|
### <a id="omitByPrefix"></a>omitByPrefix
|
|
388
416
|
|
|
389
417
|
[**@xylabs/object**](#../../README)
|
|
@@ -397,6 +425,8 @@ function omitByPrefix<T, P>(
|
|
|
397
425
|
maxDepth?): DeepOmitStartsWith<T, P>;
|
|
398
426
|
```
|
|
399
427
|
|
|
428
|
+
Omits all properties whose keys start with the given prefix, recursively through nested objects.
|
|
429
|
+
|
|
400
430
|
## Type Parameters
|
|
401
431
|
|
|
402
432
|
### T
|
|
@@ -413,18 +443,26 @@ maxDepth?): DeepOmitStartsWith<T, P>;
|
|
|
413
443
|
|
|
414
444
|
`T`
|
|
415
445
|
|
|
446
|
+
The source object.
|
|
447
|
+
|
|
416
448
|
### prefix
|
|
417
449
|
|
|
418
450
|
`P`
|
|
419
451
|
|
|
452
|
+
The string prefix to match keys against.
|
|
453
|
+
|
|
420
454
|
### maxDepth?
|
|
421
455
|
|
|
422
456
|
`number` = `100`
|
|
423
457
|
|
|
458
|
+
Maximum recursion depth.
|
|
459
|
+
|
|
424
460
|
## Returns
|
|
425
461
|
|
|
426
462
|
[`DeepOmitStartsWith`](#../type-aliases/DeepOmitStartsWith)\<`T`, `P`\>
|
|
427
463
|
|
|
464
|
+
A new object without properties that have matching prefixed keys.
|
|
465
|
+
|
|
428
466
|
### <a id="pickBy"></a>pickBy
|
|
429
467
|
|
|
430
468
|
[**@xylabs/object**](#../../README)
|
|
@@ -438,6 +476,8 @@ function pickBy<T>(
|
|
|
438
476
|
maxDepth?): Partial<T>;
|
|
439
477
|
```
|
|
440
478
|
|
|
479
|
+
Creates a new object containing only the properties that satisfy the predicate, with optional recursive depth.
|
|
480
|
+
|
|
441
481
|
## Type Parameters
|
|
442
482
|
|
|
443
483
|
### T
|
|
@@ -450,18 +490,26 @@ maxDepth?): Partial<T>;
|
|
|
450
490
|
|
|
451
491
|
`T`
|
|
452
492
|
|
|
493
|
+
The source object to pick properties from.
|
|
494
|
+
|
|
453
495
|
### predicate
|
|
454
496
|
|
|
455
497
|
[`PickByPredicate`](#../type-aliases/PickByPredicate)
|
|
456
498
|
|
|
499
|
+
A function that returns true for properties to include.
|
|
500
|
+
|
|
457
501
|
### maxDepth?
|
|
458
502
|
|
|
459
503
|
`number` = `1`
|
|
460
504
|
|
|
505
|
+
Maximum recursion depth for nested objects.
|
|
506
|
+
|
|
461
507
|
## Returns
|
|
462
508
|
|
|
463
509
|
`Partial`\<`T`\>
|
|
464
510
|
|
|
511
|
+
A partial copy of the object with only matching properties.
|
|
512
|
+
|
|
465
513
|
### <a id="pickByPrefix"></a>pickByPrefix
|
|
466
514
|
|
|
467
515
|
[**@xylabs/object**](#../../README)
|
|
@@ -475,6 +523,8 @@ function pickByPrefix<T, P>(
|
|
|
475
523
|
maxDepth?): DeepPickStartsWith<T, P>;
|
|
476
524
|
```
|
|
477
525
|
|
|
526
|
+
Picks all properties whose keys start with the given prefix, recursively through nested objects.
|
|
527
|
+
|
|
478
528
|
## Type Parameters
|
|
479
529
|
|
|
480
530
|
### T
|
|
@@ -491,18 +541,26 @@ maxDepth?): DeepPickStartsWith<T, P>;
|
|
|
491
541
|
|
|
492
542
|
`T`
|
|
493
543
|
|
|
544
|
+
The source object.
|
|
545
|
+
|
|
494
546
|
### prefix
|
|
495
547
|
|
|
496
548
|
`P`
|
|
497
549
|
|
|
550
|
+
The string prefix to match keys against.
|
|
551
|
+
|
|
498
552
|
### maxDepth?
|
|
499
553
|
|
|
500
554
|
`number` = `100`
|
|
501
555
|
|
|
556
|
+
Maximum recursion depth.
|
|
557
|
+
|
|
502
558
|
## Returns
|
|
503
559
|
|
|
504
560
|
[`DeepPickStartsWith`](#../type-aliases/DeepPickStartsWith)\<`T`, `P`\>
|
|
505
561
|
|
|
562
|
+
A new object containing only properties with matching prefixed keys.
|
|
563
|
+
|
|
506
564
|
### <a id="removeFields"></a>removeFields
|
|
507
565
|
|
|
508
566
|
[**@xylabs/object**](#../../README)
|
|
@@ -513,6 +571,8 @@ maxDepth?): DeepPickStartsWith<T, P>;
|
|
|
513
571
|
function removeFields<T, K>(obj, fields): Omit<T, K>;
|
|
514
572
|
```
|
|
515
573
|
|
|
574
|
+
Returns a shallow copy of the object with the specified fields removed.
|
|
575
|
+
|
|
516
576
|
## Type Parameters
|
|
517
577
|
|
|
518
578
|
### T
|
|
@@ -529,14 +589,20 @@ function removeFields<T, K>(obj, fields): Omit<T, K>;
|
|
|
529
589
|
|
|
530
590
|
`T`
|
|
531
591
|
|
|
592
|
+
The source object.
|
|
593
|
+
|
|
532
594
|
### fields
|
|
533
595
|
|
|
534
596
|
`K`[]
|
|
535
597
|
|
|
598
|
+
An array of keys to remove.
|
|
599
|
+
|
|
536
600
|
## Returns
|
|
537
601
|
|
|
538
602
|
`Omit`\<`T`, `K`\>
|
|
539
603
|
|
|
604
|
+
A new object without the specified fields.
|
|
605
|
+
|
|
540
606
|
### <a id="toSafeJson"></a>toSafeJson
|
|
541
607
|
|
|
542
608
|
[**@xylabs/object**](#../../README)
|
|
@@ -547,20 +613,28 @@ function removeFields<T, K>(obj, fields): Omit<T, K>;
|
|
|
547
613
|
function toSafeJson(value, maxDepth?): unknown;
|
|
548
614
|
```
|
|
549
615
|
|
|
616
|
+
Converts a value to a JSON-safe representation, handling circular references and non-serializable types.
|
|
617
|
+
|
|
550
618
|
## Parameters
|
|
551
619
|
|
|
552
620
|
### value
|
|
553
621
|
|
|
554
622
|
`unknown`
|
|
555
623
|
|
|
624
|
+
The value to convert.
|
|
625
|
+
|
|
556
626
|
### maxDepth?
|
|
557
627
|
|
|
558
628
|
`number` = `3`
|
|
559
629
|
|
|
630
|
+
Maximum recursion depth.
|
|
631
|
+
|
|
560
632
|
## Returns
|
|
561
633
|
|
|
562
634
|
`unknown`
|
|
563
635
|
|
|
636
|
+
A JSON-safe value.
|
|
637
|
+
|
|
564
638
|
### <a id="toSafeJsonArray"></a>toSafeJsonArray
|
|
565
639
|
|
|
566
640
|
[**@xylabs/object**](#../../README)
|
|
@@ -574,24 +648,34 @@ function toSafeJsonArray(
|
|
|
574
648
|
maxDepth?): unknown[];
|
|
575
649
|
```
|
|
576
650
|
|
|
651
|
+
Converts an array to a JSON-safe array, handling circular references and depth limits.
|
|
652
|
+
|
|
577
653
|
## Parameters
|
|
578
654
|
|
|
579
655
|
### value
|
|
580
656
|
|
|
581
657
|
`unknown`[]
|
|
582
658
|
|
|
659
|
+
The array to convert.
|
|
660
|
+
|
|
583
661
|
### cycleList?
|
|
584
662
|
|
|
585
663
|
`unknown`[]
|
|
586
664
|
|
|
665
|
+
Tracks visited objects to detect circular references.
|
|
666
|
+
|
|
587
667
|
### maxDepth?
|
|
588
668
|
|
|
589
669
|
`number` = `3`
|
|
590
670
|
|
|
671
|
+
Maximum recursion depth before truncating.
|
|
672
|
+
|
|
591
673
|
## Returns
|
|
592
674
|
|
|
593
675
|
`unknown`[]
|
|
594
676
|
|
|
677
|
+
A JSON-safe array representation.
|
|
678
|
+
|
|
595
679
|
### <a id="toSafeJsonObject"></a>toSafeJsonObject
|
|
596
680
|
|
|
597
681
|
[**@xylabs/object**](#../../README)
|
|
@@ -605,24 +689,34 @@ function toSafeJsonObject(
|
|
|
605
689
|
maxDepth?): JsonObject;
|
|
606
690
|
```
|
|
607
691
|
|
|
692
|
+
Converts an object to a JSON-safe object, handling circular references and depth limits.
|
|
693
|
+
|
|
608
694
|
## Parameters
|
|
609
695
|
|
|
610
696
|
### value
|
|
611
697
|
|
|
612
698
|
`object`
|
|
613
699
|
|
|
700
|
+
The object to convert.
|
|
701
|
+
|
|
614
702
|
### cycleList?
|
|
615
703
|
|
|
616
704
|
`unknown`[]
|
|
617
705
|
|
|
706
|
+
Tracks visited objects to detect circular references.
|
|
707
|
+
|
|
618
708
|
### maxDepth?
|
|
619
709
|
|
|
620
710
|
`number` = `3`
|
|
621
711
|
|
|
712
|
+
Maximum recursion depth before truncating.
|
|
713
|
+
|
|
622
714
|
## Returns
|
|
623
715
|
|
|
624
716
|
[`JsonObject`](#../type-aliases/JsonObject)
|
|
625
717
|
|
|
718
|
+
A JSON-safe object representation.
|
|
719
|
+
|
|
626
720
|
### <a id="toSafeJsonString"></a>toSafeJsonString
|
|
627
721
|
|
|
628
722
|
[**@xylabs/object**](#../../README)
|
|
@@ -633,20 +727,28 @@ function toSafeJsonObject(
|
|
|
633
727
|
function toSafeJsonString(value, maxDepth?): string;
|
|
634
728
|
```
|
|
635
729
|
|
|
730
|
+
Converts a value to a pretty-printed JSON string, safely handling circular references and non-JSON types.
|
|
731
|
+
|
|
636
732
|
## Parameters
|
|
637
733
|
|
|
638
734
|
### value
|
|
639
735
|
|
|
640
736
|
`unknown`
|
|
641
737
|
|
|
738
|
+
The value to serialize.
|
|
739
|
+
|
|
642
740
|
### maxDepth?
|
|
643
741
|
|
|
644
742
|
`number` = `3`
|
|
645
743
|
|
|
744
|
+
Maximum recursion depth.
|
|
745
|
+
|
|
646
746
|
## Returns
|
|
647
747
|
|
|
648
748
|
`string`
|
|
649
749
|
|
|
750
|
+
A formatted JSON string.
|
|
751
|
+
|
|
650
752
|
### <a id="toSafeJsonValue"></a>toSafeJsonValue
|
|
651
753
|
|
|
652
754
|
[**@xylabs/object**](#../../README)
|
|
@@ -660,24 +762,35 @@ function toSafeJsonValue(
|
|
|
660
762
|
maxDepth?): unknown;
|
|
661
763
|
```
|
|
662
764
|
|
|
765
|
+
Converts an unknown value to a JSON-safe value, replacing circular references with '[Circular]' and
|
|
766
|
+
non-JSON types with descriptive placeholder strings.
|
|
767
|
+
|
|
663
768
|
## Parameters
|
|
664
769
|
|
|
665
770
|
### value
|
|
666
771
|
|
|
667
772
|
`unknown`
|
|
668
773
|
|
|
774
|
+
The value to convert.
|
|
775
|
+
|
|
669
776
|
### cycleList?
|
|
670
777
|
|
|
671
778
|
`unknown`[]
|
|
672
779
|
|
|
780
|
+
Tracks visited objects to detect circular references.
|
|
781
|
+
|
|
673
782
|
### maxDepth?
|
|
674
783
|
|
|
675
784
|
`number` = `3`
|
|
676
785
|
|
|
786
|
+
Maximum recursion depth before truncating with '[MaxDepth]'.
|
|
787
|
+
|
|
677
788
|
## Returns
|
|
678
789
|
|
|
679
790
|
`unknown`
|
|
680
791
|
|
|
792
|
+
A JSON-safe representation of the value.
|
|
793
|
+
|
|
681
794
|
### interfaces
|
|
682
795
|
|
|
683
796
|
### <a id="ObjectTypeConfig"></a>ObjectTypeConfig
|
|
@@ -686,6 +799,8 @@ function toSafeJsonValue(
|
|
|
686
799
|
|
|
687
800
|
***
|
|
688
801
|
|
|
802
|
+
Configuration options for object type checking.
|
|
803
|
+
|
|
689
804
|
## Extends
|
|
690
805
|
|
|
691
806
|
- [`TypeCheckConfig`](#TypeCheckConfig)
|
|
@@ -708,6 +823,8 @@ optional log: boolean | Logger;
|
|
|
708
823
|
|
|
709
824
|
***
|
|
710
825
|
|
|
826
|
+
Configuration options for type check functions, with optional logging.
|
|
827
|
+
|
|
711
828
|
## Extended by
|
|
712
829
|
|
|
713
830
|
- [`ObjectTypeConfig`](#ObjectTypeConfig)
|
|
@@ -728,6 +845,8 @@ optional log: boolean | Logger;
|
|
|
728
845
|
|
|
729
846
|
***
|
|
730
847
|
|
|
848
|
+
Type check configuration that marks the value as optional, returning undefined on failure.
|
|
849
|
+
|
|
731
850
|
## Extends
|
|
732
851
|
|
|
733
852
|
- [`TypeCheckConfig`](#TypeCheckConfig)
|
|
@@ -758,6 +877,8 @@ required: false;
|
|
|
758
877
|
|
|
759
878
|
***
|
|
760
879
|
|
|
880
|
+
Type check configuration that marks the value as required, causing assertions on failure.
|
|
881
|
+
|
|
761
882
|
## Extends
|
|
762
883
|
|
|
763
884
|
- [`TypeCheckConfig`](#TypeCheckConfig)
|
|
@@ -788,6 +909,8 @@ required: true;
|
|
|
788
909
|
|
|
789
910
|
***
|
|
790
911
|
|
|
912
|
+
Interface for validating objects and returning any errors found.
|
|
913
|
+
|
|
791
914
|
## Type Parameters
|
|
792
915
|
|
|
793
916
|
### T
|
|
@@ -837,6 +960,8 @@ will result in a type that includes the universal set of field names
|
|
|
837
960
|
type AsOptionalTypeFunction<T> = <TType>(value) => TType | undefined;
|
|
838
961
|
```
|
|
839
962
|
|
|
963
|
+
A simplified type-narrowing function that returns T or undefined, without assertion support.
|
|
964
|
+
|
|
840
965
|
## Type Parameters
|
|
841
966
|
|
|
842
967
|
### T
|
|
@@ -876,6 +1001,8 @@ type AsTypeFunction<T> = {
|
|
|
876
1001
|
};
|
|
877
1002
|
```
|
|
878
1003
|
|
|
1004
|
+
A type-narrowing function that attempts to cast a value to T, with optional assertion and configuration overloads.
|
|
1005
|
+
|
|
879
1006
|
## Type Parameters
|
|
880
1007
|
|
|
881
1008
|
### T
|
|
@@ -1058,6 +1185,8 @@ type AsTypeFunction<T> = {
|
|
|
1058
1185
|
type Compare<T> = (a, b) => number;
|
|
1059
1186
|
```
|
|
1060
1187
|
|
|
1188
|
+
A comparator function that returns a negative number if a < b, zero if a == b, and a positive number if a > b.
|
|
1189
|
+
|
|
1061
1190
|
## Type Parameters
|
|
1062
1191
|
|
|
1063
1192
|
### T
|
|
@@ -1088,6 +1217,8 @@ type Compare<T> = (a, b) => number;
|
|
|
1088
1217
|
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
1218
|
```
|
|
1090
1219
|
|
|
1220
|
+
Recursively omits keys that start with the given prefix, including in nested objects and arrays.
|
|
1221
|
+
|
|
1091
1222
|
## Type Parameters
|
|
1092
1223
|
|
|
1093
1224
|
### T
|
|
@@ -1108,6 +1239,8 @@ type DeepOmitStartsWith<T, Prefix> = T extends infer U[] ? DeepOmitStartsWith<U,
|
|
|
1108
1239
|
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
1240
|
```
|
|
1110
1241
|
|
|
1242
|
+
Recursively picks only the keys that start with the given prefix, including in nested objects and arrays.
|
|
1243
|
+
|
|
1111
1244
|
## Type Parameters
|
|
1112
1245
|
|
|
1113
1246
|
### T
|
|
@@ -1128,6 +1261,8 @@ type DeepPickStartsWith<T, Prefix> = T extends infer U[] ? DeepPickStartsWith<U,
|
|
|
1128
1261
|
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
1262
|
```
|
|
1130
1263
|
|
|
1264
|
+
Recursively restricts an object type to only JSON-compatible values, excluding non-serializable types.
|
|
1265
|
+
|
|
1131
1266
|
## Type Parameters
|
|
1132
1267
|
|
|
1133
1268
|
### T
|
|
@@ -1144,6 +1279,8 @@ type DeepRestrictToJson<T> = { [K in keyof T as K extends string ? K : never]: T
|
|
|
1144
1279
|
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
1280
|
```
|
|
1146
1281
|
|
|
1282
|
+
Recursively removes all non-string keys from an object type, including in nested objects and arrays.
|
|
1283
|
+
|
|
1147
1284
|
## Type Parameters
|
|
1148
1285
|
|
|
1149
1286
|
### T
|
|
@@ -1179,6 +1316,8 @@ extended from, which then adds only those additional fields
|
|
|
1179
1316
|
type JsonArray = z.infer<typeof JsonArrayZod>;
|
|
1180
1317
|
```
|
|
1181
1318
|
|
|
1319
|
+
A JSON array containing JSON values.
|
|
1320
|
+
|
|
1182
1321
|
### <a id="JsonObject"></a>JsonObject
|
|
1183
1322
|
|
|
1184
1323
|
[**@xylabs/object**](#../../README)
|
|
@@ -1189,6 +1328,8 @@ type JsonArray = z.infer<typeof JsonArrayZod>;
|
|
|
1189
1328
|
type JsonObject = z.infer<typeof JsonObjectZod>;
|
|
1190
1329
|
```
|
|
1191
1330
|
|
|
1331
|
+
A JSON object with string keys and JSON values.
|
|
1332
|
+
|
|
1192
1333
|
### <a id="JsonValue"></a>JsonValue
|
|
1193
1334
|
|
|
1194
1335
|
[**@xylabs/object**](#../../README)
|
|
@@ -1199,6 +1340,8 @@ type JsonObject = z.infer<typeof JsonObjectZod>;
|
|
|
1199
1340
|
type JsonValue = z.infer<typeof JsonValueZod>;
|
|
1200
1341
|
```
|
|
1201
1342
|
|
|
1343
|
+
A recursive JSON value: string, number, boolean, null, array, or object.
|
|
1344
|
+
|
|
1202
1345
|
### <a id="OmitByPredicate"></a>OmitByPredicate
|
|
1203
1346
|
|
|
1204
1347
|
[**@xylabs/object**](#../../README)
|
|
@@ -1209,6 +1352,8 @@ type JsonValue = z.infer<typeof JsonValueZod>;
|
|
|
1209
1352
|
type OmitByPredicate<T> = (value, key) => boolean;
|
|
1210
1353
|
```
|
|
1211
1354
|
|
|
1355
|
+
A predicate function used to determine which properties to omit from an object.
|
|
1356
|
+
|
|
1212
1357
|
## Type Parameters
|
|
1213
1358
|
|
|
1214
1359
|
### T
|
|
@@ -1239,6 +1384,8 @@ keyof `T`
|
|
|
1239
1384
|
type OmitStartsWith<T, Prefix> = { [K in keyof T as K extends `${Prefix}${string}` ? never : K]: T[K] };
|
|
1240
1385
|
```
|
|
1241
1386
|
|
|
1387
|
+
Omits the keys of T that start with the given prefix.
|
|
1388
|
+
|
|
1242
1389
|
## Type Parameters
|
|
1243
1390
|
|
|
1244
1391
|
### T
|
|
@@ -1259,6 +1406,8 @@ type OmitStartsWith<T, Prefix> = { [K in keyof T as K extends `${Prefix}${string
|
|
|
1259
1406
|
type Optional<T, F> = Omit<T, F> & Partial<Pick<T, F>>;
|
|
1260
1407
|
```
|
|
1261
1408
|
|
|
1409
|
+
Makes the specified fields of T optional while keeping the rest required.
|
|
1410
|
+
|
|
1262
1411
|
## Type Parameters
|
|
1263
1412
|
|
|
1264
1413
|
### T
|
|
@@ -1279,6 +1428,8 @@ type Optional<T, F> = Omit<T, F> & Partial<Pick<T, F>>;
|
|
|
1279
1428
|
type Override<T1, T2> = Omit<T1, keyof T2> & T2;
|
|
1280
1429
|
```
|
|
1281
1430
|
|
|
1431
|
+
Overrides properties of T1 with those from T2.
|
|
1432
|
+
|
|
1282
1433
|
## Type Parameters
|
|
1283
1434
|
|
|
1284
1435
|
### T1
|
|
@@ -1323,6 +1474,8 @@ use Partial<Record<>> instead
|
|
|
1323
1474
|
type PickByPredicate<T> = (value, key) => boolean;
|
|
1324
1475
|
```
|
|
1325
1476
|
|
|
1477
|
+
A predicate function used to determine which properties to pick from an object.
|
|
1478
|
+
|
|
1326
1479
|
## Type Parameters
|
|
1327
1480
|
|
|
1328
1481
|
### T
|
|
@@ -1353,6 +1506,8 @@ keyof `T`
|
|
|
1353
1506
|
type PickStartsWith<T, Prefix> = { [K in keyof T as K extends `${Prefix}${string}` ? K : never]: T[K] };
|
|
1354
1507
|
```
|
|
1355
1508
|
|
|
1509
|
+
Picks only the keys of T that start with the given prefix.
|
|
1510
|
+
|
|
1356
1511
|
## Type Parameters
|
|
1357
1512
|
|
|
1358
1513
|
### T
|
|
@@ -1373,6 +1528,8 @@ type PickStartsWith<T, Prefix> = { [K in keyof T as K extends `${Prefix}${string
|
|
|
1373
1528
|
type Simplify<T> = { [K in keyof T]: T[K] } & object;
|
|
1374
1529
|
```
|
|
1375
1530
|
|
|
1531
|
+
Flattens an intersection or complex mapped type into a single object type for better readability.
|
|
1532
|
+
|
|
1376
1533
|
## Type Parameters
|
|
1377
1534
|
|
|
1378
1535
|
### T
|
|
@@ -1389,6 +1546,8 @@ type Simplify<T> = { [K in keyof T]: T[K] } & object;
|
|
|
1389
1546
|
type StringKeyObject<T> = object;
|
|
1390
1547
|
```
|
|
1391
1548
|
|
|
1549
|
+
An object type with string keys and values of type T.
|
|
1550
|
+
|
|
1392
1551
|
## Type Parameters
|
|
1393
1552
|
|
|
1394
1553
|
### T
|
|
@@ -1411,6 +1570,8 @@ type StringKeyObject<T> = object;
|
|
|
1411
1570
|
type StringOrAlertFunction<T> = string | AssertExMessageFunc<T>;
|
|
1412
1571
|
```
|
|
1413
1572
|
|
|
1573
|
+
A string message or function that produces an assertion error message for a failed type check.
|
|
1574
|
+
|
|
1414
1575
|
## Type Parameters
|
|
1415
1576
|
|
|
1416
1577
|
### T
|
|
@@ -1431,6 +1592,8 @@ type TypeCheck<T> = {
|
|
|
1431
1592
|
};
|
|
1432
1593
|
```
|
|
1433
1594
|
|
|
1595
|
+
A type guard function that checks whether a value conforms to type T, with optional configuration.
|
|
1596
|
+
|
|
1434
1597
|
## Type Parameters
|
|
1435
1598
|
|
|
1436
1599
|
### T
|
|
@@ -1503,6 +1666,8 @@ type TypeCheck<T> = {
|
|
|
1503
1666
|
type WithAdditional<T, TAdditional> = TAdditional extends EmptyObject ? T & TAdditional : T;
|
|
1504
1667
|
```
|
|
1505
1668
|
|
|
1669
|
+
Intersects T with TAdditional if TAdditional is an object, otherwise returns T unchanged.
|
|
1670
|
+
|
|
1506
1671
|
## Type Parameters
|
|
1507
1672
|
|
|
1508
1673
|
### T
|
|
@@ -1525,6 +1690,8 @@ type WithAdditional<T, TAdditional> = TAdditional extends EmptyObject ? T & TAdd
|
|
|
1525
1690
|
const AsObjectFactory: object;
|
|
1526
1691
|
```
|
|
1527
1692
|
|
|
1693
|
+
Factory for creating type-narrowing functions for TypedObject types.
|
|
1694
|
+
|
|
1528
1695
|
## Type Declaration
|
|
1529
1696
|
|
|
1530
1697
|
### create()
|
|
@@ -1593,6 +1760,9 @@ createOptional: <T>(typeCheck) => (value) => T | undefined;
|
|
|
1593
1760
|
const AsTypeFactory: object;
|
|
1594
1761
|
```
|
|
1595
1762
|
|
|
1763
|
+
Factory for creating type-narrowing 'as' functions that cast a value to T or return undefined.
|
|
1764
|
+
Supports optional assertion messages and configuration for required/optional behavior.
|
|
1765
|
+
|
|
1596
1766
|
## Type Declaration
|
|
1597
1767
|
|
|
1598
1768
|
### create()
|
|
@@ -1661,6 +1831,8 @@ createOptional: <T>(typeCheck) => (value) => T | undefined;
|
|
|
1661
1831
|
const JsonObjectZod: ZodRecord<ZodString, ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>>;
|
|
1662
1832
|
```
|
|
1663
1833
|
|
|
1834
|
+
Zod schema for a JSON object with string keys and recursive JSON values.
|
|
1835
|
+
|
|
1664
1836
|
### <a id="asAnyObject"></a>asAnyObject
|
|
1665
1837
|
|
|
1666
1838
|
[**@xylabs/object**](#../../README)
|
|
@@ -1671,6 +1843,8 @@ const JsonObjectZod: ZodRecord<ZodString, ZodType<unknown, unknown, $ZodTypeInte
|
|
|
1671
1843
|
const asAnyObject: AsTypeFunction<AnyObject>;
|
|
1672
1844
|
```
|
|
1673
1845
|
|
|
1846
|
+
Type-narrowing function that casts a value to AnyObject if it is a plain object, or returns undefined.
|
|
1847
|
+
|
|
1674
1848
|
### <a id="asJsonArray"></a>asJsonArray
|
|
1675
1849
|
|
|
1676
1850
|
[**@xylabs/object**](#../../README)
|
|
@@ -1684,6 +1858,8 @@ const asJsonArray: {
|
|
|
1684
1858
|
};
|
|
1685
1859
|
```
|
|
1686
1860
|
|
|
1861
|
+
Casts a value to JsonArray or returns undefined if it does not conform.
|
|
1862
|
+
|
|
1687
1863
|
## Call Signature
|
|
1688
1864
|
|
|
1689
1865
|
```ts
|
|
@@ -1745,6 +1921,8 @@ const asJsonObject: {
|
|
|
1745
1921
|
};
|
|
1746
1922
|
```
|
|
1747
1923
|
|
|
1924
|
+
Casts a value to JsonObject or returns undefined if it does not conform.
|
|
1925
|
+
|
|
1748
1926
|
## Call Signature
|
|
1749
1927
|
|
|
1750
1928
|
```ts
|
|
@@ -1806,6 +1984,8 @@ const asJsonValue: {
|
|
|
1806
1984
|
};
|
|
1807
1985
|
```
|
|
1808
1986
|
|
|
1987
|
+
Casts a value to JsonValue or returns undefined if it does not conform.
|
|
1988
|
+
|
|
1809
1989
|
## Call Signature
|
|
1810
1990
|
|
|
1811
1991
|
```ts
|
|
@@ -1903,6 +2083,8 @@ A new object with the merged properties.
|
|
|
1903
2083
|
const isJsonArray: <T>(value) => value is T & unknown[];
|
|
1904
2084
|
```
|
|
1905
2085
|
|
|
2086
|
+
Type guard that checks if a value is a valid JSON array.
|
|
2087
|
+
|
|
1906
2088
|
## Type Parameters
|
|
1907
2089
|
|
|
1908
2090
|
### T
|
|
@@ -1929,6 +2111,8 @@ const isJsonArray: <T>(value) => value is T & unknown[];
|
|
|
1929
2111
|
const isJsonObject: <T>(value) => value is T & Record<string, unknown>;
|
|
1930
2112
|
```
|
|
1931
2113
|
|
|
2114
|
+
Type guard that checks if a value is a valid JSON object.
|
|
2115
|
+
|
|
1932
2116
|
## Type Parameters
|
|
1933
2117
|
|
|
1934
2118
|
### T
|
|
@@ -1955,6 +2139,8 @@ const isJsonObject: <T>(value) => value is T & Record<string, unknown>;
|
|
|
1955
2139
|
const isJsonValue: <T>(value) => value is T;
|
|
1956
2140
|
```
|
|
1957
2141
|
|
|
2142
|
+
Type guard that checks if a value is a valid JSON value.
|
|
2143
|
+
|
|
1958
2144
|
## Type Parameters
|
|
1959
2145
|
|
|
1960
2146
|
### T
|
|
@@ -1984,6 +2170,8 @@ const toJsonArray: {
|
|
|
1984
2170
|
};
|
|
1985
2171
|
```
|
|
1986
2172
|
|
|
2173
|
+
Parses a value into a JsonArray, throwing if it does not conform.
|
|
2174
|
+
|
|
1987
2175
|
## Call Signature
|
|
1988
2176
|
|
|
1989
2177
|
```ts
|
|
@@ -2045,6 +2233,8 @@ const toJsonObject: {
|
|
|
2045
2233
|
};
|
|
2046
2234
|
```
|
|
2047
2235
|
|
|
2236
|
+
Parses a value into a JsonObject, throwing if it does not conform.
|
|
2237
|
+
|
|
2048
2238
|
## Call Signature
|
|
2049
2239
|
|
|
2050
2240
|
```ts
|
|
@@ -2106,6 +2296,8 @@ const toJsonValue: {
|
|
|
2106
2296
|
};
|
|
2107
2297
|
```
|
|
2108
2298
|
|
|
2299
|
+
Parses a value into a JsonValue, throwing if it does not conform.
|
|
2300
|
+
|
|
2109
2301
|
## Call Signature
|
|
2110
2302
|
|
|
2111
2303
|
```ts
|