Merge pull request #24315 from b-galazka/master

[@types/joi] Add an alternative type of a param in regex method.
This commit is contained in:
Mine Starks
2018-03-21 09:04:25 -07:00
committed by GitHub
2 changed files with 19 additions and 2 deletions

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

@@ -165,6 +165,11 @@ export interface IPOptions {
cidr?: string
}
export interface StringRegexOptions {
name?: string;
invert?: boolean;
}
export interface JoiObject {
isJoi: boolean;
}
@@ -552,9 +557,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();