mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-13 04:00:33 +08:00
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:
13
types/joi/index.d.ts
vendored
13
types/joi/index.d.ts
vendored
@@ -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:
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user