@fgv/ts-utils 3.0.0 → 3.0.1-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/dist/ts-utils.d.ts +419 -270
  2. package/dist/tsdoc-metadata.json +1 -1
  3. package/lib/packlets/conversion/baseConverter.d.ts +120 -0
  4. package/lib/packlets/conversion/baseConverter.d.ts.map +1 -0
  5. package/lib/packlets/conversion/baseConverter.js +233 -0
  6. package/lib/packlets/conversion/baseConverter.js.map +1 -0
  7. package/lib/packlets/conversion/converter.d.ts +27 -104
  8. package/lib/packlets/conversion/converter.d.ts.map +1 -1
  9. package/lib/packlets/conversion/converter.js +0 -215
  10. package/lib/packlets/conversion/converter.js.map +1 -1
  11. package/lib/packlets/conversion/converters.d.ts +138 -124
  12. package/lib/packlets/conversion/converters.d.ts.map +1 -1
  13. package/lib/packlets/conversion/converters.js +98 -94
  14. package/lib/packlets/conversion/converters.js.map +1 -1
  15. package/lib/packlets/conversion/defaultingConverter.d.ts +86 -0
  16. package/lib/packlets/conversion/defaultingConverter.d.ts.map +1 -0
  17. package/lib/packlets/conversion/defaultingConverter.js +146 -0
  18. package/lib/packlets/conversion/defaultingConverter.js.map +1 -0
  19. package/lib/packlets/conversion/index.d.ts +2 -0
  20. package/lib/packlets/conversion/index.d.ts.map +1 -1
  21. package/lib/packlets/conversion/index.js +2 -0
  22. package/lib/packlets/conversion/index.js.map +1 -1
  23. package/lib/packlets/conversion/objectConverter.d.ts +5 -3
  24. package/lib/packlets/conversion/objectConverter.d.ts.map +1 -1
  25. package/lib/packlets/conversion/objectConverter.js +2 -2
  26. package/lib/packlets/conversion/objectConverter.js.map +1 -1
  27. package/lib/packlets/conversion/stringConverter.d.ts +2 -1
  28. package/lib/packlets/conversion/stringConverter.d.ts.map +1 -1
  29. package/lib/packlets/conversion/stringConverter.js +2 -2
  30. package/lib/packlets/conversion/stringConverter.js.map +1 -1
  31. package/lib/packlets/validation/genericValidator.d.ts +4 -0
  32. package/lib/packlets/validation/genericValidator.d.ts.map +1 -1
  33. package/lib/packlets/validation/genericValidator.js +10 -0
  34. package/lib/packlets/validation/genericValidator.js.map +1 -1
  35. package/lib/packlets/validation/index.d.ts +1 -1
  36. package/lib/packlets/validation/index.d.ts.map +1 -1
  37. package/lib/packlets/validation/index.js +2 -2
  38. package/lib/packlets/validation/index.js.map +1 -1
  39. package/lib/packlets/validation/validator.d.ts +12 -2
  40. package/lib/packlets/validation/validator.d.ts.map +1 -1
  41. package/lib/packlets/validation/validator.js.map +1 -1
  42. package/package.json +13 -13
@@ -9,16 +9,17 @@
9
9
  export declare function allSucceed<T>(results: Iterable<Result<unknown>>, successValue: T): Result<T>;
10
10
 
11
11
  /**
12
- * A helper function to create a {@link Converter} which converts `unknown` to an array of `<T>`.
12
+ * A helper function to create a {@link Converter | Converter} which converts `unknown` to an array of `<T>`.
13
13
  * @remarks
14
14
  * If `onError` is `'failOnError'` (default), then the entire conversion fails if any element cannot
15
15
  * be converted. If `onError` is `'ignoreErrors'`, then failing elements are silently ignored.
16
- * @param converter - {@link Converter} used to convert each item in the array.
16
+ * @param converter - {@link Converter | Converter} or {@link Validator | Validator} used to convert each
17
+ * item in the array.
17
18
  * @param ignoreErrors - Specifies treatment of unconvertible elements.
18
- * @returns A {@link Converter} which returns an array of `<T>`.
19
+ * @returns A {@link Converter | Converter} which returns an array of `<T>`.
19
20
  * @public
20
21
  */
21
- declare function arrayOf<T, TC = undefined>(converter: Converter<T, TC>, onError?: OnError_2): Converter<T[], TC>;
22
+ declare function arrayOf<T, TC = undefined>(converter: Converter<T, TC> | Validator<T, TC>, onError?: OnError): Converter<T[], TC>;
22
23
 
23
24
  /**
24
25
  * Helper function to create a {@link Validation.Classes.ArrayValidator | ArrayValidator} which
@@ -138,6 +139,10 @@ declare class BaseConverter<T, TC = undefined> implements Converter<T, TC> {
138
139
  * {@inheritdoc Converter.mapConvertItems}
139
140
  */
140
141
  mapConvertItems<TI>(mapConverter: Converter<TI, unknown>): Converter<TI[], TC>;
142
+ /**
143
+ * {@inheritdoc Converter.withAction}
144
+ */
145
+ withAction<TI>(action: (result: Result<T>) => Result<TI>): Converter<TI, TC>;
141
146
  /**
142
147
  * {@inheritdoc Converter.withTypeGuard}
143
148
  */
@@ -154,6 +159,10 @@ declare class BaseConverter<T, TC = undefined> implements Converter<T, TC> {
154
159
  * {@inheritdoc Converter.withBrand}
155
160
  */
156
161
  withBrand<B extends string>(brand: B): Converter<Brand<T, B>, TC>;
162
+ /**
163
+ * {@inheritdoc Converter.withDefault}
164
+ */
165
+ withDefault<TD = T>(defaultValue: TD): DefaultingConverter<T, TD, TC>;
157
166
  /**
158
167
  * @internal
159
168
  */
@@ -169,7 +178,7 @@ declare class BaseConverter<T, TC = undefined> implements Converter<T, TC> {
169
178
  }
170
179
 
171
180
  /**
172
- * A {@link Converter} which converts `unknown` to `boolean`.
181
+ * A {@link Converter | Converter} which converts `unknown` to `boolean`.
173
182
  * @remarks
174
183
  * Boolean values or the case-insensitive strings `'true'` and `'false'` succeed.
175
184
  * Anything else fails.
@@ -279,12 +288,15 @@ declare type ConstraintTrait = FunctionConstraintTrait;
279
288
  declare namespace Conversion {
280
289
  export {
281
290
  Converters,
282
- ConverterTraits,
283
- ConstraintOptions,
284
- Converter,
285
291
  Infer,
286
292
  ConvertedToType,
287
293
  BaseConverter,
294
+ OnError,
295
+ ConverterTraits,
296
+ ConstraintOptions,
297
+ Converter,
298
+ DefaultingConverter,
299
+ GenericDefaultingConverter,
288
300
  ObjectConverterOptions,
289
301
  FieldConverters,
290
302
  ObjectConverter,
@@ -317,7 +329,8 @@ export declare interface Converter<T, TC = undefined> extends ConverterTraits {
317
329
  */
318
330
  readonly brand?: string;
319
331
  /**
320
- * Converts from `unknown` to `<T>`.
332
+ * Converts from `unknown` to `<T>`. For objects and arrays, is guaranteed
333
+ * to return a new entity, with any unrecognized properties removed.
321
334
  * @param from - The `unknown` to be converted
322
335
  * @param context - An optional conversion context of type `<TC>` to be used in
323
336
  * the conversion.
@@ -399,6 +412,13 @@ export declare interface Converter<T, TC = undefined> extends ConverterTraits {
399
412
  * @returns A new {@link Converter} returning `<TI[]>`.
400
413
  */
401
414
  mapConvertItems<TI>(mapConverter: Converter<TI, unknown>): Converter<TI[], TC>;
415
+ /**
416
+ * Creates a {@link Converter | Converter} which applies a supplied action after
417
+ * conversion. The supplied action is always called regardless of success or failure
418
+ * of the base conversion and is allowed to mutate the return type.
419
+ * @param action - The action to be applied.
420
+ */
421
+ withAction<T2>(action: (result: Result<T>) => Result<T2>): Converter<T2, TC>;
402
422
  /**
403
423
  * Creates a {@link Converter} which applies a supplied type guard to the conversion
404
424
  * result.
@@ -438,6 +458,10 @@ export declare interface Converter<T, TC = undefined> extends ConverterTraits {
438
458
  * @returns A {@link Converter} returning `Brand<T, B>`.
439
459
  */
440
460
  withBrand<B extends string>(brand: B): Converter<Brand<T, B>, TC>;
461
+ /**
462
+ * Returns a Converter which always succeeds with a default value rather than failing.
463
+ */
464
+ withDefault<TD = T>(dflt: TD): DefaultingConverter<T, TD, TC>;
441
465
  }
442
466
 
443
467
  declare namespace Converters {
@@ -463,7 +487,7 @@ declare namespace Converters {
463
487
  discriminatedObject,
464
488
  transform,
465
489
  transformObject,
466
- OnError_2 as OnError,
490
+ OnError,
467
491
  string,
468
492
  value,
469
493
  number,
@@ -502,6 +526,23 @@ declare class Crc32Normalizer extends HashingNormalizer {
502
526
  static crc32Hash(parts: string[]): string;
503
527
  }
504
528
 
529
+ /**
530
+ * @public
531
+ */
532
+ declare interface DefaultingConverter<T, TD = T, TC = undefined> extends Converter<T | TD, TC> {
533
+ /**
534
+ * Default value to use if the conversion fails.
535
+ */
536
+ readonly defaultValue: TD;
537
+ /**
538
+ * Convert the supplied `unknown` to `Success<T>` or to the `Success` with the default value
539
+ * if conversion is not possible.
540
+ * @param from - the value to be converted.
541
+ * @param ctx - optional context for the conversion.
542
+ */
543
+ convert(from: unknown, ctx?: TC): Success<T | TD>;
544
+ }
545
+
505
546
  /**
506
547
  * Default {@link Validation.ValidatorTraitValues | validation traits}.
507
548
  * @public
@@ -509,12 +550,12 @@ declare class Crc32Normalizer extends HashingNormalizer {
509
550
  declare const defaultValidatorTraits: ValidatorTraitValues;
510
551
 
511
552
  /**
512
- * Helper function to create a {@link Converter} which converts any `string` into an
553
+ * Helper function to create a {@link Converter | Converter} which converts any `string` into an
513
554
  * array of `string`, by separating at a supplied delimiter.
514
555
  * @remarks
515
556
  * Delimiter may also be supplied as context at conversion time.
516
557
  * @param delimiter - The delimiter at which to split.
517
- * @returns A new {@link Converter} returning `string[]`.
558
+ * @returns A new {@link Converter | Converter} returning `string[]`.
518
559
  * @public
519
560
  */
520
561
  declare function delimitedString(delimiter: string, options?: 'filtered' | 'all'): Converter<string[], string>;
@@ -646,41 +687,41 @@ export declare class DetailedSuccess<T, TD> extends Success<T> {
646
687
  export declare type DetailedSuccessContinuation<T, TD, TN> = (value: T, detail?: TD) => DetailedResult<TN, TD>;
647
688
 
648
689
  /**
649
- * Helper to create a {@link Converter} which converts a discriminated object without changing shape.
690
+ * Helper to create a {@link Converter | Converter} which converts a discriminated object without changing shape.
650
691
  * @remarks
651
692
  * Takes the name of the discriminator property and a
652
- * {@link Converters.DiscriminatedObjectConverters | string-keyed Record of converters}. During conversion,
653
- * the resulting {@link Converter} invokes the converter from `converters` that corresponds to the value of
693
+ * {@link Converters.DiscriminatedObjectConverters | string-keyed Record of converters and validators}. During conversion,
694
+ * the resulting {@link Converter | Converter} invokes the converter from `converters` that corresponds to the value of
654
695
  * the discriminator property in the source object.
655
696
  *
656
697
  * If the source is not an object, the discriminator property is missing, or the discriminator has
657
- * a value not present in the converters, conversion fails and returns {@link Failure} with more information.
698
+ * a value not present in the converters, conversion fails and returns {@link Failure | Failure} with more information.
658
699
  * @param discriminatorProp - Name of the property used to discriminate types.
659
- * @param converters - {@link Converters.DiscriminatedObjectConverters | String-keyed record of converters} to
660
- * invoke, where each key corresponds to a value of the discriminator property.
661
- * @returns A {@link Converter} which converts the corresponding discriminated object.
700
+ * @param converters - {@link Converters.DiscriminatedObjectConverters | String-keyed record of converters and validators}
701
+ * to invoke, where each key corresponds to a value of the discriminator property.
702
+ * @returns A {@link Converter | Converter} which converts the corresponding discriminated object.
662
703
  * @public
663
704
  */
664
705
  declare function discriminatedObject<T, TD extends string = string, TC = unknown>(discriminatorProp: string, converters: DiscriminatedObjectConverters<T, TD>): Converter<T, TC>;
665
706
 
666
707
  /**
667
- * A string-keyed `Record<string, Converter>` which maps specific {@link Converter | converters} to the
668
- * value of a discriminator property.
708
+ * A string-keyed `Record<string, Converter>` which maps specific {@link Converter | converters} or
709
+ * {@link Validator | Validators} to the value of a discriminator property.
669
710
  * @public
670
711
  */
671
- declare type DiscriminatedObjectConverters<T, TD extends string = string, TC = unknown> = Record<TD, Converter<T, TC>>;
712
+ declare type DiscriminatedObjectConverters<T, TD extends string = string, TC = unknown> = Record<TD, Converter<T, TC> | Validator<T, TC>>;
672
713
 
673
714
  /**
674
- * A helper function to create a {@link Converter} which extracts and converts an element from an array.
715
+ * A helper function to create a {@link Converter | Converter} which extracts and converts an element from an array.
675
716
  * @remarks
676
- * The returned {@link Converter} returns {@link Success} with the converted value if the element exists
677
- * in the supplied array and can be converted. Returns {@link Failure} with an error message otherwise.
717
+ * The returned {@link Converter | Converter} returns {@link Success | Success} with the converted value if the element exists
718
+ * in the supplied array and can be converted. Returns {@link Failure | Failure} with an error message otherwise.
678
719
  * @param index - The index of the element to be extracted.
679
- * @param converter - A {@link Converter} used to convert the extracted element.
720
+ * @param converter - A {@link Converter | Converter} or {@link Validator | Validator} for the extracted element.
680
721
  * @returns A {@link Converter | Converter<T>} which extracts the specified element from an array.
681
722
  * @public
682
723
  */
683
- declare function element<T, TC = undefined>(index: number, converter: Converter<T, TC>): Converter<T, TC>;
724
+ declare function element<T, TC = undefined>(index: number, converter: Converter<T, TC> | Validator<T, TC>): Converter<T, TC>;
684
725
 
685
726
  /**
686
727
  * @internal
@@ -688,13 +729,13 @@ declare function element<T, TC = undefined>(index: number, converter: Converter<
688
729
  declare type Entry<T> = [string | number | symbol, T];
689
730
 
690
731
  /**
691
- * Helper function to create a {@link Converter} which converts `unknown` to one of a set of supplied
732
+ * Helper function to create a {@link Converter | Converter} which converts `unknown` to one of a set of supplied
692
733
  * enumerated values. Anything else fails.
693
734
  *
694
735
  * @remarks
695
736
  * Allowed enumerated values can also be supplied as context at conversion time.
696
737
  * @param values - Array of allowed values.
697
- * @returns A new {@link Converter} returning `<T>`.
738
+ * @returns A new {@link Converter | Converter} returning `<T>`.
698
739
  * @public
699
740
  */
700
741
  declare function enumeratedValue<T>(values: T[]): Converter<T, T[]>;
@@ -809,26 +850,27 @@ export declare type FailureContinuation<T> = (message: string) => Result<T>;
809
850
  export declare function failWithDetail<T, TD>(message: string, detail: TD): DetailedFailure<T, TD>;
810
851
 
811
852
  /**
812
- * A helper function to create a {@link Converter} which extracts and convert a property specified
853
+ * A helper function to create a {@link Converter | Converter} which extracts and convert a property specified
813
854
  * by name from an object.
814
855
  * @remarks
815
- * The resulting {@link Converter} returns {@link Success} with the converted value of the corresponding
816
- * object property if the field exists and can be converted. Returns {@link Failure} with an error message
856
+ * The resulting {@link Converter | Converter} returns {@link Success | Success} with the converted value of the corresponding
857
+ * object property if the field exists and can be converted. Returns {@link Failure | Failure} with an error message
817
858
  * otherwise.
818
859
  * @param name - The name of the field to be extracted.
819
- * @param converter - {@link Converter} used to convert the extracted field.
860
+ * @param converter - {@link Converter | Converter} or {@link Validator | Validator} to use for the extracted
861
+ * field.
820
862
  * @public
821
863
  */
822
- declare function field<T, TC = undefined>(name: string, converter: Converter<T, TC>): Converter<T, TC>;
864
+ declare function field<T, TC = undefined>(name: string, converter: Converter<T, TC> | Validator<T, TC>): Converter<T, TC>;
823
865
 
824
866
  /**
825
- * Per-property converters for each of the properties in type T.
867
+ * Per-property converters or validators for each of the properties in type T.
826
868
  * @remarks
827
869
  * Used to construct a {@link Conversion.ObjectConverter | ObjectConverter}
828
870
  * @public
829
871
  */
830
872
  declare type FieldConverters<T, TC = unknown> = {
831
- [key in keyof T]: Converter<T[key], TC>;
873
+ [key in keyof T]: Converter<T[key], TC> | Validator<T[key], TC>;
832
874
  };
833
875
 
834
876
  /**
@@ -848,13 +890,13 @@ export declare type FieldInitializers<T> = {
848
890
  declare type FieldTransformers<TSRC, TDEST, TC = unknown> = {
849
891
  [key in keyof TDEST]: {
850
892
  /**
851
- * The name of the property in the source object to be converter.
893
+ * The name of the property in the source object to be converted.
852
894
  */
853
895
  from: keyof TSRC;
854
896
  /**
855
- * The converter used to convert the property.
897
+ * The converter or validator used to convert the property.
856
898
  */
857
- converter: Converter<TDEST[key], TC>;
899
+ converter: Converter<TDEST[key], TC> | Validator<TDEST[key], TC>;
858
900
  /**
859
901
  * If `true` then a missing source property is ignored. If `false` or omitted
860
902
  * then a missing source property causes an error.
@@ -881,6 +923,90 @@ declare interface FunctionConstraintTrait {
881
923
  type: 'function';
882
924
  }
883
925
 
926
+ /**
927
+ * Generic {@link Conversion.DefaultingConverter | DefaultingConverter}, which wraps another converter
928
+ * to substitute a supplied default value for any errors returned by the inner converter.
929
+ * @public
930
+ */
931
+ declare class GenericDefaultingConverter<T, TD = T, TC = undefined> implements DefaultingConverter<T, TD, TC> {
932
+ private _converter;
933
+ /**
934
+ * {@inheritdoc Conversion.DefaultingConverter.defaultValue}
935
+ */
936
+ defaultValue: TD;
937
+ /**
938
+ * {@inheritdoc Converter.isOptional}
939
+ */
940
+ get isOptional(): boolean;
941
+ /**
942
+ * {@inheritdoc Converter.isOptional}
943
+ */
944
+ get brand(): string | undefined;
945
+ /**
946
+ * Constructs a new {@link Conversion.GenericDefaultingConverter | generic defaulting converter}.
947
+ * @param converter - inner {@link Converter | Converter} used for the base conversion.
948
+ * @param defaultValue - default value to be supplied if the inner conversion fails.
949
+ */
950
+ constructor(converter: Converter<T, TC>, defaultValue: TD);
951
+ /**
952
+ * {@inheritdoc Converter.convert}
953
+ */
954
+ convert(from: unknown, ctx?: TC | undefined): Success<T | TD>;
955
+ /**
956
+ * {@inheritdoc Converter.convertOptional}
957
+ */
958
+ convertOptional(from: unknown, context?: TC | undefined, onError?: ('failOnError' | 'ignoreErrors') | undefined): Result<T | TD | undefined>;
959
+ /**
960
+ * {@inheritdoc Converter.optional}
961
+ */
962
+ optional(onError?: ('failOnError' | 'ignoreErrors') | undefined): Converter<T | TD | undefined, TC>;
963
+ /**
964
+ * {@inheritdoc Converter.map}
965
+ */
966
+ map<T2>(mapper: (from: T | TD) => Result<T2>): Converter<T2, TC>;
967
+ /**
968
+ * {@inheritdoc Converter.mapConvert}
969
+ */
970
+ mapConvert<T2>(mapConverter: Converter<T2, unknown>): Converter<T2, TC>;
971
+ /**
972
+ * {@inheritdoc Converter.mapItems}
973
+ */
974
+ mapItems<TI>(mapper: (from: unknown) => Result<TI>): Converter<TI[], TC>;
975
+ /**
976
+ * {@inheritdoc Converter.mapConvertItems}
977
+ */
978
+ mapConvertItems<TI>(mapConverter: Converter<TI, unknown>): Converter<TI[], TC>;
979
+ /**
980
+ * {@inheritdoc Converter.withAction}
981
+ */
982
+ withAction<T2>(action: (result: Result<T | TD>) => Result<T2>): Converter<T2, TC>;
983
+ /**
984
+ * {@inheritdoc Converter.withTypeGuard}
985
+ */
986
+ withTypeGuard<TI>(guard: (from: unknown) => from is TI, message?: string | undefined): Converter<TI, TC>;
987
+ /**
988
+ * {@inheritdoc Converter.withItemTypeGuard}
989
+ */
990
+ withItemTypeGuard<TI>(guard: (from: unknown) => from is TI, message?: string | undefined): Converter<TI[], TC>;
991
+ /**
992
+ * {@inheritdoc Converter.withConstraint}
993
+ */
994
+ withConstraint(constraint: (val: T | TD) => boolean | Result<T | TD>, options?: ConstraintOptions | undefined): Converter<T | TD, TC>;
995
+ /**
996
+ * {@inheritdoc Converter.withBrand}
997
+ */
998
+ withBrand<B extends string>(brand: B): Converter<Brand<T | TD, B>, TC>;
999
+ /**
1000
+ * Returns a Converter which always succeeds with the supplied default value rather
1001
+ * than failing.
1002
+ *
1003
+ * Note that the supplied default value *overrides* the default value of this
1004
+ * {@link Conversion.DefaultingConverter | DefaultingConverter}.
1005
+ */
1006
+ withDefault<TD2 = T>(dflt: TD2): DefaultingConverter<T, TD2, TC>;
1007
+ private _applyDefault;
1008
+ }
1009
+
884
1010
  /**
885
1011
  * Generic base implementation for an in-place {@link Validation.Validator | Validator}.
886
1012
  * @public
@@ -916,6 +1042,10 @@ declare class GenericValidator<T, TC = undefined> implements Validator<T, TC> {
916
1042
  * {@inheritdoc Validation.Validator.validate}
917
1043
  */
918
1044
  validate(from: unknown, context?: TC): Result<T>;
1045
+ /**
1046
+ * {@inheritdoc Validation.Validator.convert}
1047
+ */
1048
+ convert(from: unknown, context?: TC): Result<T>;
919
1049
  /**
920
1050
  * {@inheritdoc Validation.Validator.validateOptional}
921
1051
  */
@@ -1176,10 +1306,10 @@ export declare interface IResultLogger {
1176
1306
  }
1177
1307
 
1178
1308
  /**
1179
- * Helper function to create a {@link Converter} from a supplied type guard function.
1309
+ * Helper function to create a {@link Converter | Converter} from a supplied type guard function.
1180
1310
  * @param description - a description of the thing to be validated for use in error messages
1181
1311
  * @param guard - a {@link Validation.TypeGuardWithContext} which performs the validation.
1182
- * @returns A new {@link Converter} which validates the values using the supplied type guard
1312
+ * @returns A new {@link Converter | Converter} which validates the values using the supplied type guard
1183
1313
  * and returns them in place.
1184
1314
  * @public
1185
1315
  */
@@ -1207,7 +1337,7 @@ declare function isA_2<T, TC>(description: string, guard: TypeGuardWithContext<T
1207
1337
  export declare function isKeyOf<T extends object>(key: string | number | symbol, item: T): key is keyof T;
1208
1338
 
1209
1339
  /**
1210
- * A {@link Converter} which converts an iso formatted string, a number or a `Date` object to
1340
+ * A {@link Converter | Converter} which converts an iso formatted string, a number or a `Date` object to
1211
1341
  * a `Date` object.
1212
1342
  * @public
1213
1343
  */
@@ -1231,7 +1361,7 @@ declare interface KeyedConverterOptions<T extends string = string, TC = undefine
1231
1361
  * @remarks
1232
1362
  * Can be used to coerce key names to supported values and/or strong types.
1233
1363
  */
1234
- keyConverter?: Converter<T, TC>;
1364
+ keyConverter?: Converter<T, TC> | Validator<T, TC>;
1235
1365
  }
1236
1366
 
1237
1367
  /**
@@ -1241,10 +1371,10 @@ declare interface KeyedConverterOptions<T extends string = string, TC = undefine
1241
1371
  declare type KeyedThingFactory<TS, TD, TK extends string = string> = (key: TK, thing: TS) => Result<TD>;
1242
1372
 
1243
1373
  /**
1244
- * Helper function to create a {@link Converter} which converts `unknown` to some supplied literal value. Succeeds with
1374
+ * Helper function to create a {@link Converter | Converter} which converts `unknown` to some supplied literal value. Succeeds with
1245
1375
  * the supplied value if an identity comparison succeeds, fails otherwise.
1246
1376
  * @param value - The value to be compared.
1247
- * @returns A {@link Converter} which returns the supplied value on success.
1377
+ * @returns A {@link Converter | Converter} which returns the supplied value on success.
1248
1378
  * @public
1249
1379
  */
1250
1380
  declare function literal<T>(value: T): Converter<T, unknown>;
@@ -1326,48 +1456,53 @@ declare type LogLevel = 'detail' | 'info' | 'warning' | 'error' | 'silent';
1326
1456
  export declare function mapFailures<T>(results: Iterable<Result<T>>): string[];
1327
1457
 
1328
1458
  /**
1329
- * A helper function to create a {@link Converter} which converts the `string`-keyed properties
1330
- * using a supplied {@link Converter | Converter<T>} to produce a `Map<string, T>`.
1459
+ * A helper function to create a {@link Converter | Converter} which converts the `string`-keyed properties
1460
+ * using a supplied {@link Converter | Converter<T>} or {@link Validator | Validator<T>} to produce a
1461
+ * `Map<string, T>`.
1331
1462
  * @remarks
1332
1463
  * The resulting converter fails conversion if any element cannot be converted.
1333
- * @param converter - {@link Converter} used to convert each item in the source object.
1334
- * @returns A {@link Converter} which returns `Map<string, T>`.
1464
+ * @param converter - {@link Converter | Converter} | {@link Validator | Validator} used for each item in
1465
+ * the source object.
1466
+ * @returns A {@link Converter | Converter} which returns `Map<string, T>`.
1335
1467
  * {@label WITH_DEFAULT}
1336
1468
  * @public
1337
1469
  */
1338
- declare function mapOf<T, TC = undefined, TK extends string = string>(converter: Converter<T, TC>): Converter<Map<TK, T>, TC>;
1470
+ declare function mapOf<T, TC = undefined, TK extends string = string>(converter: Converter<T, TC> | Validator<T, TC>): Converter<Map<TK, T>, TC>;
1339
1471
 
1340
1472
  /**
1341
- * A helper function to create a {@link Converter} which converts the `string`-keyed properties
1342
- * using a supplied {@link Converter | Converter<T>} to produce a `Map<string, T>` and optionally
1343
- * specified handling of elements that cannot be converted.
1473
+ * A helper function to create a {@link Converter | Converter} which converts the `string`-keyed properties
1474
+ * using a supplied {@link Converter | Converter<T>} or {@link Validator | Validator<T>} to produce a
1475
+ * `Map<string, T>` and specified handling of elements that cannot be converted.
1344
1476
  * @remarks
1345
1477
  * if `onError` is `'fail'` (default), then the entire conversion fails if any key or element
1346
1478
  * cannot be converted. If `onError` is `'ignore'`, failing elements are silently ignored.
1347
- * @param converter - {@link Converter} used to convert each item in the source object.
1348
- * @returns A {@link Converter} which returns `Map<string, T>`.
1479
+ * @param converter - {@link Converter | Converter} or {@link Validator | Validator} used for
1480
+ * each item in the source object.
1481
+ * @returns A {@link Converter | Converter} which returns `Map<string, T>`.
1349
1482
  * {@label WITH_ON_ERROR}
1350
1483
  * @public
1351
1484
  */
1352
- declare function mapOf<T, TC = undefined, TK extends string = string>(converter: Converter<T, TC>, onError: 'fail' | 'ignore'): Converter<Map<TK, T>, TC>;
1485
+ declare function mapOf<T, TC = undefined, TK extends string = string>(converter: Converter<T, TC> | Validator<T, TC>, onError: 'fail' | 'ignore'): Converter<Map<TK, T>, TC>;
1353
1486
 
1354
1487
  /**
1355
- * A helper function to create a {@link Converter} which converts the `string`-keyed properties
1356
- * using a supplied {@link Converter | Converter<T>} to produce a `Map<TK, T>`.
1488
+ * A helper function to create a {@link Converter | Converter} which converts the `string`-keyed properties
1489
+ * using a supplied {@link Converter | Converter<T>} or {@link Validator | Validator<T>} to produce
1490
+ * a `Map<TK,T>`.
1357
1491
  * @remarks
1358
1492
  * If present, the supplied {@link Converters.KeyedConverterOptions | options} can provide a strongly-typed
1359
1493
  * converter for keys and/or control the handling of elements that fail conversion.
1360
- * @param converter - {@link Converter} used to convert each item in the source object.
1494
+ * @param converter - {@link Converter | Converter} or {@link Validator | Validator} used for each item
1495
+ * in the source object.
1361
1496
  * @param options - Optional {@link Converters.KeyedConverterOptions | KeyedConverterOptions<TK, TC>} which
1362
1497
  * supplies a key converter and/or error-handling options.
1363
- * @returns A {@link Converter} which returns `Map<TK, T>`.
1498
+ * @returns A {@link Converter | Converter} which returns `Map<TK,T>`.
1364
1499
  * {@label WITH_OPTIONS}
1365
1500
  * @public
1366
1501
  */
1367
- declare function mapOf<T, TC = undefined, TK extends string = string>(converter: Converter<T, TC>, options: KeyedConverterOptions<TK, TC>): Converter<Map<TK, T>, TC>;
1502
+ declare function mapOf<T, TC = undefined, TK extends string = string>(converter: Converter<T, TC> | Validator<T, TC>, options: KeyedConverterOptions<TK, TC>): Converter<Map<TK, T>, TC>;
1368
1503
 
1369
1504
  /**
1370
- * Helper function to create a {@link Converter} which converts `unknown` to one of a set of supplied enumerated
1505
+ * Helper function to create a {@link Converter | Converter} which converts `unknown` to one of a set of supplied enumerated
1371
1506
  * values, mapping any of multiple supplied values to the enumeration.
1372
1507
  * @remarks
1373
1508
  * Enables mapping of multiple input values to a consistent internal representation (so e.g. `'y'`, `'yes'`,
@@ -1376,7 +1511,7 @@ declare type LogLevel = 'detail' | 'info' | 'warning' | 'error' | 'silent';
1376
1511
  * value, the second is the set of values that map to the result. Tuples are evaluated in the order
1377
1512
  * supplied and are not checked for duplicates.
1378
1513
  * @param message - An optional error message.
1379
- * @returns A {@link Converter} which applies the mapping and yields `<T>` on success.
1514
+ * @returns A {@link Converter | Converter} which applies the mapping and yields `<T>` on success.
1380
1515
  * @public
1381
1516
  */
1382
1517
  declare function mappedEnumeratedValue<T>(map: [T, unknown[]][], message?: string): Converter<T, undefined>;
@@ -1458,7 +1593,7 @@ declare type LogLevel = 'detail' | 'info' | 'warning' | 'error' | 'silent';
1458
1593
  }
1459
1594
 
1460
1595
  /**
1461
- * A {@link Converter} which converts `unknown` to a `number`.
1596
+ * A {@link Converter | Converter} which converts `unknown` to a `number`.
1462
1597
  * @remarks
1463
1598
  * Numbers and strings with a numeric format succeed. Anything else fails.
1464
1599
  * @public
@@ -1511,9 +1646,9 @@ declare type LogLevel = 'detail' | 'info' | 'warning' | 'error' | 'silent';
1511
1646
  * without changing shape, given a {@link Conversion.FieldConverters | FieldConverters<T>} and an optional
1512
1647
  * {@link Conversion.ObjectConverterOptions | ObjectConverterOptions<T>} to further refine conversion behavior.
1513
1648
  * @remarks
1514
- * By default, if all of the requested fields exist and can be converted, returns {@link Success}
1649
+ * By default, if all of the requested fields exist and can be converted, returns {@link Success | Success}
1515
1650
  * with a new object that contains the converted values under the original key names. If any required properties
1516
- * do not exist or cannot be converted, the entire conversion fails, returning {@link Failure} with additional
1651
+ * do not exist or cannot be converted, the entire conversion fails, returning {@link Failure | Failure} with additional
1517
1652
  * error information.
1518
1653
  *
1519
1654
  * Fields that succeed but convert to undefined are omitted from the result object but do not
@@ -1533,9 +1668,9 @@ declare type LogLevel = 'detail' | 'info' | 'warning' | 'error' | 'silent';
1533
1668
  * without changing shape, given a {@link Conversion.FieldConverters | FieldConverters<T>} and a set of
1534
1669
  * optional properties.
1535
1670
  * @remarks
1536
- * By default, if all of the requested fields exist and can be converted, returns {@link Success}
1671
+ * By default, if all of the requested fields exist and can be converted, returns {@link Success | Success}
1537
1672
  * with a new object that contains the converted values under the original key names. If any required properties
1538
- * do not exist or cannot be converted, the entire conversion fails, returning {@link Failure} with additional
1673
+ * do not exist or cannot be converted, the entire conversion fails, returning {@link Failure | Failure} with additional
1539
1674
  * error information.
1540
1675
  *
1541
1676
  * Fields that succeed but convert to undefined are omitted from the result object but do not
@@ -1767,22 +1902,24 @@ declare type LogLevel = 'detail' | 'info' | 'warning' | 'error' | 'silent';
1767
1902
  export declare function omit<T extends object, K extends keyof T>(from: T, exclude: K[]): Omit<T, K>;
1768
1903
 
1769
1904
  /**
1770
- * A helper function to create a {@link Converter} for polymorphic values. Returns a
1771
- * converter which Invokes the wrapped converters in sequence, returning the first successful
1772
- * result. Returns an error if none of the supplied converters can convert the value.
1905
+ * A helper function to create a {@link Converter | Converter} for polymorphic values.
1906
+ * Returns a converter which invokes the wrapped converters in sequence, returning the
1907
+ * first successful result. Returns an error if none of the supplied converters can
1908
+ * convert the value.
1773
1909
  * @remarks
1774
1910
  * If `onError` is `ignoreErrors` (default), then errors from any of the
1775
1911
  * converters are ignored provided that some converter succeeds. If
1776
1912
  * onError is `failOnError`, then an error from any converter fails the entire
1777
1913
  * conversion.
1778
1914
  *
1779
- * @param converters - An ordered list of {@link Converter | converters} to be considered.
1915
+ * @param converters - An ordered list of {@link Converter | converters} or {@link Validator | validators}
1916
+ * to be considered.
1780
1917
  * @param onError - Specifies treatment of unconvertible elements.
1781
- * @returns A new {@link Converter} which yields a value from the union of the types returned
1918
+ * @returns A new {@link Converter | Converter} which yields a value from the union of the types returned
1782
1919
  * by the wrapped converters.
1783
1920
  * @public
1784
1921
  */
1785
- declare function oneOf<T, TC = unknown>(converters: Array<Converter<T, TC>>, onError?: OnError_2): Converter<T, TC>;
1922
+ declare function oneOf<T, TC = unknown>(converters: Array<Converter<T, TC> | Validator<T, TC>>, onError?: OnError): Converter<T, TC>;
1786
1923
 
1787
1924
  /**
1788
1925
  * Helper function to create a {@link Validation.Validator | Validator} which validates one
@@ -1832,51 +1969,49 @@ declare type LogLevel = 'detail' | 'info' | 'warning' | 'error' | 'silent';
1832
1969
  validators: Validator<T, TC>[];
1833
1970
  }
1834
1971
 
1835
- declare type OnError = 'failOnError' | 'ignoreErrors';
1836
-
1837
1972
  /**
1838
1973
  * Action to take on conversion failures.
1839
1974
  * @public
1840
1975
  */
1841
- declare type OnError_2 = 'failOnError' | 'ignoreErrors';
1976
+ declare type OnError = 'failOnError' | 'ignoreErrors';
1842
1977
 
1843
1978
  /**
1844
- * A {@link Converter} to convert an optional `boolean` value.
1979
+ * A {@link Converter | Converter} to convert an optional `boolean` value.
1845
1980
  * @remarks
1846
1981
  * Values of type `boolean` or strings that match (case-insensitive) `'true'`
1847
- * or `'false'` are converted and returned. Anything else returns {@link Success}
1982
+ * or `'false'` are converted and returned. Anything else returns {@link Success | Success}
1848
1983
  * with value `undefined`.
1849
1984
  * @public
1850
1985
  */
1851
1986
  declare const optionalBoolean: Converter<boolean | undefined>;
1852
1987
 
1853
1988
  /**
1854
- * A helper function to create a {@link Converter} which extracts and converts an optional element from an array.
1989
+ * A helper function to create a {@link Converter | Converter} which extracts and converts an optional element from an array.
1855
1990
  * @remarks
1856
- * The resulting {@link Converter} returns {@link Success} with the converted value if the element exists
1857
- * in the supplied array and can be converted. Returns {@link Success} with value `undefined` if the parameter
1858
- * is an array but the index is out of range. Returns {@link Failure} with a message if the supplied parameter
1991
+ * The resulting {@link Converter | Converter} returns {@link Success | Success} with the converted value if the element exists
1992
+ * in the supplied array and can be converted. Returns {@link Success | Success} with value `undefined` if the parameter
1993
+ * is an array but the index is out of range. Returns {@link Failure | Failure} with a message if the supplied parameter
1859
1994
  * is not an array, if the requested index is negative, or if the element cannot be converted.
1860
1995
  * @param index - The index of the element to be extracted.
1861
- * @param converter - A {@link Converter} used to convert the extracted element.
1996
+ * @param converter - A {@link Converter | Converter} or {@link Validator | Validator} used for the extracted element.
1862
1997
  * @returns A {@link Converter | Converter<T>} which extracts the specified element from an array.
1863
1998
  * @public
1864
1999
  */
1865
- declare function optionalElement<T, TC = undefined>(index: number, converter: Converter<T, TC>): Converter<T | undefined, TC>;
2000
+ declare function optionalElement<T, TC = undefined>(index: number, converter: Converter<T, TC> | Validator<T, TC>): Converter<T | undefined, TC>;
1866
2001
 
1867
2002
  /**
1868
- * A helper function to create a {@link Converter} which extracts and convert a property specified
2003
+ * A helper function to create a {@link Converter | Converter} which extracts and convert a property specified
1869
2004
  * by name from an object.
1870
2005
  * @remarks
1871
- * The resulting {@link Converter} returns {@link Success} with the converted value of the corresponding
1872
- * object property if the field exists and can be converted. Returns {@link Success} with value `undefined`
1873
- * if the supplied parameter is an object but the named field is not present. Returns {@link Failure} with
1874
- * an error message otherwise.
2006
+ * The resulting {@link Converter | Converter} returns {@link Success | Success} with the converted value of
2007
+ * the corresponding object property if the field exists and can be converted. Returns {@link Success | Success}
2008
+ * with `undefined` if the supplied parameter is an object but the named field is not present.
2009
+ * Returns {@link Failure | Failure} with an error message otherwise.
1875
2010
  * @param name - The name of the field to be extracted.
1876
- * @param converter - {@link Converter} used to convert the extracted field.
2011
+ * @param converter - {@link Converter | Converter} or {@link Validator | Validator} to use for the extracted field.
1877
2012
  * @public
1878
2013
  */
1879
- declare function optionalField<T, TC = undefined>(name: string, converter: Converter<T, TC>): Converter<T | undefined, TC>;
2014
+ declare function optionalField<T, TC = undefined>(name: string, converter: Converter<T, TC> | Validator<T, TC>): Converter<T | undefined, TC>;
1880
2015
 
1881
2016
  /**
1882
2017
  * Applies a factory method to convert an optional `ReadonlyMap<string, TS>` into a `Record<string, TD>`
@@ -1899,10 +2034,10 @@ declare type LogLevel = 'detail' | 'info' | 'warning' | 'error' | 'silent';
1899
2034
  export declare function optionalMapToRecord<TS, TD, TK extends string = string>(src: ReadonlyMap<TK, TS> | undefined, factory: KeyedThingFactory<TS, TD, TK>): Result<Record<TK, TD> | undefined>;
1900
2035
 
1901
2036
  /**
1902
- * A {@link Converter} which converts an optional `number` value.
2037
+ * A {@link Converter | Converter} which converts an optional `number` value.
1903
2038
  * @remarks
1904
2039
  * Values of type `number` or numeric strings are converted and returned.
1905
- * Anything else returns {@link Success} with value `undefined`.
2040
+ * Anything else returns {@link Success | Success} with value `undefined`.
1906
2041
  * @public
1907
2042
  */
1908
2043
  declare const optionalNumber: Converter<number | undefined>;
@@ -1928,8 +2063,8 @@ declare type LogLevel = 'detail' | 'info' | 'warning' | 'error' | 'silent';
1928
2063
  export declare function optionalRecordToPossiblyEmptyMap<TS, TD, TK extends string = string>(src: Record<TK, TS> | undefined, factory: KeyedThingFactory<TS, TD, TK>): Result<Map<TK, TD>>;
1929
2064
 
1930
2065
  /**
1931
- * A {@link Converter} which converts an optional `string` value. Values of type
1932
- * `string` are returned. Anything else returns {@link Success} with value `undefined`.
2066
+ * A {@link Converter | Converter} which converts an optional `string` value. Values of type
2067
+ * `string` are returned. Anything else returns {@link Success | Success} with value `undefined`.
1933
2068
  * @public
1934
2069
  */
1935
2070
  declare const optionalString: Converter<string | undefined, unknown>;
@@ -2006,45 +2141,49 @@ declare type LogLevel = 'detail' | 'info' | 'warning' | 'error' | 'silent';
2006
2141
  export declare function propagateWithDetail<T, TD>(result: Result<T>, detail: TD, successDetail?: TD): DetailedResult<T, TD>;
2007
2142
 
2008
2143
  /**
2009
- * A helper function to create a {@link Converter} which converts the `string`-keyed properties
2010
- * using a supplied {@link Converter | Converter<T>} to produce a `Record<string, T>`.
2144
+ * A helper function to create a {@link Converter | Converter} which converts the `string`-keyed
2145
+ * properties using a supplied {@link Converter | Converter<T>} or {@link Validator | Validator<T>} to
2146
+ * produce a `Record<string, T>`.
2011
2147
  * @remarks
2012
2148
  * The resulting converter fails conversion if any element cannot be converted.
2013
- * @param converter - {@link Converter} used to convert each item in the source object.
2014
- * @returns A {@link Converter} which returns `Record<string, T>`.
2149
+ * @param converter - {@link Converter | Converter} or {@link Validator | Validator} used for each
2150
+ * item in the source object.
2151
+ * @returns A {@link Converter | Converter} which returns `Record<string, T>`.
2015
2152
  * {@label WITH_DEFAULT}
2016
2153
  * @public
2017
2154
  */
2018
- declare function recordOf<T, TC = undefined, TK extends string = string>(converter: Converter<T, TC>): Converter<Record<TK, T>, TC>;
2155
+ declare function recordOf<T, TC = undefined, TK extends string = string>(converter: Converter<T, TC> | Validator<T, TC>): Converter<Record<TK, T>, TC>;
2019
2156
 
2020
2157
  /**
2021
- * A helper function to create a {@link Converter} which converts the `string`-keyed properties
2022
- * using a supplied {@link Converter | Converter<T>} to produce a `Record<string, T>` and optionally
2023
- * specified handling of elements that cannot be converted.
2158
+ * A helper function to create a {@link Converter | Converter} which converts the `string`-keyed properties
2159
+ * using a supplied {@link Converter | Converter<T>} or {@link Validator | Validator<T>} to produce a
2160
+ * `Record<string, T>` and optionally specified handling of elements that cannot be converted.
2024
2161
  * @remarks
2025
2162
  * if `onError` is `'fail'` (default), then the entire conversion fails if any key or element
2026
2163
  * cannot be converted. If `onError` is `'ignore'`, failing elements are silently ignored.
2027
- * @param converter - {@link Converter} used to convert each item in the source object.
2028
- * @returns A {@link Converter} which returns `Record<string, T>`.
2164
+ * @param converter - {@link Converter | Converter} or {@link Validator | Validator} for each item in
2165
+ * the source object.
2166
+ * @returns A {@link Converter | Converter} which returns `Record<string, T>`.
2029
2167
  * {@label WITH_ON_ERROR}
2030
2168
  * @public
2031
2169
  */
2032
- declare function recordOf<T, TC = undefined, TK extends string = string>(converter: Converter<T, TC>, onError: 'fail' | 'ignore'): Converter<Record<TK, T>, TC>;
2170
+ declare function recordOf<T, TC = undefined, TK extends string = string>(converter: Converter<T, TC> | Validator<T, TC>, onError: 'fail' | 'ignore'): Converter<Record<TK, T>, TC>;
2033
2171
 
2034
2172
  /**
2035
- * A helper function to create a {@link Converter} which converts the `string`-keyed properties
2036
- * using a supplied {@link Converter | Converter<T>} to produce a `Record<TK, T>`.
2173
+ * A helper function to create a {@link Converter | Converter} or which converts the `string`-keyed properties
2174
+ * using a supplied {@link Converter | Converter<T>} or {@link Validator | Validator<T>} to produce a
2175
+ * `Record<TK, T>`.
2037
2176
  * @remarks
2038
2177
  * If present, the supplied {@link Converters.KeyedConverterOptions | options} can provide a strongly-typed
2039
2178
  * converter for keys and/or control the handling of elements that fail conversion.
2040
- * @param converter - {@link Converter} used to convert each item in the source object.
2179
+ * @param converter - {@link Converter | Converter} or {@link Validator | Validator} used for each item in the source object.
2041
2180
  * @param options - Optional {@link Converters.KeyedConverterOptions | KeyedConverterOptions<TK, TC>} which
2042
2181
  * supplies a key converter and/or error-handling options.
2043
- * @returns A {@link Converter} which returns `Record<TK, T>`.
2182
+ * @returns A {@link Converter | Converter} which returns `Record<TK, T>`.
2044
2183
  * {@label WITH_OPTIONS}
2045
2184
  * @public
2046
2185
  */
2047
- declare function recordOf<T, TC = undefined, TK extends string = string>(converter: Converter<T, TC>, options: KeyedConverterOptions<TK, TC>): Converter<Record<TK, T>, TC>;
2186
+ declare function recordOf<T, TC = undefined, TK extends string = string>(converter: Converter<T, TC> | Validator<T, TC>, options: KeyedConverterOptions<TK, TC>): Converter<Record<TK, T>, TC>;
2048
2187
 
2049
2188
  /**
2050
2189
  * Applies a factory method to convert a `Record<TK, TS>` into a `Map<TK, TD>`.
@@ -2138,10 +2277,10 @@ declare type LogLevel = 'detail' | 'info' | 'warning' | 'error' | 'silent';
2138
2277
  declare const string_2: Validator<string>;
2139
2278
 
2140
2279
  /**
2141
- * {@link Converter} to convert an `unknown` to an array of `string`.
2280
+ * {@link Converter | Converter} to convert an `unknown` to an array of `string`.
2142
2281
  * @remarks
2143
- * Returns {@link Success} with the the supplied value if it as an array
2144
- * of strings, returns {@link Failure} with an error message otherwise.
2282
+ * Returns {@link Success | Success} with the the supplied value if it as an array
2283
+ * of strings, returns {@link Failure | Failure} with an error message otherwise.
2145
2284
  * @public
2146
2285
  */
2147
2286
  declare const stringArray: Converter<string[]>;
@@ -2352,19 +2491,19 @@ declare type LogLevel = 'detail' | 'info' | 'warning' | 'error' | 'silent';
2352
2491
  * @remarks
2353
2492
  * Template conversions are applied using `mustache` syntax.
2354
2493
  * @param defaultContext - Optional default context to use for template values.
2355
- * @returns A new {@link Converter} returning `string`.
2494
+ * @returns A new {@link Converter | Converter} returning `string`.
2356
2495
  * @public
2357
2496
  */
2358
2497
  declare function templateString(defaultContext?: unknown): StringConverter<string, unknown>;
2359
2498
 
2360
2499
  /**
2361
- * Helper to create a {@link Converter} which converts a source object to a new object with a
2500
+ * Helper to create a {@link Converter | Converter} which converts a source object to a new object with a
2362
2501
  * different shape.
2363
2502
  *
2364
2503
  * @remarks
2365
- * On successful conversion, the resulting {@link Converter} returns {@link Success} with a new
2504
+ * On successful conversion, the resulting {@link Converter | Converter} returns {@link Success | Success} with a new
2366
2505
  * object, which contains the converted values under the key names specified at initialization time.
2367
- * It returns {@link Failure} with an error message if any fields to be extracted do not exist
2506
+ * It returns {@link Failure | Failure} with an error message if any fields to be extracted do not exist
2368
2507
  * or cannot be converted.
2369
2508
  *
2370
2509
  * Fields that succeed but convert to undefined are omitted from the result object but do not
@@ -2373,29 +2512,29 @@ declare type LogLevel = 'detail' | 'info' | 'warning' | 'error' | 'silent';
2373
2512
  * @param properties - An object with key names that correspond to the target object and an
2374
2513
  * appropriate {@link Conversion.FieldConverters | FieldConverter} which extracts and converts
2375
2514
  * a single filed from the source object.
2376
- * @returns A {@link Converter} with the specified conversion behavior.
2515
+ * @returns A {@link Converter | Converter} with the specified conversion behavior.
2377
2516
  * @public
2378
2517
  */
2379
2518
  declare function transform<T, TC = unknown>(properties: FieldConverters<T, TC>): Converter<T, TC>;
2380
2519
 
2381
2520
  /**
2382
- * Helper to create a strongly-typed {@link Converter} which converts a source object to a
2521
+ * Helper to create a strongly-typed {@link Converter | Converter} which converts a source object to a
2383
2522
  * new object with a different shape.
2384
2523
  *
2385
2524
  * @remarks
2386
- * On successful conversion, the resulting {@link Converter} returns {@link Success} with a new
2525
+ * On successful conversion, the resulting {@link Converter | Converter} returns {@link Success | Success} with a new
2387
2526
  * object, which contains the converted values under the key names specified at initialization time.
2388
2527
  *
2389
- * It returns {@link Failure} with an error message if any fields to be extracted do not exist
2528
+ * It returns {@link Failure | Failure} with an error message if any fields to be extracted do not exist
2390
2529
  * or cannot be converted.
2391
2530
  *
2392
2531
  * @param destinationFields - An object with key names that correspond to the target object and an
2393
2532
  * appropriate {@link Converters.FieldTransformers | FieldTransformers} which specifies the name
2394
- * of the corresponding property in the source object, the converter used to convert the source
2395
- * property and any configuration to guide the conversion.
2533
+ * of the corresponding property in the source object, the converter or validator used for each source
2534
+ * property and any other configuration to guide the conversion.
2396
2535
  * @param options - Options which affect the transformation.
2397
2536
  *
2398
- * @returns A {@link Converter} with the specified conversion behavior.
2537
+ * @returns A {@link Converter | Converter} with the specified conversion behavior.
2399
2538
  * @public
2400
2539
  */
2401
2540
  declare function transformObject<TSRC, TDEST, TC = unknown>(destinationFields: FieldTransformers<TSRC, TDEST, TC>, options?: TransformObjectOptions<TSRC>): Converter<TDEST, TC>;
@@ -2469,19 +2608,19 @@ declare type LogLevel = 'detail' | 'info' | 'warning' | 'error' | 'silent';
2469
2608
  declare type TypeGuardWithContext<T, TC = unknown> = (from: unknown, context?: TC) => from is T;
2470
2609
 
2471
2610
  /**
2472
- * Helper function to create a {@link Converter} from any {@link Validation.Validator}
2611
+ * Helper function to create a {@link Converter | Converter} from any {@link Validation.Validator}
2473
2612
  * @param validator - the validator to be wrapped
2474
- * @returns A {@link Converter} which uses the supplied validator.
2613
+ * @returns A {@link Converter | Converter} which uses the supplied validator.
2475
2614
  * @public
2476
2615
  */
2477
2616
  declare function validated<T, TC = unknown>(validator: Validator<T, TC>): Converter<T, TC>;
2478
2617
 
2479
2618
  /**
2480
- * Helper function to create a {@link Converter} which validates that a supplied value is
2619
+ * Helper function to create a {@link Converter | Converter} which validates that a supplied value is
2481
2620
  * of a type validated by a supplied validator function and returns it.
2482
2621
  * @remarks
2483
- * If `validator` succeeds, this {@link Converter} returns {@link Success} with the supplied
2484
- * value of `from` coerced to type `<T>`. Returns a {@link Failure} with additional
2622
+ * If `validator` succeeds, this {@link Converter | Converter} returns {@link Success | Success} with the supplied
2623
+ * value of `from` coerced to type `<T>`. Returns a {@link Failure | Failure} with additional
2485
2624
  * information otherwise.
2486
2625
  * @param validator - A validator function to determine if the converted value is valid.
2487
2626
  * @param description - A description of the validated type for use in error messages.
@@ -2527,8 +2666,8 @@ declare type LogLevel = 'detail' | 'info' | 'warning' | 'error' | 'silent';
2527
2666
  */
2528
2667
  readonly brand: string | undefined;
2529
2668
  /**
2530
- * Tests to see if a supplied `unknown` value matches this
2531
- * validation.
2669
+ * Tests to see if a supplied `unknown` value matches this validation. All
2670
+ * validate calls are guaranteed to return the entity passed in on Success.
2532
2671
  * @param from - The `unknown` value to be tested.
2533
2672
  * @param context - Optional validation context.
2534
2673
  * @returns {@link Success} with the typed, validated value,
@@ -2536,156 +2675,166 @@ declare type LogLevel = 'detail' | 'info' | 'warning' | 'error' | 'silent';
2536
2675
  */
2537
2676
  validate(from: unknown, context?: TC): Result<T>;
2538
2677
  /**
2539
- * Tests to see if a supplied `unknown` value matches this
2540
- * validation. Accepts `undefined`.
2678
+ * Tests to see if a supplied 'unknown' value matches this validation. In
2679
+ * contrast to {@link Validator.validate | validate}, makes no guarantees
2680
+ * about the identity of the returned value.
2541
2681
  * @param from - The `unknown` value to be tested.
2542
2682
  * @param context - Optional validation context.
2543
- * @returns {@link Success} with the typed, validated value,
2544
- * or {@link Failure} with an error message if validation fails.
2683
+ * @returns {@link Success} with the typed, conversion value,
2684
+ * or {@link Failure} with an error message if conversion fails.
2545
2685
  */
2546
- validateOptional(from: unknown, context?: TC): Result<T | undefined>;
2686
+ convert(from: unknown, context?: TC): Result<T>;
2547
2687
  /**
2548
- * Non-throwing type guard
2549
- * @param from - The value to be tested.
2688
+ * Tests to see if a supplied `unknown` value matches this
2689
+ * validation. Accepts `undefined`.
2690
+ * @param from - The `unknown` value to be tested.
2550
2691
  * @param context - Optional validation context.
2551
- */
2552
- guard(from: unknown, context?: TC): from is T;
2692
+ * @returns {@link Success} with the typed, validated value,
2693
+ * or {@link Failure} with an error message if validation fails.
2694
+ */
2695
+ validateOptional(from: unknown, context?: TC): Result<T | undefined>;
2696
+ /**
2697
+ * Non-throwing type guard
2698
+ * @param from - The value to be tested.
2699
+ * @param context - Optional validation context.
2700
+ */
2701
+ guard(from: unknown, context?: TC): from is T;
2702
+ /**
2703
+ * Creates an {@link Validation.Validator | in-place validator}
2704
+ * which is derived from this one but which also matches `undefined`.
2705
+ */
2706
+ optional(): Validator<T | undefined, TC>;
2707
+ /**
2708
+ * Creates an {@link Validation.Validator | in-place validator}
2709
+ * which is derived from this one but which applies additional constraints.
2710
+ * @param constraint - the constraint to be applied
2711
+ * @param trait - As optional {@link Validation.ConstraintTrait | ConstraintTrait}
2712
+ * to be applied to the resulting {@link Validation.Validator | Validator}.
2713
+ * @returns A new {@link Validation.Validator | Validator}.
2714
+ */
2715
+ withConstraint(constraint: Constraint<T>, trait?: ConstraintTrait): Validator<T, TC>;
2716
+ /**
2717
+ * Creates a new {@link Validation.Validator | in-place validator} which
2718
+ * is derived from this one but which matches a branded result.
2719
+ * @param brand - The brand to be applied.
2720
+ */
2721
+ withBrand<B extends string>(brand: B): Validator<Brand<T, B>, TC>;
2722
+ }
2723
+
2553
2724
  /**
2554
- * Creates an {@link Validation.Validator | in-place validator}
2555
- * which is derived from this one but which also matches `undefined`.
2725
+ * Abstract base helper class for specific validator implementations
2726
+ * @internal
2556
2727
  */
2557
- optional(): Validator<T | undefined, TC>;
2728
+ declare abstract class ValidatorBase<T, TC = undefined> extends GenericValidator<T, TC> {
2729
+ /**
2730
+ * Inner constructor
2731
+ * @param params - Initialization params.
2732
+ * @internal
2733
+ */
2734
+ protected constructor(params: Partial<ValidatorBaseConstructorParams<T, TC>>);
2735
+ /**
2736
+ * Abstract validation method to me implemented by derived classes.
2737
+ * @param from - Value to be converted.
2738
+ * @param context - Optional validation context.
2739
+ * @returns `true` if `from` is valid, {@link Failure | Failure<T>}
2740
+ * with an error message if `from` is invalid.
2741
+ * @internal
2742
+ */
2743
+ protected abstract _validate(from: unknown, context?: TC): boolean | Failure<T>;
2744
+ }
2745
+
2558
2746
  /**
2559
- * Creates an {@link Validation.Validator | in-place validator}
2560
- * which is derived from this one but which applies additional constraints.
2561
- * @param constraint - the constraint to be applied
2562
- * @param trait - As optional {@link Validation.ConstraintTrait | ConstraintTrait}
2563
- * to be applied to the resulting {@link Validation.Validator | Validator}.
2564
- * @returns A new {@link Validation.Validator | Validator}.
2747
+ * @internal
2565
2748
  */
2566
- withConstraint(constraint: Constraint<T>, trait?: ConstraintTrait): Validator<T, TC>;
2749
+ declare type ValidatorBaseConstructorParams<T, TC> = Omit<GenericValidatorConstructorParams<T, TC>, 'validator'>;
2750
+
2567
2751
  /**
2568
- * Creates a new {@link Validation.Validator | in-place validator} which
2569
- * is derived from this one but which matches a branded result.
2570
- * @param brand - The brand to be applied.
2752
+ * Type for a validation function, which validates that a supplied `unknown`
2753
+ * value is a valid value of type `<T>`, possibly as influenced by
2754
+ * an optionally-supplied validation context of type `<TC>`.
2755
+ * @public
2571
2756
  */
2572
- withBrand<B extends string>(brand: B): Validator<Brand<T, B>, TC>;
2573
- }
2574
-
2575
- /**
2576
- * Abstract base helper class for specific validator implementations
2577
- * @internal
2578
- */
2579
- declare abstract class ValidatorBase<T, TC = undefined> extends GenericValidator<T, TC> {
2580
- /**
2581
- * Inner constructor
2582
- * @param params - Initialization params.
2583
- * @internal
2584
- */
2585
- protected constructor(params: Partial<ValidatorBaseConstructorParams<T, TC>>);
2586
- /**
2587
- * Abstract validation method to me implemented by derived classes.
2588
- * @param from - Value to be converted.
2589
- * @param context - Optional validation context.
2590
- * @returns `true` if `from` is valid, {@link Failure | Failure<T>}
2591
- * with an error message if `from` is invalid.
2592
- * @internal
2593
- */
2594
- protected abstract _validate(from: unknown, context?: TC): boolean | Failure<T>;
2595
- }
2757
+ declare type ValidatorFunc<T, TC> = (from: unknown, context?: TC) => boolean | Failure<T>;
2596
2758
 
2597
- /**
2598
- * @internal
2599
- */
2600
- declare type ValidatorBaseConstructorParams<T, TC> = Omit<GenericValidatorConstructorParams<T, TC>, 'validator'>;
2601
-
2602
- /**
2603
- * Type for a validation function, which validates that a supplied `unknown`
2604
- * value is a valid value of type `<T>`, possibly as influenced by
2605
- * an optionally-supplied validation context of type `<TC>`.
2606
- * @public
2607
- */
2608
- declare type ValidatorFunc<T, TC> = (from: unknown, context?: TC) => boolean | Failure<T>;
2759
+ /**
2760
+ * Options that apply to any {@link Validation.Validator | Validator}.
2761
+ * @public
2762
+ */
2763
+ declare interface ValidatorOptions<TC> {
2764
+ defaultContext?: TC;
2765
+ }
2766
+
2767
+ declare namespace Validators {
2768
+ export {
2769
+ object_2 as object,
2770
+ arrayOf_2 as arrayOf,
2771
+ enumeratedValue_2 as enumeratedValue,
2772
+ literal_2 as literal,
2773
+ oneOf_2 as oneOf,
2774
+ isA_2 as isA,
2775
+ string_2 as string,
2776
+ number_2 as number,
2777
+ boolean_2 as boolean
2778
+ }
2779
+ }
2780
+ export { Validators }
2609
2781
 
2610
- /**
2611
- * Options that apply to any {@link Validation.Validator | Validator}.
2612
- * @public
2613
- */
2614
- declare interface ValidatorOptions<TC> {
2615
- defaultContext?: TC;
2616
- }
2617
-
2618
- declare namespace Validators {
2619
- export {
2620
- object_2 as object,
2621
- arrayOf_2 as arrayOf,
2622
- enumeratedValue_2 as enumeratedValue,
2623
- literal_2 as literal,
2624
- oneOf_2 as oneOf,
2625
- isA_2 as isA,
2626
- string_2 as string,
2627
- number_2 as number,
2628
- boolean_2 as boolean
2629
- }
2630
- }
2631
- export { Validators }
2782
+ /**
2783
+ * Generic implementation of {@link Validation.ValidatorTraitValues | ValidatorTraitValues}.
2784
+ * @public
2785
+ */
2786
+ declare class ValidatorTraits implements ValidatorTraitValues {
2787
+ /**
2788
+ * {@inheritdoc Validation.ValidatorTraitValues.isOptional}
2789
+ */
2790
+ readonly isOptional: boolean;
2791
+ /**
2792
+ * {@inheritdoc Validation.ValidatorTraitValues.brand}
2793
+ */
2794
+ readonly brand?: string;
2795
+ /**
2796
+ * {@inheritdoc Validation.ValidatorTraitValues.constraints}
2797
+ */
2798
+ readonly constraints: ConstraintTrait[];
2799
+ /**
2800
+ * Constructs a new {@link Validation.ValidatorTraits | ValidatorTraits} optionally
2801
+ * initialized with the supplied base and initial values.
2802
+ * @remarks
2803
+ * Initial values take priority over base values, which fall back to the global default values.
2804
+ * @param init - Partial initial values to be set in the resulting {@link Validation.Validator | Validator}.
2805
+ * @param base - Base values to be used when no initial values are present.
2806
+ */
2807
+ constructor(init?: Partial<ValidatorTraitValues>, base?: ValidatorTraitValues);
2808
+ }
2632
2809
 
2633
- /**
2634
- * Generic implementation of {@link Validation.ValidatorTraitValues | ValidatorTraitValues}.
2635
- * @public
2636
- */
2637
- declare class ValidatorTraits implements ValidatorTraitValues {
2638
- /**
2639
- * {@inheritdoc Validation.ValidatorTraitValues.isOptional}
2640
- */
2641
- readonly isOptional: boolean;
2642
- /**
2643
- * {@inheritdoc Validation.ValidatorTraitValues.brand}
2644
- */
2645
- readonly brand?: string;
2646
- /**
2647
- * {@inheritdoc Validation.ValidatorTraitValues.constraints}
2648
- */
2649
- readonly constraints: ConstraintTrait[];
2650
- /**
2651
- * Constructs a new {@link Validation.ValidatorTraits | ValidatorTraits} optionally
2652
- * initialized with the supplied base and initial values.
2653
- * @remarks
2654
- * Initial values take priority over base values, which fall back to the global default values.
2655
- * @param init - Partial initial values to be set in the resulting {@link Validation.Validator | Validator}.
2656
- * @param base - Base values to be used when no initial values are present.
2657
- */
2658
- constructor(init?: Partial<ValidatorTraitValues>, base?: ValidatorTraitValues);
2659
- }
2810
+ /**
2811
+ * Interface describing the supported validator traits.
2812
+ * @public
2813
+ */
2814
+ declare interface ValidatorTraitValues {
2815
+ /**
2816
+ * Indicates whether the validator accepts `undefined` as
2817
+ * a valid value.
2818
+ */
2819
+ readonly isOptional: boolean;
2820
+ /**
2821
+ * If present, indicates that the result will be branded
2822
+ * with the corresponding brand.
2823
+ */
2824
+ readonly brand?: string;
2825
+ /**
2826
+ * Zero or more additional {@link Validation.ConstraintTrait | ConstraintTrait}s
2827
+ * describing additional constraints applied by this {@link Validation.Validator | Validator}.
2828
+ */
2829
+ readonly constraints: ConstraintTrait[];
2830
+ }
2660
2831
 
2661
- /**
2662
- * Interface describing the supported validator traits.
2663
- * @public
2664
- */
2665
- declare interface ValidatorTraitValues {
2666
- /**
2667
- * Indicates whether the validator accepts `undefined` as
2668
- * a valid value.
2669
- */
2670
- readonly isOptional: boolean;
2671
- /**
2672
- * If present, indicates that the result will be branded
2673
- * with the corresponding brand.
2674
- */
2675
- readonly brand?: string;
2676
- /**
2677
- * Zero or more additional {@link Validation.ConstraintTrait | ConstraintTrait}s
2678
- * describing additional constraints applied by this {@link Validation.Validator | Validator}.
2679
- */
2680
- readonly constraints: ConstraintTrait[];
2681
- }
2832
+ /**
2833
+ * Deprecated alias for @see literal
2834
+ * @param value - The value to be compared.
2835
+ * @deprecated Use {@link Converters.literal} instead.
2836
+ * @internal
2837
+ */
2838
+ declare const value: typeof literal;
2682
2839
 
2683
- /**
2684
- * Deprecated alias for @see literal
2685
- * @param value - The value to be compared.
2686
- * @deprecated Use {@link Converters.literal} instead.
2687
- * @internal
2688
- */
2689
- declare const value: typeof literal;
2690
-
2691
- export { }
2840
+ export { }