增加基本项目配置

This commit is contained in:
Gao xiaosong
2020-03-15 13:59:43 +08:00
commit 397082cdaf
1117 changed files with 105700 additions and 0 deletions

9
node_modules/async-validator/LICENSE.md generated vendored Normal file
View 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.

456
node_modules/async-validator/README.md generated vendored Normal file
View File

@ -0,0 +1,456 @@
# async-validator
---
Validate form asynchronous. A variation of https://github.com/freeformsystems/async-validate
[![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://img.shields.io/travis/yiminghe/async-validator.svg?style=flat-square
[travis-url]: https://travis-ci.org/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
## Install
```
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:
```javascript
import schema from 'async-validator';
var 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();
}
});
}
}
};
var 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
```javascript
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 (required).
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
### 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.
```javascript
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`.
```javascript
import schema from 'async-validator';
var descriptor = {
name(rule, value, callback, source, options) {
var errors = [];
if(!/^[a-z0-9]+$/.test(value)) {
errors.push(
new Error(
util.format("%s must be lowercase alphanumeric characters",
rule.field)));
}
return errors;
}
}
var 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:
```javascript
var descriptor = {
email: [
{type: "string", required: true, pattern: schema.pattern.email},
{validator(rule, value, callback, source, options) {
var 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:
```javascript
var 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.
```javascript
var 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}
}
var 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.
```javascript
var 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}
}
var 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:
```javascript
var 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:
```javascript
var 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 re-assigned to the source object to mutate the value of the property in place.
```javascript
import schema from 'async-validator';
var descriptor = {
name: {
type: "string",
required: true, pattern: /^[a-z]+$/,
transform(value) {
return value.trim();
}
}
}
var validator = new schema(descriptor);
var source = {name: " user "};
validator.validate(source)
.then(() => assert.equal(source.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:
```javascript
{name:{type: "string", required: true, message: "Name is required"}}
```
Message can be any type, such as jsx format.
```javascript
{name:{type: "string", required: true, message: "<b>Name is required</b>"}}
```
Message can also be a function, e.g. if you use vue-i18n:
```javascript
{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:
```javascript
import schema from 'async-validator';
var cn = {
required: '%s 必填',
};
var descriptor = {name:{type: "string", required: true}};
var 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 warning
```js
import Schema from 'async-validator';
Schema.warning = function(){};
```
### How to check if it is `true`
Use `enum` type passing `true` as option.
```js
{
type: 'enum',
enum: [true],
message: '',
}
```
## Test Case
```
npm test
npm run chrome-test
```
## Coverage
```
npm run coverage
```
open coverage/ dir
## License
Everything is [MIT](https://en.wikipedia.org/wiki/MIT_License).

1352
node_modules/async-validator/dist-node/index.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

1
node_modules/async-validator/dist-node/index.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

97
node_modules/async-validator/dist-types/index.d.ts generated vendored Normal file
View File

@ -0,0 +1,97 @@
// Type definitions for async-validator 3.0.4
// Project: http://github.com/yiminghe/async-validator
// Definitions by: iamdhj <https://github.com/iamdhj>
// TypeScript Version: 3.6.2
export default class {
constructor(rule: Rules);
/**
* Validate source
* @param source The object to validate (required)
* @param options An object describing processing options for the validation
* @param callback A callback function to invoke when validation completes
* @returns Promise
*/
validate(
source: ValidateSource,
options?: ValidateOption,
callback?: (errors: ErrorList, fields: FieldErrorList) => void,
): Promise<void>;
}
export type RuleType =
| 'string'
| 'number'
| 'boolean'
| 'method'
| 'regexp'
| 'integer'
| 'float'
| 'array'
| 'object'
| 'enum'
| 'date'
| 'url'
| 'hex'
| 'email'
| 'any';
export interface RuleItem {
type?: RuleType; // default type is 'string'
required?: boolean;
pattern?: RegExp | string;
min?: number; // Range of type 'string' and 'array'
max?: number; // Range of type 'string' and 'array'
len?: number; // Length of type 'string' and 'array'
enum?: Array<string | number | boolean | null | undefined>; // possible values of type 'enum'
whitespace?: boolean;
fields?: Rules; // ignore when without required
options?: ValidateOption;
defaultField?: { type: RuleType }; // 'object' or 'array' containing validation rules
transform?: (value: any) => any;
message?: string;
asyncValidator?: (
rule: Rules,
value: any,
callback: (error: string | string[] | void) => void,
source: ValidateSource,
options: ValidateOption,
) => void | Promise<void>;
validator?: (
rule: Rules,
value: any,
callback: (error: string | string[] | void) => void,
source: ValidateSource,
options: ValidateOption,
) => void;
}
export interface Rules {
[field: string]: RuleItem | RuleItem[];
}
export interface ValidateSource {
[field: string]: any;
}
export interface ValidateOption {
// whether to suppress internal warning
suppressWarning?: boolean;
// when the first validation rule generates an error stop processed
first?: boolean;
// when the first validation rule of the specified field generates an error stop the field processed, 'true' means all fields.
firstFields?: boolean | string[];
}
export interface ValidateError {
message: string;
field: string;
}
export type ErrorList = ValidateError[];
export interface FieldErrorList {
[field: string]: ValidateError[];
}

1348
node_modules/async-validator/dist-web/index.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

1
node_modules/async-validator/dist-web/index.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

71
node_modules/async-validator/package.json generated vendored Normal file
View File

@ -0,0 +1,71 @@
{
"_from": "async-validator",
"_id": "async-validator@3.2.4",
"_inBundle": false,
"_integrity": "sha1-Tnc6HQ10EBa0VbeZW0aaR8zg2+A=",
"_location": "/async-validator",
"_phantomChildren": {},
"_requested": {
"type": "tag",
"registry": true,
"raw": "async-validator",
"name": "async-validator",
"escapedName": "async-validator",
"rawSpec": "",
"saveSpec": null,
"fetchSpec": "latest"
},
"_requiredBy": [
"#USER",
"/"
],
"_resolved": "https://registry.npm.taobao.org/async-validator/download/async-validator-3.2.4.tgz",
"_shasum": "4e773a1d0d741016b455b7995b469a47cce0dbe0",
"_spec": "async-validator",
"_where": "/Users/piao/Documents/Project/yshopmall_uni",
"bugs": {
"url": "http://github.com/yiminghe/async-validator/issues"
},
"bundleDependencies": false,
"dependencies": {},
"deprecated": false,
"description": "validate form asynchronous",
"devDependencies": {
"@babel/preset-env": "^7.8.7",
"@pika/pack": "^0.5.0",
"@pika/plugin-build-types": "^0.6.0",
"@pika/plugin-standard-pkg": "^0.6.0",
"@pika/types": "^0.6.0",
"babel-jest": "^24.8.0",
"coveralls": "^2.13.1",
"jest": "^24.8.0",
"lint-staged": "^7.2.0",
"np": "^5.0.3",
"pika-plugin-build-web-babel": "^0.8.0",
"pika-plugin-clean-dist-src": "^0.1.1",
"pre-commit": "^1.2.2",
"prettier": "^1.11.1"
},
"files": [
"dist-*/",
"bin/"
],
"homepage": "http://github.com/yiminghe/async-validator",
"keywords": [
"validator",
"validate",
"async"
],
"license": "MIT",
"main": "dist-node/index.js",
"module": "dist-web/index.js",
"name": "async-validator",
"pika": true,
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/yiminghe/async-validator.git"
},
"sideEffects": false,
"types": "dist-types/index.d.ts",
"version": "3.2.4"
}