UNPKG

1.53 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 AND logical operation.
7 * When all rules returns no errors, than this rule also returns no errors.
8 * When one of the rules return errors, than the rules returns all errors.
9 *
10 * @see [[IValidationRule]]
11 *
12 * ### Example ###
13 *
14 * let schema = new Schema()
15 * .withRule(new AndRule(
16 * new ValueComparisonRule("GTE", 1),
17 * new ValueComparisonRule("LTE", 10)
18 * ));
19 *
20 * schema.validate(0); // Result: 0 must be greater or equal to 1
21 * schema.validate(5); // Result: no error
22 * schema.validate(20); // Result: 20 must be letter or equal 10
23 */
24export declare class AndRule 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 AND 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}