This commit is contained in:
syuilo 2017-03-03 05:52:12 +09:00
parent 8985d55b1b
commit d6af0bb78b
2 changed files with 32 additions and 22 deletions

View file

@ -266,6 +266,30 @@ class StringQuery extends QueryCore {
validate(validator: Validator<string>) {
return super.validate(validator);
}
/**
*
*
* @param pattern
*/
or(pattern: string | string[]) {
if (this.error || this.value === null) return this;
if (typeof pattern == 'string') pattern = pattern.split(' ');
const match = pattern.some(x => x === this.value);
if (!match) this.error = new Error('not-match-pattern');
return this;
}
/**
*
*
* @param pattern
*/
match(pattern: RegExp) {
if (this.error || this.value === null) return this;
if (!pattern.test(this.value)) this.error = new Error('not-match-pattern');
return this;
}
}
class ArrayQuery extends QueryCore {