lakmus
Version:
Fluent validation.
161 lines (160 loc) • 7.85 kB
TypeScript
import { ValidationRule } from "./validation-rule";
import { Validator } from "./validator";
import { PropertyValidator } from "./validators/property-validator";
/** Helper class that can be used to configure a validation rule. */
export declare class ValidationRuleConfigurator<TInstance, TProperty> {
private _rule;
/**
* Initializes a new instance of the ValidationRuleConfigurator class.
* @param rule Rule to be configured.
*/
constructor(rule: ValidationRule<TInstance, any>);
/**
* Сan be used to specify condition that control when the rule should execute.
* @param predicate Condition.
*/
when(predicate: (instance: TInstance) => boolean): ValidationRuleConfigurator<TInstance, TProperty>;
/**
* Specifies a custom error message to use if validation fails.
* @param errorMessage The error message to use.
*/
withMessage(errorMessage: string): ValidationRuleConfigurator<TInstance, TProperty>;
/**
* Specifies a custom error message resource to use when validation fails.
* @param resourceName The resource to use.
*/
withLocalizedMessage(resourceName: string): ValidationRuleConfigurator<TInstance, TProperty>;
/**
* Specifies a custom property name to use within the error message.
* @param name Custom property name to use.
*/
withName(name: string): ValidationRuleConfigurator<TInstance, TProperty>;
/**
* Defines a custom validator on the current rule builder.
* @param validator Property or object validator instance.
*/
setValidator(validator: Validator<TProperty> | PropertyValidator): ValidationRuleConfigurator<TInstance, TProperty>;
/**
* Defines a custom collection validator on the current rule builder.
* @param validator Object validator to apply.
*/
setCollectionValidator(validator: Validator<any>): ValidationRuleConfigurator<TInstance, TProperty>;
/**
* Defines a 'credit card' validator on the current rule.
* Validation will fail if the property is not a credit card number.
*/
creditCard(): ValidationRuleConfigurator<TInstance, TProperty>;
/**
* Defines an 'email' validator on the current rule.
* Validation will fail if the property is not an email address.
*/
email(): ValidationRuleConfigurator<TInstance, TProperty>;
/**
* Defines an 'empty' validator on the current rule.
* Validation will fail if the property is not null, not undefined, not whitespace, not zero and not an empty array.
*/
empty(): ValidationRuleConfigurator<TInstance, TProperty>;
/**
* Defines an 'equal' validator on the current rule.
* Validation will fail if the specified value is not equal to the value of the property.
*/
equal(valueToCompare: any): ValidationRuleConfigurator<TInstance, TProperty>;
/**
* Defines an 'exact length' validator on the current rule.
* Validation will fail if the length of the string is not equal to the length specified.
* @param length Exact length.
*/
exactLength(length: number): ValidationRuleConfigurator<TInstance, TProperty>;
/**
* Defines a 'exclusive between' validator on the current rule.
* Validation will fail if the value of the property is outside of the specifed range. The range is exclusive.
* @param min Minimum value.
* @param max Maximum value.
*/
exclusiveBetween(min: number, max: number): ValidationRuleConfigurator<TInstance, TProperty>;
/**
* Defines a 'greater than' validator on the current rule.
* The validation will fail if the property value is less than or equal to the specified value.
* @param min Minimum value.
*/
greaterThan(min: number): ValidationRuleConfigurator<TInstance, TProperty>;
/**
* Defines a 'greater than or equal' validator on the current rule.
* The validation will fail if the property value is less than the specified value.
* @param min Minimum value.
*/
greaterThanOrEqual(min: number): ValidationRuleConfigurator<TInstance, TProperty>;
/**
* Defines a 'inclusive between' validator on the current rule.
* Validation will fail if the value of the property is outside of the specifed range. The range is inclusive.
* @param min Minimum value.
* @param max Maximum value.
*/
inclusiveBetween(min: number, max: number): ValidationRuleConfigurator<TInstance, TProperty>;
/**
* Defines a 'less than' validator on the current rule.
* The validation will fail if the property value is more than or equal to the specified value.
* @param max Maximum value.
*/
lessThan(max: number): ValidationRuleConfigurator<TInstance, TProperty>;
/**
* Defines a 'less than or equal' validator on the current rule.
* The validation will fail if the property value is more than the specified value.
* @param max Maximum value.
*/
lessThanOrEqual(max: number): ValidationRuleConfigurator<TInstance, TProperty>;
/**
* Defines a 'maximum length' validator on the current rule.
* Validation will fail if the length of the string is more than the specified value.
* @param maxLength Maximum length.
*/
maxLength(maxLength: number): ValidationRuleConfigurator<TInstance, TProperty>;
/**
* Defines a 'minimum length' validator on the current rule.
* Validation will fail if the length of the string is less than the specified value.
* @param maxLength Maximum length.
*/
minLength(minLength: number): ValidationRuleConfigurator<TInstance, TProperty>;
/**
* Defines an 'not empty' validator on the current rule.
* Validation will fail if the property is null, undefined, whitespace, zero or an empty array.
*/
notEmpty(): ValidationRuleConfigurator<TInstance, TProperty>;
/**
* Defines a 'not equal' validator on the current rule.
* Validation will fail if the specified value is equal to the value of the property.
*/
notEqual(valueToCompare: any): ValidationRuleConfigurator<TInstance, TProperty>;
/**
* Defines a 'not null' validator on the current rule.
* Validation will fail if the property is null or undefined.
*/
notNull(): ValidationRuleConfigurator<TInstance, TProperty>;
/**
* Defines a 'null' validator on the current rule.
* Validation will fail if the property is not null and not undefined.
*/
null(): ValidationRuleConfigurator<TInstance, TProperty>;
/**
* Defines a 'phone' validator on the current rule.
* Validation will fail if the property is not a well-formed phone number.
*/
phone(): ValidationRuleConfigurator<TInstance, TProperty>;
/**
* Defines a 'predicate' validator on the current rule.
* Validation will fail if the specified function or lambda returns false.
* @param predicate A function or lambda expression specifying the predicate.
*/
must(predicate: (property: TProperty, instance?: TInstance) => boolean): ValidationRuleConfigurator<TInstance, TProperty>;
/**
* Defines a 'regular expression' validator on the current rule.
* The validation will fail if the property does not match the regular expression.
* @param regularExpression The regular expression to check the value against.
*/
regularExpression(regularExpression: RegExp): ValidationRuleConfigurator<TInstance, TProperty>;
/**
* Defines an 'uri' validator on the current rule.
* Validation will fail if the property is not a well-formed URI.
*/
uri(): ValidationRuleConfigurator<TInstance, TProperty>;
}