decoval
Version:
DecoVal is a decorator-driven validation pattern that allows you to add validation rules directly to the properties of TypeScript classes, simplifying data control and increasing code readability and reusability.
20 lines (19 loc) • 672 B
JavaScript
export function skipValidation(value, options) {
const isUndefined = typeof value === "undefined";
const isNull = value === null;
const isEmpty = value === "";
// Se o valor for undefined e a opção optional for true, ignora a validação
if (options.optional && isUndefined) {
return true;
}
// Se o valor for null e a opção null for true, ignora a validação
if (options.null && isNull) {
return true;
}
// Se o valor for vazio e a opção empty for true, ignora a validação
if (options.empty && isEmpty) {
return true;
}
// Caso contrário, não ignora a validação
return false;
}