Comparing version 4.3.1 to 4.3.2
{ | ||
"name": "abolish", | ||
"version": "4.3.1", | ||
"version": "4.3.2", | ||
"description": "A javascript object validator.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -313,47 +313,39 @@ "use strict"; | ||
validationResult instanceof AbolishError_1.default) { | ||
let message = $error; | ||
let message; | ||
let data = null; | ||
if (validationResult instanceof AbolishError_1.default) { | ||
message = validationResult.message; | ||
data = validationResult.data; | ||
} | ||
message = $error || message; | ||
if ($errors && $errors[validatorName]) | ||
message = $errors[validatorName]; | ||
if (validationResult instanceof AbolishError_1.default) { | ||
return [ | ||
{ | ||
key: rule, | ||
type: "validator", | ||
validator: validatorName, | ||
message: message || validationResult.message, | ||
data: validationResult.data | ||
}, | ||
{} | ||
]; | ||
} | ||
else if (validationResult === false) { | ||
/** | ||
* Check if option is stringable | ||
* This is required because a rule option could an array or an object | ||
* and these cannot be converted to string | ||
* | ||
* Only strings and numbers can be parsed as :option | ||
*/ | ||
const optionIsStringable = typeof validatorOption === "string" || | ||
typeof validatorOption === "number" || | ||
Array.isArray(validatorOption); | ||
/** | ||
* Replace :param with rule converted to upperCase | ||
* and if option is stringable, replace :option with validatorOption | ||
*/ | ||
message = (message || validator.error).replace(":param", $name ? $name : Functions_1.abolish_StartCase(rule, this)); | ||
if (optionIsStringable) | ||
message = message.replace(":option", validatorOption); | ||
// Return Error using the ValidationResult format | ||
return [ | ||
{ | ||
key: rule, | ||
type: "validator", | ||
validator: validatorName, | ||
message, | ||
data: null | ||
}, | ||
{} | ||
]; | ||
} | ||
/** | ||
* Check if option is stringable | ||
* This is required because a rule option could an array or an object | ||
* and these cannot be converted to string | ||
* | ||
* Only strings and numbers can be parsed as :option | ||
*/ | ||
const optionIsStringable = typeof validatorOption === "string" || | ||
typeof validatorOption === "number" || | ||
Array.isArray(validatorOption); | ||
/** | ||
* Replace :param with rule converted to upperCase | ||
* and if option is stringable, replace :option with validatorOption | ||
*/ | ||
message = (message || validator.error).replace(":param", $name ? $name : Functions_1.abolish_StartCase(rule, this)); | ||
if (optionIsStringable) | ||
message = message.replace(":option", validatorOption); | ||
// Return Error using the ValidationResult format | ||
return [ | ||
{ | ||
key: rule, | ||
type: "validator", | ||
validator: validatorName, | ||
message, | ||
data | ||
}, | ||
{} | ||
]; | ||
} | ||
@@ -431,46 +423,37 @@ } | ||
if (validationResult === false || validationResult instanceof AbolishError_1.default) { | ||
let message = $error; | ||
let message; | ||
let data = null; | ||
if (validationResult instanceof AbolishError_1.default) { | ||
message = validationResult.message; | ||
data = validationResult.data; | ||
} | ||
message = $error || message; | ||
if ($errors && $errors[validatorName]) | ||
message = $errors[validatorName]; | ||
if (validationResult instanceof AbolishError_1.default) { | ||
return resolve([ | ||
{ | ||
key: rule, | ||
type: "validator", | ||
validator: validatorName, | ||
message: message ? message : validationResult.message, | ||
data: validationResult.data | ||
}, | ||
{} | ||
]); | ||
} | ||
else if (validationResult === false) { | ||
/** | ||
* Check if option is stringable | ||
* This is required because a rule option could an array or an object | ||
* and these cannot be converted to string | ||
* | ||
* Only strings and numbers can be parsed as :option | ||
*/ | ||
const optionIsStringable = typeof validatorOption === "string" || | ||
typeof validatorOption === "number"; | ||
/** | ||
* Replace :param with rule converted to upperCase | ||
* and if option is stringable, replace :option with validatorOption | ||
*/ | ||
message = (message || validator.error).replace(":param", $name ? $name : Functions_1.abolish_StartCase(rule, this)); | ||
if (optionIsStringable) | ||
message = message.replace(":option", validatorOption); | ||
// Return Error using the ValidationResult format | ||
return resolve([ | ||
{ | ||
key: rule, | ||
type: "validator", | ||
validator: validatorName, | ||
message, | ||
data: null | ||
}, | ||
{} | ||
]); | ||
} | ||
/** | ||
* Replace :param with rule converted to upperCase | ||
* and if option is stringable, replace :option with validatorOption | ||
*/ | ||
message = (message || validator.error).replace(":param", $name ? $name : Functions_1.abolish_StartCase(rule, this)); | ||
/** | ||
* Check if option is stringable | ||
* This is required because a rule option could an array or an object | ||
* and these cannot be converted to string | ||
* | ||
* Only strings and numbers can be parsed as :option | ||
*/ | ||
const optionIsStringable = typeof validatorOption === "string" || typeof validatorOption === "number"; | ||
if (optionIsStringable) | ||
message = message.replace(":option", validatorOption); | ||
// Return Error using the ValidationResult format | ||
return resolve([ | ||
{ | ||
key: rule, | ||
type: "validator", | ||
validator: validatorName, | ||
message: message, | ||
data | ||
}, | ||
{} | ||
]); | ||
} | ||
@@ -477,0 +460,0 @@ } |
58662
1699