@fgv/ts-utils 1.3.1 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/converters.d.ts +12 -12
- package/converters.js +10 -10
- package/index.d.ts +1 -0
- package/index.d.ts.map +1 -1
- package/index.js +4 -2
- package/normalize.d.ts +43 -0
- package/normalize.d.ts.map +1 -0
- package/normalize.js +139 -0
- package/package.json +1 -1
- package/ts-utils.d.ts +0 -2475
- package/tsdoc-metadata.json +0 -11
package/converters.d.ts
CHANGED
|
@@ -159,7 +159,7 @@ export declare const optionalString: Converter<string | undefined, unknown>;
|
|
|
159
159
|
* Helper function to create a {@link Converter} which converts any `string` into an
|
|
160
160
|
* array of `string`, by separating at a supplied delimiter.
|
|
161
161
|
* @remarks
|
|
162
|
-
*
|
|
162
|
+
* Delimiter may also be supplied as context at conversion time.
|
|
163
163
|
* @param delimiter - The delimiter at which to split.
|
|
164
164
|
* @returns A new {@link Converter} returning `string[]`.
|
|
165
165
|
* @public
|
|
@@ -199,7 +199,7 @@ export declare const optionalBoolean: Converter<boolean | undefined, undefined>;
|
|
|
199
199
|
* conversion.
|
|
200
200
|
*
|
|
201
201
|
* @param converters - An ordered list of {@link Converter | converters} to be considered.
|
|
202
|
-
* @param onError - Specifies treatment of
|
|
202
|
+
* @param onError - Specifies treatment of unconvertible elements.
|
|
203
203
|
* @returns A new {@link Converter} which yields a value from the union of the types returned
|
|
204
204
|
* by the wrapped converters.
|
|
205
205
|
* @public
|
|
@@ -211,7 +211,7 @@ export declare function oneOf<T, TC = unknown>(converters: Array<Converter<T, TC
|
|
|
211
211
|
* If `onError` is `'failOnError'` (default), then the entire conversion fails if any element cannot
|
|
212
212
|
* be converted. If `onError` is `'ignoreErrors'`, then failing elements are silently ignored.
|
|
213
213
|
* @param converter - {@link Converter} used to convert each item in the array.
|
|
214
|
-
* @param ignoreErrors - Specifies treatment of
|
|
214
|
+
* @param ignoreErrors - Specifies treatment of unconvertible elements.
|
|
215
215
|
* @returns A {@link Converter} which returns an array of `<T>`.
|
|
216
216
|
* @public
|
|
217
217
|
*/
|
|
@@ -222,7 +222,7 @@ export declare function arrayOf<T, TC = undefined>(converter: Converter<T, TC>,
|
|
|
222
222
|
* If `onError` is `'failOnError'` (default), then the entire conversion fails if any element cannot
|
|
223
223
|
* be converted. If `onError` is `'ignoreErrors'`, then failing elements are silently ignored.
|
|
224
224
|
* @param converter - {@link Converter} used to convert each item in the array
|
|
225
|
-
* @param ignoreErrors - Specifies treatment of
|
|
225
|
+
* @param ignoreErrors - Specifies treatment of unconvertible elements
|
|
226
226
|
* @beta
|
|
227
227
|
*/
|
|
228
228
|
export declare function extendedArrayOf<T, TC = undefined>(label: string, converter: Converter<T, TC>, onError?: OnError): Converter<ExtendedArray<T>, TC>;
|
|
@@ -364,7 +364,7 @@ export declare function element<T, TC = undefined>(index: number, converter: Con
|
|
|
364
364
|
/**
|
|
365
365
|
* A helper function to create a {@link Converter} which extracts and converts an optional element from an array.
|
|
366
366
|
* @remarks
|
|
367
|
-
* The resulting {@link Converter} returns {@link Success} with the converted value if the element
|
|
367
|
+
* The resulting {@link Converter} returns {@link Success} with the converted value if the element exists
|
|
368
368
|
* in the supplied array and can be converted. Returns {@link Success} with value `undefined` if the parameter
|
|
369
369
|
* is an array but the index is out of range. Returns {@link Failure} with a message if the supplied parameter
|
|
370
370
|
* is not an array, if the requested index is negative, or if the element cannot be converted.
|
|
@@ -378,7 +378,7 @@ export declare function optionalElement<T, TC = undefined>(index: number, conver
|
|
|
378
378
|
* A helper function to create a {@link Converter} which extracts and convert a property specified
|
|
379
379
|
* by name from an object.
|
|
380
380
|
* @remarks
|
|
381
|
-
* The resulting {@link Converter} returns {@link Success} with the converted value of the
|
|
381
|
+
* The resulting {@link Converter} returns {@link Success} with the converted value of the corresponding
|
|
382
382
|
* object property if the field exists and can be converted. Returns {@link Failure} with an error message
|
|
383
383
|
* otherwise.
|
|
384
384
|
* @param name - The name of the field to be extracted.
|
|
@@ -390,9 +390,9 @@ export declare function field<T, TC = undefined>(name: string, converter: Conver
|
|
|
390
390
|
* A helper function to create a {@link Converter} which extracts and convert a property specified
|
|
391
391
|
* by name from an object.
|
|
392
392
|
* @remarks
|
|
393
|
-
* The resulting {@link Converter} returns {@link Success} with the converted value of the
|
|
393
|
+
* The resulting {@link Converter} returns {@link Success} with the converted value of the corresponding
|
|
394
394
|
* object property if the field exists and can be converted. Returns {@link Success} with value `undefined`
|
|
395
|
-
* if the supplied
|
|
395
|
+
* if the supplied parameter is an object but the named field is not present. Returns {@link Failure} with
|
|
396
396
|
* an error message otherwise.
|
|
397
397
|
* @param name - The name of the field to be extracted.
|
|
398
398
|
* @param converter - {@link Converter} used to convert the extracted field.
|
|
@@ -490,10 +490,10 @@ export declare class ObjectConverter<T, TC = unknown> extends BaseConverter<T, T
|
|
|
490
490
|
/**
|
|
491
491
|
* Helper function to create a {@link Converters.ObjectConverter | ObjectConverter<T>} which converts an object
|
|
492
492
|
* without changing shape, given a {@link Converters.FieldConverters | FieldConverters<T>} and an optional
|
|
493
|
-
* {@link Converters.ObjectConverterOptions | ObjectConverterOptions<T>} to further refine conversion
|
|
493
|
+
* {@link Converters.ObjectConverterOptions | ObjectConverterOptions<T>} to further refine conversion behavior.
|
|
494
494
|
* @remarks
|
|
495
495
|
* By default, if all of the requested fields exist and can be converted, returns {@link Success}
|
|
496
|
-
* with a new object that contains the converted values under the original key names. If any
|
|
496
|
+
* with a new object that contains the converted values under the original key names. If any required properties
|
|
497
497
|
* do not exist or cannot be converted, the entire conversion fails, returning {@link Failure} with additional
|
|
498
498
|
* error information.
|
|
499
499
|
*
|
|
@@ -514,7 +514,7 @@ export declare function object<T>(properties: FieldConverters<T>, options?: Obje
|
|
|
514
514
|
* optional properties.
|
|
515
515
|
* @remarks
|
|
516
516
|
* By default, if all of the requested fields exist and can be converted, returns {@link Success}
|
|
517
|
-
* with a new object that contains the converted values under the original key names. If any
|
|
517
|
+
* with a new object that contains the converted values under the original key names. If any required properties
|
|
518
518
|
* do not exist or cannot be converted, the entire conversion fails, returning {@link Failure} with additional
|
|
519
519
|
* error information.
|
|
520
520
|
*
|
|
@@ -580,7 +580,7 @@ export declare function strictObject<T>(properties: FieldConverters<T>, optional
|
|
|
580
580
|
*/
|
|
581
581
|
export declare type DiscriminatedObjectConverters<T, TD extends string = string, TC = unknown> = Record<TD, Converter<T, TC>>;
|
|
582
582
|
/**
|
|
583
|
-
* Helper to create a {@link Converter}
|
|
583
|
+
* Helper to create a {@link Converter} which converts a discriminated object without changing shape.
|
|
584
584
|
* @remarks
|
|
585
585
|
* Takes the name of the discriminator property and a
|
|
586
586
|
* {@link Converters.DiscriminatedObjectConverters | string-keyed Record of converters}. During conversion,
|