UNPKG

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.

13 lines (12 loc) 446 B
import { ValidationSkipError } from "../dv/error/validation.SkipError"; import { registerValidation } from "../dv/register.validation"; export function Optional() { return (target, key) => { registerValidation(target, key, (value) => { const isSkipped = value === undefined || value === null || value === ""; if (isSkipped) { throw new ValidationSkipError(); } }); }; }