summaryrefslogtreecommitdiff
path: root/src/api/it.ts
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2017-03-03 05:52:12 +0900
committersyuilo <syuilotan@yahoo.co.jp>2017-03-03 05:52:12 +0900
commitd6af0bb78ba2cd179161139b7ae20655e69a98c1 (patch)
tree4297f0fb94ecd7ffdf796f808708c37a3dcb3679 /src/api/it.ts
parentfix (diff)
downloadsharkey-d6af0bb78ba2cd179161139b7ae20655e69a98c1.tar.gz
sharkey-d6af0bb78ba2cd179161139b7ae20655e69a98c1.tar.bz2
sharkey-d6af0bb78ba2cd179161139b7ae20655e69a98c1.zip
wip
Diffstat (limited to 'src/api/it.ts')
-rw-r--r--src/api/it.ts24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/api/it.ts b/src/api/it.ts
index 5ca8d7dcae..2e6a7a770d 100644
--- a/src/api/it.ts
+++ b/src/api/it.ts
@@ -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 {