Skip to content
This repository was archived by the owner on Sep 5, 2022. It is now read-only.

Latest commit

 

History

History
53 lines (37 loc) · 946 Bytes

readme.md

File metadata and controls

53 lines (37 loc) · 946 Bytes

validator

Validation operators using class-validator.

Sample usage:

import { IsNumber } from 'class-validator';

class Point {
  @IsNumber()
  x: number;

  @IsNumber()
  y: number;
}

validate$

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

validateOrReject$

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
  }
});