@42.nl/jarb-final-form
Version:
Validating forms through JaRB.
85 lines (84 loc) • 4.54 kB
TypeScript
import { FieldType, Constraints, FieldConstraints } from './models';
/**
* Finds the most specific <input> type for the types parameter. For example if
* types is ['email', 'text'] the function returns 'email' because 'email'
* is the most specific input type. If nothing is found returns 'text'.
*
* If the types array is not defined or null 'text` is returned.
*
* @param {Array<string>} The types you want the closest type for.
* @return {FieldType} The closest <input> type, based on the types parameter.
*/
export declare function mostSpecificInputTypeFor(types: FieldType[] | null | undefined): FieldType;
/**
* Finds the FieldConstraints rules for a specific validator in the
* Constraints object.
*
* If no constraints can be found for a validator the boolean false
* is returned.
*
* @param {validator} 'validator' is a string with the format: 'Class.field' for example: 'User.age'
* @param {Constraints} The constraints to find the validator in.
* @throws {error} When the validator doesn't match the format 'className.fieldName'.
* @returns {FieldConstraints | false} The constraints for the specific field
*/
export declare function getFieldConstraintsFor(validator: string, constraints: Constraints): FieldConstraints | false;
/**
* Finds the FieldConstraints rules for a specific validator.
*
* If no constraints can be found for a validator the boolean false
* is returned.
*
* @param validator 'validator' is a string with the format: 'Class.field' for example: 'User.age'
* @throws {error} When the validator doesn't match the format 'className.fieldName'.
* @returns FieldConstraints | false The constraints for the specific field
*/
export declare function getFieldConstraints(validator: string): FieldConstraints | false;
/**
* Determine if constraints tell a specific validator makes a field required.
* @param validator 'validator' is a string with the format: 'Class.field' for example: 'User.age'
* @throws {error} When the validator doesn't match the format 'className.fieldName'.
*/
export declare function isRequired(validator: string): boolean;
/**
* Determine if constraints tell a specific validator makes a field have a minimum length.
* @param validator 'validator' is a string with the format: 'Class.field' for example: 'User.age'
* @throws {error} When the validator doesn't match the format 'className.fieldName'.
*/
export declare function hasMinimumLength(validator: string): boolean;
/**
* Determine if constraints tell a specific validator makes a field have a maximum length.
* @param validator 'validator' is a string with the format: 'Class.field' for example: 'User.age'
* @throws {error} When the validator doesn't match the format 'className.fieldName'.
*/
export declare function hasMaximumLength(validator: string): boolean;
/**
* Determine if constraints tell a specific validator makes a field have a fraction length.
* @param validator 'validator' is a string with the format: 'Class.field' for example: 'User.age'
* @throws {error} When the validator doesn't match the format 'className.fieldName'.
*/
export declare function hasFractionLength(validator: string): boolean;
/**
* Determine if constraints tell a specific validator makes a field have a radix.
* @param validator 'validator' is a string with the format: 'Class.field' for example: 'User.age'
* @throws {error} When the validator doesn't match the format 'className.fieldName'.
*/
export declare function hasRadix(validator: string): boolean;
/**
* Determine if constraints tell a specific validator makes a field comply to a pattern.
* @param validator 'validator' is a string with the format: 'Class.field' for example: 'User.age'
* @throws {error} When the validator doesn't match the format 'className.fieldName'.
*/
export declare function hasPattern(validator: string): boolean;
/**
* Determine if constraints tell a specific validator makes a field have a minimum.
* @param validator 'validator' is a string with the format: 'Class.field' for example: 'User.age'
* @throws {error} When the validator doesn't match the format 'className.fieldName'.
*/
export declare function hasMin(validator: string): boolean;
/**
* Determine if constraints tell a specific validator makes a field have a maximum.
* @param validator 'validator' is a string with the format: 'Class.field' for example: 'User.age'
* @throws {error} When the validator doesn't match the format 'className.fieldName'.
*/
export declare function hasMax(validator: string): boolean;