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 (11 loc) • 431 B
text/typescript
import { ValidationError } from "../dv/error/validation.error";
import { registerValidation } from "../dv/register.validation";
export function Finite(message?: string) {
return (target: any, key: string) => {
registerValidation(target, key, (value: any) => {
if (!Number.isFinite(value)) {
throw new ValidationError(message || `Property "${key}" must be a finite number.`);
}
});
};
}