Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function _getMsg(opts, b) {
var ruleName = opts.rule;
var msgtpl;
if (opts.message) { // user specifies a message
if ($.isPlainObject(opts.message)) {
msgtpl = opts.message[b ? 'success' : 'failure'];
// if user's message is undefined,use default
typeof msgtpl === 'undefined' && (msgtpl = messages[ruleName][b ? 'success' : 'failure']);
} else {//just string
msgtpl = b ? '' : opts.message
}
} else { // use default
msgtpl = messages[ruleName][b ? 'success' : 'failure'];
}
return msgtpl ? compileTpl(opts, msgtpl) : msgtpl;
}
function setMessage(name, msg) {
if ($.isPlainObject(name)) {
$.each(name, function (i, v) {
setMessage(i, v);
});
return this;
}
if ($.isPlainObject(msg)) {
messages[name] = msg;
} else {
messages[name] = {
failure: msg
};
}
return this;
}
function setMessage(name, msg) {
if ($.isPlainObject(name)) {
$.each(name, function (i, v) {
setMessage(i, v);
});
return this;
}
if ($.isPlainObject(msg)) {
messages[name] = msg;
} else {
messages[name] = {
failure: msg
};
}
return this;
}
function addRule(name, operator, message) {
if ($.isPlainObject(name)) {
$.each(name, function (i, v) {
if ($.isArray(v))
addRule(i, v[0], v[1]);
else
addRule(i, v);
});
return this;
}
if (operator instanceof Rule) {
rules[name] = new Rule(name, operator.operator);
} else {
rules[name] = new Rule(name, operator);
}
setMessage(name, message);