UNPKG

1.51 kBTypeScriptView Raw
1/** @module validate */
2import { IValidationRule } from './IValidationRule';
3import { Schema } from './Schema';
4import { ValidationResult } from './ValidationResult';
5/**
6 * Validation rule to combine rules with OR logical operation.
7 * When one of rules returns no errors, than this rule also returns no errors.
8 * When all rules return errors, than the rule returns all errors.
9 *
10 * @see [[IValidationRule]]
11 *
12 * ### Example ###
13 *
14 * let schema = new Schema()
15 * .withRule(new OrRule(
16 * new ValueComparisonRule("LT", 1),
17 * new ValueComparisonRule("GT", 10)
18 * ));
19 *
20 * schema.validate(0); // Result: no error
21 * schema.validate(5); // Result: 5 must be less than 1 or 5 must be more than 10
22 * schema.validate(20); // Result: no error
23 */
24export declare class OrRule implements IValidationRule {
25 private readonly _rules;
26 /**
27 * Creates a new validation rule and sets its values.
28 *
29 * @param rules a list of rules to join with OR operator
30 */
31 constructor(...rules: IValidationRule[]);
32 /**
33 * Validates a given value against this rule.
34 *
35 * @param path a dot notation path to the value.
36 * @param schema a schema this rule is called from
37 * @param value a value to be validated.
38 * @param results a list with validation results to add new results.
39 */
40 validate(path: string, schema: Schema, value: any, results: ValidationResult[]): void;
41}