提交
This commit is contained in:
9
甲情_甲意/miniprogram/node_modules/async-validator/LICENSE.md
generated
vendored
Normal file
9
甲情_甲意/miniprogram/node_modules/async-validator/LICENSE.md
generated
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014-present yiminghe
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
472
甲情_甲意/miniprogram/node_modules/async-validator/README.md
generated
vendored
Normal file
472
甲情_甲意/miniprogram/node_modules/async-validator/README.md
generated
vendored
Normal file
@ -0,0 +1,472 @@
|
||||
# async-validator
|
||||
|
||||
[![NPM version][npm-image]][npm-url]
|
||||
[![build status][travis-image]][travis-url]
|
||||
[![Test coverage][coveralls-image]][coveralls-url]
|
||||
[![node version][node-image]][node-url]
|
||||
[![npm download][download-image]][download-url]
|
||||
[![npm bundle size (minified + gzip)][bundlesize-image]][bundlesize-url]
|
||||
|
||||
[npm-image]: https://img.shields.io/npm/v/async-validator.svg?style=flat-square
|
||||
[npm-url]: https://npmjs.org/package/async-validator
|
||||
[travis-image]:https://app.travis-ci.com/yiminghe/async-validator.svg?branch=master
|
||||
[travis-url]: https://app.travis-ci.com/github/yiminghe/async-validator
|
||||
[coveralls-image]: https://img.shields.io/coveralls/yiminghe/async-validator.svg?style=flat-square
|
||||
[coveralls-url]: https://coveralls.io/r/yiminghe/async-validator?branch=master
|
||||
[node-image]: https://img.shields.io/badge/node.js-%3E=4.0.0-green.svg?style=flat-square
|
||||
[node-url]: https://nodejs.org/download/
|
||||
[download-image]: https://img.shields.io/npm/dm/async-validator.svg?style=flat-square
|
||||
[download-url]: https://npmjs.org/package/async-validator
|
||||
[bundlesize-image]: https://img.shields.io/bundlephobia/minzip/async-validator.svg?label=gzip%20size
|
||||
[bundlesize-url]: https://bundlephobia.com/result?p=async-validator
|
||||
|
||||
Validate form asynchronous. A variation of https://github.com/freeformsystems/async-validate
|
||||
|
||||
## Install
|
||||
|
||||
```bash
|
||||
npm i async-validator
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
Basic usage involves defining a descriptor, assigning it to a schema and passing the object to be validated and a callback function to the `validate` method of the schema:
|
||||
|
||||
```js
|
||||
import Schema from 'async-validator';
|
||||
const descriptor = {
|
||||
name: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
validator: (rule, value) => value === 'muji',
|
||||
},
|
||||
age: {
|
||||
type: 'number',
|
||||
asyncValidator: (rule, value) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (value < 18) {
|
||||
reject('too young'); // reject with error message
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
},
|
||||
},
|
||||
};
|
||||
const validator = new Schema(descriptor);
|
||||
validator.validate({ name: 'muji' }, (errors, fields) => {
|
||||
if (errors) {
|
||||
// validation failed, errors is an array of all errors
|
||||
// fields is an object keyed by field name with an array of
|
||||
// errors per field
|
||||
return handleErrors(errors, fields);
|
||||
}
|
||||
// validation passed
|
||||
});
|
||||
|
||||
// PROMISE USAGE
|
||||
validator.validate({ name: 'muji', age: 16 }).then(() => {
|
||||
// validation passed or without error message
|
||||
}).catch(({ errors, fields }) => {
|
||||
return handleErrors(errors, fields);
|
||||
});
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### Validate
|
||||
|
||||
```js
|
||||
function(source, [options], callback): Promise
|
||||
```
|
||||
|
||||
* `source`: The object to validate (required).
|
||||
* `options`: An object describing processing options for the validation (optional).
|
||||
* `callback`: A callback function to invoke when validation completes (optional).
|
||||
|
||||
The method will return a Promise object like:
|
||||
* `then()`,validation passed
|
||||
* `catch({ errors, fields })`,validation failed, errors is an array of all errors, fields is an object keyed by field name with an array of errors per field
|
||||
|
||||
### Options
|
||||
|
||||
* `suppressWarning`: Boolean, whether to suppress internal warning about invalid value.
|
||||
|
||||
* `first`: Boolean, Invoke `callback` when the first validation rule generates an error,
|
||||
no more validation rules are processed.
|
||||
If your validation involves multiple asynchronous calls (for example, database queries) and you only need the first error use this option.
|
||||
|
||||
* `firstFields`: Boolean|String[], Invoke `callback` when the first validation rule of the specified field generates an error,
|
||||
no more validation rules of the same field are processed. `true` means all fields.
|
||||
|
||||
### Rules
|
||||
|
||||
Rules may be functions that perform validation.
|
||||
|
||||
```js
|
||||
function(rule, value, callback, source, options)
|
||||
```
|
||||
|
||||
* `rule`: The validation rule in the source descriptor that corresponds to the field name being validated. It is always assigned a `field` property with the name of the field being validated.
|
||||
* `value`: The value of the source object property being validated.
|
||||
* `callback`: A callback function to invoke once validation is complete. It expects to be passed an array of `Error` instances to indicate validation failure. If the check is synchronous, you can directly return a ` false ` or ` Error ` or ` Error Array `.
|
||||
* `source`: The source object that was passed to the `validate` method.
|
||||
* `options`: Additional options.
|
||||
* `options.messages`: The object containing validation error messages, will be deep merged with defaultMessages.
|
||||
|
||||
The options passed to `validate` or `asyncValidate` are passed on to the validation functions so that you may reference transient data (such as model references) in validation functions. However, some option names are reserved; if you use these properties of the options object they are overwritten. The reserved properties are `messages`, `exception` and `error`.
|
||||
|
||||
```js
|
||||
import Schema from 'async-validator';
|
||||
const descriptor = {
|
||||
name(rule, value, callback, source, options) {
|
||||
const errors = [];
|
||||
if (!/^[a-z0-9]+$/.test(value)) {
|
||||
errors.push(new Error(
|
||||
util.format('%s must be lowercase alphanumeric characters', rule.field),
|
||||
));
|
||||
}
|
||||
return errors;
|
||||
},
|
||||
};
|
||||
const validator = new Schema(descriptor);
|
||||
validator.validate({ name: 'Firstname' }, (errors, fields) => {
|
||||
if (errors) {
|
||||
return handleErrors(errors, fields);
|
||||
}
|
||||
// validation passed
|
||||
});
|
||||
```
|
||||
|
||||
It is often useful to test against multiple validation rules for a single field, to do so make the rule an array of objects, for example:
|
||||
|
||||
```js
|
||||
const descriptor = {
|
||||
email: [
|
||||
{ type: 'string', required: true, pattern: Schema.pattern.email },
|
||||
{
|
||||
validator(rule, value, callback, source, options) {
|
||||
const errors = [];
|
||||
// test if email address already exists in a database
|
||||
// and add a validation error to the errors array if it does
|
||||
return errors;
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
#### Type
|
||||
|
||||
Indicates the `type` of validator to use. Recognised type values are:
|
||||
|
||||
* `string`: Must be of type `string`. `This is the default type.`
|
||||
* `number`: Must be of type `number`.
|
||||
* `boolean`: Must be of type `boolean`.
|
||||
* `method`: Must be of type `function`.
|
||||
* `regexp`: Must be an instance of `RegExp` or a string that does not generate an exception when creating a new `RegExp`.
|
||||
* `integer`: Must be of type `number` and an integer.
|
||||
* `float`: Must be of type `number` and a floating point number.
|
||||
* `array`: Must be an array as determined by `Array.isArray`.
|
||||
* `object`: Must be of type `object` and not `Array.isArray`.
|
||||
* `enum`: Value must exist in the `enum`.
|
||||
* `date`: Value must be valid as determined by `Date`
|
||||
* `url`: Must be of type `url`.
|
||||
* `hex`: Must be of type `hex`.
|
||||
* `email`: Must be of type `email`.
|
||||
* `any`: Can be any type.
|
||||
|
||||
#### Required
|
||||
|
||||
The `required` rule property indicates that the field must exist on the source object being validated.
|
||||
|
||||
#### Pattern
|
||||
|
||||
The `pattern` rule property indicates a regular expression that the value must match to pass validation.
|
||||
|
||||
#### Range
|
||||
|
||||
A range is defined using the `min` and `max` properties. For `string` and `array` types comparison is performed against the `length`, for `number` types the number must not be less than `min` nor greater than `max`.
|
||||
|
||||
#### Length
|
||||
|
||||
To validate an exact length of a field specify the `len` property. For `string` and `array` types comparison is performed on the `length` property, for the `number` type this property indicates an exact match for the `number`, ie, it may only be strictly equal to `len`.
|
||||
|
||||
If the `len` property is combined with the `min` and `max` range properties, `len` takes precedence.
|
||||
|
||||
#### Enumerable
|
||||
|
||||
> Since version 3.0.0 if you want to validate the values `0` or `false` inside `enum` types, you have to include them explicitly.
|
||||
|
||||
To validate a value from a list of possible values use the `enum` type with a `enum` property listing the valid values for the field, for example:
|
||||
|
||||
```js
|
||||
const descriptor = {
|
||||
role: { type: 'enum', enum: ['admin', 'user', 'guest'] },
|
||||
};
|
||||
```
|
||||
|
||||
#### Whitespace
|
||||
|
||||
It is typical to treat required fields that only contain whitespace as errors. To add an additional test for a string that consists solely of whitespace add a `whitespace` property to a rule with a value of `true`. The rule must be a `string` type.
|
||||
|
||||
You may wish to sanitize user input instead of testing for whitespace, see [transform](#transform) for an example that would allow you to strip whitespace.
|
||||
|
||||
|
||||
#### Deep Rules
|
||||
|
||||
If you need to validate deep object properties you may do so for validation rules that are of the `object` or `array` type by assigning nested rules to a `fields` property of the rule.
|
||||
|
||||
```js
|
||||
const descriptor = {
|
||||
address: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
fields: {
|
||||
street: { type: 'string', required: true },
|
||||
city: { type: 'string', required: true },
|
||||
zip: { type: 'string', required: true, len: 8, message: 'invalid zip' },
|
||||
},
|
||||
},
|
||||
name: { type: 'string', required: true },
|
||||
};
|
||||
const validator = new Schema(descriptor);
|
||||
validator.validate({ address: {} }, (errors, fields) => {
|
||||
// errors for address.street, address.city, address.zip
|
||||
});
|
||||
```
|
||||
|
||||
Note that if you do not specify the `required` property on the parent rule it is perfectly valid for the field not to be declared on the source object and the deep validation rules will not be executed as there is nothing to validate against.
|
||||
|
||||
Deep rule validation creates a schema for the nested rules so you can also specify the `options` passed to the `schema.validate()` method.
|
||||
|
||||
```js
|
||||
const descriptor = {
|
||||
address: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
options: { first: true },
|
||||
fields: {
|
||||
street: { type: 'string', required: true },
|
||||
city: { type: 'string', required: true },
|
||||
zip: { type: 'string', required: true, len: 8, message: 'invalid zip' },
|
||||
},
|
||||
},
|
||||
name: { type: 'string', required: true },
|
||||
};
|
||||
const validator = new Schema(descriptor);
|
||||
|
||||
validator.validate({ address: {} })
|
||||
.catch(({ errors, fields }) => {
|
||||
// now only errors for street and name
|
||||
});
|
||||
```
|
||||
|
||||
The parent rule is also validated so if you have a set of rules such as:
|
||||
|
||||
```js
|
||||
const descriptor = {
|
||||
roles: {
|
||||
type: 'array',
|
||||
required: true,
|
||||
len: 3,
|
||||
fields: {
|
||||
0: { type: 'string', required: true },
|
||||
1: { type: 'string', required: true },
|
||||
2: { type: 'string', required: true },
|
||||
},
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
And supply a source object of `{ roles: ['admin', 'user'] }` then two errors will be created. One for the array length mismatch and one for the missing required array entry at index 2.
|
||||
|
||||
#### defaultField
|
||||
|
||||
The `defaultField` property can be used with the `array` or `object` type for validating all values of the container.
|
||||
It may be an `object` or `array` containing validation rules. For example:
|
||||
|
||||
```js
|
||||
const descriptor = {
|
||||
urls: {
|
||||
type: 'array',
|
||||
required: true,
|
||||
defaultField: { type: 'url' },
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
Note that `defaultField` is expanded to `fields`, see [deep rules](#deep-rules).
|
||||
|
||||
#### Transform
|
||||
|
||||
Sometimes it is necessary to transform a value before validation, possibly to coerce the value or to sanitize it in some way. To do this add a `transform` function to the validation rule. The property is transformed prior to validation and returned as promise result or callback result when pass validation.
|
||||
|
||||
```js
|
||||
import Schema from 'async-validator';
|
||||
const descriptor = {
|
||||
name: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
pattern: /^[a-z]+$/,
|
||||
transform(value) {
|
||||
return value.trim();
|
||||
},
|
||||
},
|
||||
};
|
||||
const validator = new Schema(descriptor);
|
||||
const source = { name: ' user ' };
|
||||
|
||||
validator.validate(source)
|
||||
.then((data) => assert.equal(data.name, 'user'));
|
||||
|
||||
validator.validate(source,(errors, data)=>{
|
||||
assert.equal(data.name, 'user'));
|
||||
});
|
||||
```
|
||||
|
||||
Without the `transform` function validation would fail due to the pattern not matching as the input contains leading and trailing whitespace, but by adding the transform function validation passes and the field value is sanitized at the same time.
|
||||
|
||||
|
||||
#### Messages
|
||||
|
||||
Depending upon your application requirements, you may need i18n support or you may prefer different validation error messages.
|
||||
|
||||
The easiest way to achieve this is to assign a `message` to a rule:
|
||||
|
||||
```js
|
||||
{ name: { type: 'string', required: true, message: 'Name is required' } }
|
||||
```
|
||||
|
||||
Message can be any type, such as jsx format.
|
||||
|
||||
```js
|
||||
{ name: { type: 'string', required: true, message: '<b>Name is required</b>' } }
|
||||
```
|
||||
|
||||
Message can also be a function, e.g. if you use vue-i18n:
|
||||
```js
|
||||
{ name: { type: 'string', required: true, message: () => this.$t( 'name is required' ) } }
|
||||
```
|
||||
|
||||
Potentially you may require the same schema validation rules for different languages, in which case duplicating the schema rules for each language does not make sense.
|
||||
|
||||
In this scenario you could just provide your own messages for the language and assign it to the schema:
|
||||
|
||||
```js
|
||||
import Schema from 'async-validator';
|
||||
const cn = {
|
||||
required: '%s 必填',
|
||||
};
|
||||
const descriptor = { name: { type: 'string', required: true } };
|
||||
const validator = new Schema(descriptor);
|
||||
// deep merge with defaultMessages
|
||||
validator.messages(cn);
|
||||
...
|
||||
```
|
||||
|
||||
If you are defining your own validation functions it is better practice to assign the message strings to a messages object and then access the messages via the `options.messages` property within the validation function.
|
||||
|
||||
#### asyncValidator
|
||||
|
||||
You can customize the asynchronous validation function for the specified field:
|
||||
|
||||
```js
|
||||
const fields = {
|
||||
asyncField: {
|
||||
asyncValidator(rule, value, callback) {
|
||||
ajax({
|
||||
url: 'xx',
|
||||
value: value,
|
||||
}).then(function(data) {
|
||||
callback();
|
||||
}, function(error) {
|
||||
callback(new Error(error));
|
||||
});
|
||||
},
|
||||
},
|
||||
|
||||
promiseField: {
|
||||
asyncValidator(rule, value) {
|
||||
return ajax({
|
||||
url: 'xx',
|
||||
value: value,
|
||||
});
|
||||
},
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
#### validator
|
||||
|
||||
You can custom validate function for specified field:
|
||||
|
||||
```js
|
||||
const fields = {
|
||||
field: {
|
||||
validator(rule, value, callback) {
|
||||
return value === 'test';
|
||||
},
|
||||
message: 'Value is not equal to "test".',
|
||||
},
|
||||
|
||||
field2: {
|
||||
validator(rule, value, callback) {
|
||||
return new Error(`${value} is not equal to 'test'.`);
|
||||
},
|
||||
},
|
||||
|
||||
arrField: {
|
||||
validator(rule, value) {
|
||||
return [
|
||||
new Error('Message 1'),
|
||||
new Error('Message 2'),
|
||||
];
|
||||
},
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
## FAQ
|
||||
|
||||
### How to avoid global warning
|
||||
|
||||
```js
|
||||
import Schema from 'async-validator';
|
||||
Schema.warning = function(){};
|
||||
```
|
||||
|
||||
or
|
||||
```js
|
||||
globalThis.ASYNC_VALIDATOR_NO_WARNING = 1;
|
||||
```
|
||||
|
||||
### How to check if it is `true`
|
||||
|
||||
Use `enum` type passing `true` as option.
|
||||
|
||||
```js
|
||||
{
|
||||
type: 'enum',
|
||||
enum: [true],
|
||||
message: '',
|
||||
}
|
||||
```
|
||||
|
||||
## Test Case
|
||||
|
||||
```bash
|
||||
npm test
|
||||
```
|
||||
|
||||
## Coverage
|
||||
|
||||
```bash
|
||||
npm run coverage
|
||||
```
|
||||
|
||||
Open coverage/ dir
|
||||
|
||||
## License
|
||||
|
||||
Everything is [MIT](https://en.wikipedia.org/wiki/MIT_License).
|
1333
甲情_甲意/miniprogram/node_modules/async-validator/dist-node/index.js
generated
vendored
Normal file
1333
甲情_甲意/miniprogram/node_modules/async-validator/dist-node/index.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1
甲情_甲意/miniprogram/node_modules/async-validator/dist-node/index.js.map
generated
vendored
Normal file
1
甲情_甲意/miniprogram/node_modules/async-validator/dist-node/index.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
43
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/index.d.ts
generated
vendored
Normal file
43
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
import { InternalRuleItem, InternalValidateMessages, RuleItem, Rules, ValidateCallback, ValidateMessages, ValidateOption, Values, SyncErrorType } from './interface';
|
||||
export * from './interface';
|
||||
/**
|
||||
* Encapsulates a validation schema.
|
||||
*
|
||||
* @param descriptor An object declaring validation rules
|
||||
* for this schema.
|
||||
*/
|
||||
declare class Schema {
|
||||
static register: (type: string, validator: any) => void;
|
||||
static warning: (type: string, errors: SyncErrorType[]) => void;
|
||||
static messages: InternalValidateMessages;
|
||||
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;
|
||||
};
|
||||
rules: Record<string, RuleItem[]>;
|
||||
_messages: InternalValidateMessages;
|
||||
constructor(descriptor: Rules);
|
||||
define(rules: Rules): void;
|
||||
messages(messages?: ValidateMessages): InternalValidateMessages;
|
||||
validate(source: Values, option?: ValidateOption, callback?: ValidateCallback): Promise<Values>;
|
||||
validate(source: Values, callback: ValidateCallback): Promise<Values>;
|
||||
validate(source: Values): Promise<Values>;
|
||||
getType(rule: InternalRuleItem): import("./interface").RuleType;
|
||||
getValidationMethod(rule: InternalRuleItem): ((rule: InternalRuleItem, value: any, callback: (error?: string | Error) => void, source: Values, options: ValidateOption) => void | import("./interface").SyncValidateResult) | import("./interface").ExecuteValidator;
|
||||
}
|
||||
export default Schema;
|
135
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/interface.d.ts
generated
vendored
Normal file
135
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/interface.d.ts
generated
vendored
Normal file
@ -0,0 +1,135 @@
|
||||
export declare type RuleType = 'string' | 'number' | 'boolean' | 'method' | 'regexp' | 'integer' | 'float' | 'array' | 'object' | 'enum' | 'date' | 'url' | 'hex' | 'email' | 'pattern' | 'any';
|
||||
export interface ValidateOption {
|
||||
suppressWarning?: boolean;
|
||||
suppressValidatorError?: boolean;
|
||||
first?: boolean;
|
||||
firstFields?: boolean | string[];
|
||||
messages?: Partial<ValidateMessages>;
|
||||
/** The name of rules need to be trigger. Will validate all rules if leave empty */
|
||||
keys?: string[];
|
||||
error?: (rule: InternalRuleItem, message: string) => ValidateError;
|
||||
}
|
||||
export declare type SyncErrorType = Error | string;
|
||||
export declare type SyncValidateResult = boolean | SyncErrorType | SyncErrorType[];
|
||||
export declare type ValidateResult = void | Promise<void> | SyncValidateResult;
|
||||
export interface RuleItem {
|
||||
type?: RuleType;
|
||||
required?: boolean;
|
||||
pattern?: RegExp | string;
|
||||
min?: number;
|
||||
max?: number;
|
||||
len?: number;
|
||||
enum?: Array<string | number | boolean | null | undefined>;
|
||||
whitespace?: boolean;
|
||||
fields?: Record<string, Rule>;
|
||||
options?: ValidateOption;
|
||||
defaultField?: Rule;
|
||||
transform?: (value: Value) => Value;
|
||||
message?: string | ((a?: string) => string);
|
||||
asyncValidator?: (rule: InternalRuleItem, value: Value, callback: (error?: string | Error) => void, source: Values, options: ValidateOption) => void | Promise<void>;
|
||||
validator?: (rule: InternalRuleItem, value: Value, callback: (error?: string | Error) => void, source: Values, options: ValidateOption) => SyncValidateResult | void;
|
||||
}
|
||||
export declare type Rule = RuleItem | RuleItem[];
|
||||
export declare type Rules = Record<string, Rule>;
|
||||
/**
|
||||
* Rule for validating a value exists in an enumerable list.
|
||||
*
|
||||
* @param rule The validation rule.
|
||||
* @param value The value of the field on the source object.
|
||||
* @param source The source object being validated.
|
||||
* @param errors An array of errors that this rule may add
|
||||
* validation errors to.
|
||||
* @param options The validation options.
|
||||
* @param options.messages The validation messages.
|
||||
* @param type Rule type
|
||||
*/
|
||||
export declare type ExecuteRule = (rule: InternalRuleItem, value: Value, source: Values, errors: string[], options: ValidateOption, type?: string) => void;
|
||||
/**
|
||||
* Performs validation for any type.
|
||||
*
|
||||
* @param rule The validation rule.
|
||||
* @param value The value of the field on the source object.
|
||||
* @param callback The callback function.
|
||||
* @param source The source object being validated.
|
||||
* @param options The validation options.
|
||||
* @param options.messages The validation messages.
|
||||
*/
|
||||
export declare type ExecuteValidator = (rule: InternalRuleItem, value: Value, callback: (error?: string[]) => void, source: Values, options: ValidateOption) => void;
|
||||
declare type ValidateMessage<T extends any[] = unknown[]> = string | ((...args: T) => string);
|
||||
declare type FullField = string | undefined;
|
||||
declare type EnumString = string | undefined;
|
||||
declare type Pattern = string | RegExp | undefined;
|
||||
declare type Range = number | undefined;
|
||||
declare type Type = string | undefined;
|
||||
export interface ValidateMessages {
|
||||
default?: ValidateMessage;
|
||||
required?: ValidateMessage<[FullField]>;
|
||||
enum?: ValidateMessage<[FullField, EnumString]>;
|
||||
whitespace?: ValidateMessage<[FullField]>;
|
||||
date?: {
|
||||
format?: ValidateMessage;
|
||||
parse?: ValidateMessage;
|
||||
invalid?: ValidateMessage;
|
||||
};
|
||||
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]>;
|
||||
};
|
||||
string?: {
|
||||
len?: ValidateMessage<[FullField, Range]>;
|
||||
min?: ValidateMessage<[FullField, Range]>;
|
||||
max?: ValidateMessage<[FullField, Range]>;
|
||||
range?: ValidateMessage<[FullField, Range, Range]>;
|
||||
};
|
||||
number?: {
|
||||
len?: ValidateMessage<[FullField, Range]>;
|
||||
min?: ValidateMessage<[FullField, Range]>;
|
||||
max?: ValidateMessage<[FullField, Range]>;
|
||||
range?: ValidateMessage<[FullField, Range, Range]>;
|
||||
};
|
||||
array?: {
|
||||
len?: ValidateMessage<[FullField, Range]>;
|
||||
min?: ValidateMessage<[FullField, Range]>;
|
||||
max?: ValidateMessage<[FullField, Range]>;
|
||||
range?: ValidateMessage<[FullField, Range, Range]>;
|
||||
};
|
||||
pattern?: {
|
||||
mismatch?: ValidateMessage<[FullField, Value, Pattern]>;
|
||||
};
|
||||
}
|
||||
export interface InternalValidateMessages extends ValidateMessages {
|
||||
clone: () => InternalValidateMessages;
|
||||
}
|
||||
export declare type Value = any;
|
||||
export declare type Values = Record<string, Value>;
|
||||
export interface ValidateError {
|
||||
message?: string;
|
||||
fieldValue?: Value;
|
||||
field?: string;
|
||||
}
|
||||
export declare type ValidateFieldsError = Record<string, ValidateError[]>;
|
||||
export declare type ValidateCallback = (errors: ValidateError[] | null, fields: ValidateFieldsError | Values) => void;
|
||||
export interface RuleValuePackage {
|
||||
rule: InternalRuleItem;
|
||||
value: Value;
|
||||
source: Values;
|
||||
field: string;
|
||||
}
|
||||
export interface InternalRuleItem extends Omit<RuleItem, 'validator'> {
|
||||
field?: string;
|
||||
fullField?: string;
|
||||
fullFields?: string[];
|
||||
validator?: RuleItem['validator'] | ExecuteValidator;
|
||||
}
|
||||
export {};
|
3
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/messages.d.ts
generated
vendored
Normal file
3
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/messages.d.ts
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
import { InternalValidateMessages } from './interface';
|
||||
export declare function newMessages(): InternalValidateMessages;
|
||||
export declare const messages: InternalValidateMessages;
|
3
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/rule/enum.d.ts
generated
vendored
Normal file
3
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/rule/enum.d.ts
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
import { ExecuteRule } from '../interface';
|
||||
declare const enumerable: ExecuteRule;
|
||||
export default enumerable;
|
9
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/rule/index.d.ts
generated
vendored
Normal file
9
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/rule/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
declare const _default: {
|
||||
required: import("..").ExecuteRule;
|
||||
whitespace: import("..").ExecuteRule;
|
||||
type: import("..").ExecuteRule;
|
||||
range: import("..").ExecuteRule;
|
||||
enum: import("..").ExecuteRule;
|
||||
pattern: import("..").ExecuteRule;
|
||||
};
|
||||
export default _default;
|
3
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/rule/pattern.d.ts
generated
vendored
Normal file
3
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/rule/pattern.d.ts
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
import { ExecuteRule } from '../interface';
|
||||
declare const pattern: ExecuteRule;
|
||||
export default pattern;
|
3
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/rule/range.d.ts
generated
vendored
Normal file
3
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/rule/range.d.ts
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
import { ExecuteRule } from '../interface';
|
||||
declare const range: ExecuteRule;
|
||||
export default range;
|
3
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/rule/required.d.ts
generated
vendored
Normal file
3
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/rule/required.d.ts
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
import { ExecuteRule } from '../interface';
|
||||
declare const required: ExecuteRule;
|
||||
export default required;
|
3
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/rule/type.d.ts
generated
vendored
Normal file
3
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/rule/type.d.ts
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
import { ExecuteRule } from '../interface';
|
||||
declare const type: ExecuteRule;
|
||||
export default type;
|
2
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/rule/url.d.ts
generated
vendored
Normal file
2
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/rule/url.d.ts
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
declare const _default: () => RegExp;
|
||||
export default _default;
|
14
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/rule/whitespace.d.ts
generated
vendored
Normal file
14
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/rule/whitespace.d.ts
generated
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
import { ExecuteRule } from '../interface';
|
||||
/**
|
||||
* Rule for validating whitespace.
|
||||
*
|
||||
* @param rule The validation rule.
|
||||
* @param value The value of the field on the source object.
|
||||
* @param source The source object being validated.
|
||||
* @param errors An array of errors that this rule may add
|
||||
* validation errors to.
|
||||
* @param options The validation options.
|
||||
* @param options.messages The validation messages.
|
||||
*/
|
||||
declare const whitespace: ExecuteRule;
|
||||
export default whitespace;
|
16
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/util.d.ts
generated
vendored
Normal file
16
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/util.d.ts
generated
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
import { ValidateError, ValidateOption, RuleValuePackage, InternalRuleItem, SyncErrorType, Value, Values } from './interface';
|
||||
export declare let warning: (type: string, errors: SyncErrorType[]) => void;
|
||||
export declare function convertFieldsError(errors: ValidateError[]): Record<string, ValidateError[]>;
|
||||
export declare function format(template: ((...args: any[]) => string) | string, ...args: any[]): string;
|
||||
export declare function isEmptyValue(value: Value, type?: string): boolean;
|
||||
export declare function isEmptyObject(obj: object): boolean;
|
||||
export declare class AsyncValidationError extends Error {
|
||||
errors: ValidateError[];
|
||||
fields: Record<string, ValidateError[]>;
|
||||
constructor(errors: ValidateError[], fields: Record<string, ValidateError[]>);
|
||||
}
|
||||
declare type ValidateFunc = (data: RuleValuePackage, doIt: (errors: ValidateError[]) => void) => void;
|
||||
export declare function asyncMap(objArr: Record<string, RuleValuePackage[]>, option: ValidateOption, func: ValidateFunc, callback: (errors: ValidateError[]) => void, source: Values): Promise<Values>;
|
||||
export declare function complementError(rule: InternalRuleItem, source: Values): (oe: ValidateError | (() => string) | string) => ValidateError;
|
||||
export declare function deepMerge<T extends object>(target: T, source: Partial<T>): T;
|
||||
export {};
|
3
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/validator/any.d.ts
generated
vendored
Normal file
3
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/validator/any.d.ts
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
import { ExecuteValidator } from '../interface';
|
||||
declare const any: ExecuteValidator;
|
||||
export default any;
|
3
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/validator/array.d.ts
generated
vendored
Normal file
3
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/validator/array.d.ts
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
import { ExecuteValidator } from '../interface';
|
||||
declare const array: ExecuteValidator;
|
||||
export default array;
|
3
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/validator/boolean.d.ts
generated
vendored
Normal file
3
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/validator/boolean.d.ts
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
import { ExecuteValidator } from '../interface';
|
||||
declare const boolean: ExecuteValidator;
|
||||
export default boolean;
|
3
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/validator/date.d.ts
generated
vendored
Normal file
3
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/validator/date.d.ts
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
import { ExecuteValidator } from '../interface';
|
||||
declare const date: ExecuteValidator;
|
||||
export default date;
|
3
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/validator/enum.d.ts
generated
vendored
Normal file
3
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/validator/enum.d.ts
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
import { ExecuteValidator } from '../interface';
|
||||
declare const enumerable: ExecuteValidator;
|
||||
export default enumerable;
|
3
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/validator/float.d.ts
generated
vendored
Normal file
3
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/validator/float.d.ts
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
import { ExecuteValidator } from '../interface';
|
||||
declare const floatFn: ExecuteValidator;
|
||||
export default floatFn;
|
20
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/validator/index.d.ts
generated
vendored
Normal file
20
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/validator/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
declare const _default: {
|
||||
string: import("..").ExecuteValidator;
|
||||
method: import("..").ExecuteValidator;
|
||||
number: import("..").ExecuteValidator;
|
||||
boolean: import("..").ExecuteValidator;
|
||||
regexp: import("..").ExecuteValidator;
|
||||
integer: import("..").ExecuteValidator;
|
||||
float: import("..").ExecuteValidator;
|
||||
array: import("..").ExecuteValidator;
|
||||
object: import("..").ExecuteValidator;
|
||||
enum: import("..").ExecuteValidator;
|
||||
pattern: import("..").ExecuteValidator;
|
||||
date: import("..").ExecuteValidator;
|
||||
url: import("..").ExecuteValidator;
|
||||
hex: import("..").ExecuteValidator;
|
||||
email: import("..").ExecuteValidator;
|
||||
required: import("..").ExecuteValidator;
|
||||
any: import("..").ExecuteValidator;
|
||||
};
|
||||
export default _default;
|
3
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/validator/integer.d.ts
generated
vendored
Normal file
3
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/validator/integer.d.ts
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
import { ExecuteValidator } from '../interface';
|
||||
declare const integer: ExecuteValidator;
|
||||
export default integer;
|
3
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/validator/method.d.ts
generated
vendored
Normal file
3
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/validator/method.d.ts
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
import { ExecuteValidator } from '../interface';
|
||||
declare const method: ExecuteValidator;
|
||||
export default method;
|
3
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/validator/number.d.ts
generated
vendored
Normal file
3
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/validator/number.d.ts
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
import { ExecuteValidator } from '../interface';
|
||||
declare const number: ExecuteValidator;
|
||||
export default number;
|
3
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/validator/object.d.ts
generated
vendored
Normal file
3
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/validator/object.d.ts
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
import { ExecuteValidator } from '../interface';
|
||||
declare const object: ExecuteValidator;
|
||||
export default object;
|
3
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/validator/pattern.d.ts
generated
vendored
Normal file
3
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/validator/pattern.d.ts
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
import { ExecuteValidator } from '../interface';
|
||||
declare const pattern: ExecuteValidator;
|
||||
export default pattern;
|
3
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/validator/regexp.d.ts
generated
vendored
Normal file
3
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/validator/regexp.d.ts
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
import { ExecuteValidator } from '../interface';
|
||||
declare const regexp: ExecuteValidator;
|
||||
export default regexp;
|
3
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/validator/required.d.ts
generated
vendored
Normal file
3
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/validator/required.d.ts
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
import { ExecuteValidator } from '../interface';
|
||||
declare const required: ExecuteValidator;
|
||||
export default required;
|
3
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/validator/string.d.ts
generated
vendored
Normal file
3
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/validator/string.d.ts
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
import { ExecuteValidator } from '../interface';
|
||||
declare const string: ExecuteValidator;
|
||||
export default string;
|
3
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/validator/type.d.ts
generated
vendored
Normal file
3
甲情_甲意/miniprogram/node_modules/async-validator/dist-types/validator/type.d.ts
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
import { ExecuteValidator } from '../interface';
|
||||
declare const type: ExecuteValidator;
|
||||
export default type;
|
1329
甲情_甲意/miniprogram/node_modules/async-validator/dist-web/index.js
generated
vendored
Normal file
1329
甲情_甲意/miniprogram/node_modules/async-validator/dist-web/index.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1
甲情_甲意/miniprogram/node_modules/async-validator/dist-web/index.js.map
generated
vendored
Normal file
1
甲情_甲意/miniprogram/node_modules/async-validator/dist-web/index.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
48
甲情_甲意/miniprogram/node_modules/async-validator/package.json
generated
vendored
Normal file
48
甲情_甲意/miniprogram/node_modules/async-validator/package.json
generated
vendored
Normal file
@ -0,0 +1,48 @@
|
||||
{
|
||||
"name": "async-validator",
|
||||
"description": "validate form asynchronous",
|
||||
"version": "4.2.5",
|
||||
"license": "MIT",
|
||||
"files": [
|
||||
"dist-*/",
|
||||
"bin/"
|
||||
],
|
||||
"pika": true,
|
||||
"sideEffects": false,
|
||||
"keywords": [
|
||||
"validator",
|
||||
"validate",
|
||||
"async"
|
||||
],
|
||||
"homepage": "https://github.com/yiminghe/async-validator",
|
||||
"bugs": {
|
||||
"url": "https://github.com/yiminghe/async-validator/issues"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git@github.com:yiminghe/async-validator.git"
|
||||
},
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.15.0",
|
||||
"@babel/node": "^7.14.9",
|
||||
"@babel/preset-env": "^7.8.7",
|
||||
"@babel/preset-typescript": "^7.13.0",
|
||||
"@pika/pack": "^0.5.0",
|
||||
"@types/jest": "27.x",
|
||||
"babel-jest": "27.x",
|
||||
"coveralls": "^2.13.1",
|
||||
"jest": "27.x",
|
||||
"lint-staged": "^7.2.0",
|
||||
"np": "7.x",
|
||||
"pika-plugin-build-web-babel": "^0.10.0",
|
||||
"pika-plugin-ts-types": "0.1.x",
|
||||
"pre-commit": "^1.2.2",
|
||||
"prettier": "^1.11.1",
|
||||
"ts-node": "^10.8.1",
|
||||
"typescript": "^4.3.2"
|
||||
},
|
||||
"types": "dist-types/index.d.ts",
|
||||
"main": "dist-node/index.js",
|
||||
"module": "dist-web/index.js"
|
||||
}
|
Reference in New Issue
Block a user