async-validator
- Version 4.2.5
- Published
- 285 kB
- No dependencies
- MIT license
Install
npm i async-validator
yarn add async-validator
pnpm add async-validator
Overview
validate form asynchronous
Index
Classes
Interfaces
Type Aliases
Classes
class Schema
class Schema {}
Encapsulates a validation schema.
Parameter descriptor
An object declaring validation rules for this schema.
constructor
constructor(descriptor: Rules);
property messages
static messages: InternalValidateMessages;
property register
static register: (type: string, validator: any) => void;
property rules
rules: Record<string, RuleItem[]>;
property validators
static validators: { string: import('./interface').ExecuteValidator; method: import('./interface').ExecuteValidator; number: import('./interface').ExecuteValidator; boolean: import('./interface').ExecuteValidator; regexp: import('./interface').ExecuteValidator; integer: import('./interface').ExecuteValidator; float: import('./interface').ExecuteValidator; array: import('./interface').ExecuteValidator; object: import('./interface').ExecuteValidator; enum: import('./interface').ExecuteValidator; pattern: import('./interface').ExecuteValidator; date: import('./interface').ExecuteValidator; url: import('./interface').ExecuteValidator; hex: import('./interface').ExecuteValidator; email: import('./interface').ExecuteValidator; required: import('./interface').ExecuteValidator; any: import('./interface').ExecuteValidator;};
property warning
static warning: (type: string, errors: SyncErrorType[]) => void;
method define
define: (rules: Rules) => void;
method getType
getType: (rule: InternalRuleItem) => import('./interface').RuleType;
method getValidationMethod
getValidationMethod: ( rule: InternalRuleItem) => | ExecuteValidator | (( rule: InternalRuleItem, value: any, callback: (error?: string | Error) => void, source: Values, options: ValidateOption ) => void | import('./interface').SyncValidateResult);
method messages
messages: (messages?: ValidateMessages) => InternalValidateMessages;
method validate
validate: { ( source: Values, option?: ValidateOption, callback?: ValidateCallback ): Promise<Values>; (source: Values, callback: ValidateCallback): Promise<Values>; (source: Values): Promise<Values>;};
Interfaces
interface InternalRuleItem
interface InternalRuleItem extends Omit<RuleItem, 'validator'> {}
property field
field?: string;
property fullField
fullField?: string;
property fullFields
fullFields?: string[];
property validator
validator?: RuleItem['validator'] | ExecuteValidator;
interface InternalValidateMessages
interface InternalValidateMessages extends ValidateMessages {}
property clone
clone: () => InternalValidateMessages;
interface RuleItem
interface RuleItem {}
property asyncValidator
asyncValidator?: ( rule: InternalRuleItem, value: Value, callback: (error?: string | Error) => void, source: Values, options: ValidateOption) => void | Promise<void>;
property defaultField
defaultField?: Rule;
property enum
enum?: Array<string | number | boolean | null | undefined>;
property fields
fields?: Record<string, Rule>;
property len
len?: number;
property max
max?: number;
property message
message?: string | ((a?: string) => string);
property min
min?: number;
property options
options?: ValidateOption;
property pattern
pattern?: RegExp | string;
property required
required?: boolean;
property transform
transform?: (value: Value) => Value;
property type
type?: RuleType;
property validator
validator?: ( rule: InternalRuleItem, value: Value, callback: (error?: string | Error) => void, source: Values, options: ValidateOption) => SyncValidateResult | void;
property whitespace
whitespace?: boolean;
interface RuleValuePackage
interface RuleValuePackage {}
interface ValidateError
interface ValidateError {}
property field
field?: string;
property fieldValue
fieldValue?: Value;
property message
message?: string;
interface ValidateMessages
interface ValidateMessages {}
property array
array?: { len?: ValidateMessage<[FullField, Range]>; min?: ValidateMessage<[FullField, Range]>; max?: ValidateMessage<[FullField, Range]>; range?: ValidateMessage<[FullField, Range, Range]>;};
property date
date?: { format?: ValidateMessage; parse?: ValidateMessage; invalid?: ValidateMessage;};
property default
default?: ValidateMessage;
property enum
enum?: ValidateMessage<[FullField, EnumString]>;
property number
number?: { len?: ValidateMessage<[FullField, Range]>; min?: ValidateMessage<[FullField, Range]>; max?: ValidateMessage<[FullField, Range]>; range?: ValidateMessage<[FullField, Range, Range]>;};
property pattern
pattern?: { mismatch?: ValidateMessage<[FullField, Value, Pattern]>;};
property required
required?: ValidateMessage<[FullField]>;
property string
string?: { len?: ValidateMessage<[FullField, Range]>; min?: ValidateMessage<[FullField, Range]>; max?: ValidateMessage<[FullField, Range]>; range?: ValidateMessage<[FullField, Range, Range]>;};
property types
types?: { string?: ValidateMessage<[FullField, Type]>; method?: ValidateMessage<[FullField, Type]>; array?: ValidateMessage<[FullField, Type]>; object?: ValidateMessage<[FullField, Type]>; number?: ValidateMessage<[FullField, Type]>; date?: ValidateMessage<[FullField, Type]>; boolean?: ValidateMessage<[FullField, Type]>; integer?: ValidateMessage<[FullField, Type]>; float?: ValidateMessage<[FullField, Type]>; regexp?: ValidateMessage<[FullField, Type]>; email?: ValidateMessage<[FullField, Type]>; url?: ValidateMessage<[FullField, Type]>; hex?: ValidateMessage<[FullField, Type]>;};
property whitespace
whitespace?: ValidateMessage<[FullField]>;
interface ValidateOption
interface ValidateOption {}
property error
error?: (rule: InternalRuleItem, message: string) => ValidateError;
property first
first?: boolean;
property firstFields
firstFields?: boolean | string[];
property keys
keys?: string[];
The name of rules need to be trigger. Will validate all rules if leave empty
property messages
messages?: Partial<ValidateMessages>;
property suppressValidatorError
suppressValidatorError?: boolean;
property suppressWarning
suppressWarning?: boolean;
Type Aliases
type ExecuteRule
type ExecuteRule = ( rule: InternalRuleItem, value: Value, source: Values, errors: string[], options: ValidateOption, type?: string) => void;
Rule for validating a value exists in an enumerable list.
Parameter rule
The validation rule.
Parameter value
The value of the field on the source object.
Parameter source
The source object being validated.
Parameter errors
An array of errors that this rule may add validation errors to.
Parameter options
The validation options.
Parameter
options.messages The validation messages.
Parameter type
Rule type
type ExecuteValidator
type ExecuteValidator = ( rule: InternalRuleItem, value: Value, callback: (error?: string[]) => void, source: Values, options: ValidateOption) => void;
Performs validation for any type.
Parameter rule
The validation rule.
Parameter value
The value of the field on the source object.
Parameter callback
The callback function.
Parameter source
The source object being validated.
Parameter options
The validation options.
Parameter
options.messages The validation messages.
type Rule
type Rule = RuleItem | RuleItem[];
type Rules
type Rules = Record<string, Rule>;
type RuleType
type RuleType = | 'string' | 'number' | 'boolean' | 'method' | 'regexp' | 'integer' | 'float' | 'array' | 'object' | 'enum' | 'date' | 'url' | 'hex' | 'email' | 'pattern' | 'any';
type SyncErrorType
type SyncErrorType = Error | string;
type SyncValidateResult
type SyncValidateResult = boolean | SyncErrorType | SyncErrorType[];
type ValidateCallback
type ValidateCallback = ( errors: ValidateError[] | null, fields: ValidateFieldsError | Values) => void;
type ValidateFieldsError
type ValidateFieldsError = Record<string, ValidateError[]>;
type ValidateResult
type ValidateResult = void | Promise<void> | SyncValidateResult;
type Value
type Value = any;
type Values
type Values = Record<string, Value>;
Package Files (2)
Dependencies (0)
No dependencies.
Dev Dependencies (17)
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/async-validator
.
- Markdown[](https://www.jsdocs.io/package/async-validator)
- HTML<a href="https://www.jsdocs.io/package/async-validator"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 3215 ms. - Missing or incorrect documentation? Open an issue for this package.