UNPKG

1.21 kBTypeScriptView Raw
1/** @module validate */
2import { IValidationRule } from './IValidationRule';
3import { Schema } from './Schema';
4import { ValidationResult } from './ValidationResult';
5/**
6 * Validation rule to check that value is included into the list of constants.
7 *
8 * @see [[IValidationRule]]
9 *
10 * ### Example ###
11 *
12 * let schema = new Schema()
13 * .withRule(new IncludedRule(1, 2, 3));
14 *
15 * schema.validate(2); // Result: no errors
16 * schema.validate(10); // Result: 10 must be one of 1, 2, 3
17 */
18export declare class IncludedRule implements IValidationRule {
19 private readonly _values;
20 /**
21 * Creates a new validation rule and sets its values.
22 *
23 * @param values a list of constants that value must be included to
24 */
25 constructor(...values: any[]);
26 /**
27 * Validates a given value against this rule.
28 *
29 * @param path a dot notation path to the value.
30 * @param schema a schema this rule is called from
31 * @param value a value to be validated.
32 * @param results a list with validation results to add new results.
33 */
34 validate(path: string, schema: Schema, value: any, results: ValidationResult[]): void;
35}