File tree 1 file changed +18
-0
lines changed
1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -219,6 +219,8 @@ if (validator.isValid(data)) doThing(data); // typeof data => `string`
219
219
else throw new Error (' oops!' ); // typeof data => `any`
220
220
```
221
221
222
+ ### TypeToSchemaOptions
223
+
222
224
### union
223
225
Creates a ` Validator ` instance that matches on any one of the given list of possible types.
224
226
@@ -344,6 +346,22 @@ if (result.valid) doThing(result.data);
344
346
else logger .error (... result .errors );
345
347
```
346
348
349
+ ### Validator.withOptions
350
+ Add additional validations to the generated schema.
351
+ While most of these validations are not representable at compile time
352
+ with typescript (` minLength ` of a ` string ` for instance), it can be helpful
353
+ to have the additional validations when validating runtime types.
354
+
355
+ | Param | Description |
356
+ | --- | --- |
357
+ | opts | JSON schema specific options (for instance: ` { maxLength: 2, minLength: 0 } ` ) |
358
+ ###### Example:
359
+ ``` typescript
360
+ const validator = v .string ().withOptions ({ minLength: 1 });
361
+ validator .isValid (' ' ); // false
362
+ validator .isValid (' hi' ); // true
363
+ ```
364
+
347
365
### ValidType
348
366
Returns the encapsulated type of a ` Validator ` type.
349
367
###### Example:
You can’t perform that action at this time.
0 commit comments