Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function Rule(name, oper) {
var self = this;
self.name = name;
if (oper instanceof RegExp) {
self.operator = function (opts, commit) {
var rslt = oper.test($(opts.element).val());
commit(rslt ? null : opts.rule, _getMsg(opts, rslt));
};
} else if ($.isFunction(oper)) {
self.operator = function (opts, commit) {
var rslt = oper.call(this, opts, function (result, msg) {
commit(result ? null : opts.rule, msg || _getMsg(opts, result));
});
// 当是异步判断时, 返回 undefined, 则执行上面的 commit
if (rslt !== undefined) {
commit(rslt ? null : opts.rule, _getMsg(opts, rslt));
}
};
} else {
throw new Error('The second argument must be a regexp or a function.');
}
}
setter: function (val) {
return $.isFunction(val) ? val : utils.helper(val);
}
};
setup: function () {
if (!this.get('display') && $.isFunction(this.get('displayHelper'))) {
this.set('display', this.get('displayHelper')(this));
}
},