|
@@ -2,10 +2,10 @@
|
|
|
type errMessage = string | undefined;
|
|
|
|
|
|
/**
|
|
|
- * 检测是否通过
|
|
|
- * code_pass 通过
|
|
|
- * code_notPass 不通过
|
|
|
- * code_notMatch 未匹配到规则
|
|
|
+ * 规则匹配结果
|
|
|
+ * @property code_pass 验证通过
|
|
|
+ * @property code_notPass 验证未通过
|
|
|
+ * @property code_notMatch 未匹配到规则
|
|
|
*/
|
|
|
enum checkCode {
|
|
|
code_pass = 1,
|
|
@@ -13,13 +13,21 @@ enum checkCode {
|
|
|
code_notMatch = 3
|
|
|
}
|
|
|
|
|
|
-/**
|
|
|
- * @description 验证字段
|
|
|
- * @param {Array<string | RegExp>} checkFields 用于匹配的字段字符或者正则
|
|
|
- */
|
|
|
type checkFields = Array<string | RegExp>;
|
|
|
|
|
|
-
|
|
|
+/**
|
|
|
+ * 验证规则
|
|
|
+ * @property [type] 类型
|
|
|
+ * @property [min] 最小值
|
|
|
+ * @property max 最大值
|
|
|
+ * @property length 长度
|
|
|
+ * @property regex 正则表达式
|
|
|
+ * @property message 错误信息
|
|
|
+ * @property require 是否必填
|
|
|
+ * @property minLength 最小长度
|
|
|
+ * @property maxLength 最大长度
|
|
|
+ * @property validator 自定义验证函数
|
|
|
+ */
|
|
|
type checkRule = {
|
|
|
type?: string;
|
|
|
min?: number;
|
|
@@ -34,13 +42,23 @@ type checkRule = {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
+/**
|
|
|
+ * 规则项
|
|
|
+ * @property name 规则名称
|
|
|
+ * @property checkFields 验证匹配字段
|
|
|
+ * @property rules 验证规则
|
|
|
+ */
|
|
|
type ruleItem = {
|
|
|
name: string,
|
|
|
checkFields: checkFields;
|
|
|
rules: Array<validatorFunction | checkRule>;
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * 验证函数
|
|
|
+ * @param value 要验证的值
|
|
|
+ * @returns {string | null} 错误信息
|
|
|
+ */
|
|
|
type validatorFunction = {
|
|
|
(value: any): string | null
|
|
|
}
|