0.1.0 • Published 3 years ago
validate-parameter v0.1.0
参数校验库
example
import { BaseValidate, IRule, URule } from 'validate-parameter';
// 要校验的对象
interface Param {
type: string;
}
class Test extends BaseValidate<Param> {
rule: { type?: IRule } = {
// 校验对象key
type: {
// 校验规则组成数组
rules: [URule.in('a,b'), this.isB],
},
};
// 自定义校验规则
isB(value: any) {
if (value === 'b') {
return true;
}
return 'value mush be b';
}
}
export default Test;
调用
// 调用校验器
new Test().check(param);