UNPKG

1.37 kBTypeScriptView Raw
1/** @module validate */
2import { IValidationRule } from './IValidationRule';
3import { Schema } from './Schema';
4import { ValidationResult } from './ValidationResult';
5/**
6 * Validation rule that compares value to a constant.
7 *
8 * @see [[IValidationRule]]
9 *
10 * ### Example ###
11 *
12 * let schema = new Schema()
13 * .withRule(new ValueComparisonRule("EQ", 1));
14 *
15 * schema.validate(1); // Result: no errors
16 * schema.validate(2); // Result: 2 is not equal to 1
17 */
18export declare class ValueComparisonRule implements IValidationRule {
19 private readonly _value;
20 private readonly _operation;
21 /**
22 * Creates a new validation rule and sets its values.
23 *
24 * @param operation a comparison operation: "==" ("=", "EQ"), "!= " ("<>", "NE"); "<"/">" ("LT"/"GT"), "<="/">=" ("LE"/"GE"); "LIKE".
25 * @param value a constant value to compare to
26 */
27 constructor(operation: string, value: any);
28 /**
29 * Validates a given value against this rule.
30 *
31 * @param path a dot notation path to the value.
32 * @param schema a schema this rule is called from
33 * @param value a value to be validated.
34 * @param results a list with validation results to add new results.
35 */
36 validate(path: string, schema: Schema, value: any, results: ValidationResult[]): void;
37}