add an alternative type of a param in Joi's method

This commit is contained in:
b-galazka
2018-03-15 15:52:04 +01:00
parent 52bde4982f
commit f44d70afae
2 changed files with 19 additions and 2 deletions

13
types/joi/index.d.ts vendored
View File

@@ -164,6 +164,11 @@ export interface IPOptions {
cidr?: string
}
export interface StringRegexOptions {
name?: string;
invert?: boolean;
}
export interface JoiObject {
isJoi: boolean;
}
@@ -551,9 +556,13 @@ export interface StringSchema extends AnySchema {
/**
* Defines a regular expression rule.
* @param pattern - a regular expression object the string value must match against.
* @param name - optional name for patterns (useful with multiple patterns). Defaults to 'required'.
* @param options - optional, can be:
* Name for patterns (useful with multiple patterns). Defaults to 'required'.
* An optional configuration object with the following supported properties:
* name - optional pattern name.
* invert - optional boolean flag. Defaults to false behavior. If specified as true, the provided pattern will be disallowed instead of required.
*/
regex(pattern: RegExp, name?: string): this;
regex(pattern: RegExp, options?: string | StringRegexOptions): this;
/**
* Replace characters matching the given pattern with the specified replacement string where:

View File

@@ -135,6 +135,13 @@ refOpts = { contextPrefix: str };
// --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
let stringRegexOpts: Joi.StringRegexOptions = null;
stringRegexOpts = { name: str };
stringRegexOpts = { invert: bool };
// --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
let validErr: Joi.ValidationError = null;
let validErrItem: Joi.ValidationErrorItem;
let validErrFunc: Joi.ValidationErrorFunction;
@@ -764,6 +771,7 @@ strSchema = strSchema.length(ref);
strSchema = strSchema.length(ref, str);
strSchema = strSchema.regex(exp);
strSchema = strSchema.regex(exp, str);
strSchema = strSchema.regex(exp, stringRegexOpts);
strSchema = strSchema.replace(exp, str);
strSchema = strSchema.replace(str, str);
strSchema = strSchema.alphanum();