Validation operators using class-validator
.
Sample usage:
import { IsNumber } from 'class-validator';
class Point {
@IsNumber()
x: number;
@IsNumber()
y: number;
}
Run validation and return a list of errors.
import { IsNumber } from 'class-validator';
import validate$ from '@xpr/operators/validators/validate';
const point = new Point();
point.x = 1;
point.y = 'not a number';
of(input).pipe(validate$(point)).subscribe(console.log);
// ValidationError list or empty list for no errors
Run validation and reject on errors.
import { IsNumber } from 'class-validator';
import validate$ from '@xpr/operators/validators/validate-or-reject';
const point = new Point();
point.x = 1;
point.y = 'not a number';
of(input).pipe(validateOrReject$(point)).subscribe({
error(err) {
// err is a list of ValidationError
}
});