[
  {
    "path": ".babelrc.js",
    "content": "console.log('Load babel config');\n\nmodule.exports = api => {\n  return {\n    presets: [\n      [\n        '@babel/preset-env',\n        api.env('test')\n          ? { targets: { node: true } }\n          : {\n              loose: true,\n              modules: false,\n            },\n      ],\n      '@babel/preset-typescript',\n    ],\n  };\n};\n"
  },
  {
    "path": ".editorconfig",
    "content": "# top-most EditorConfig file\nroot = true\n\n# Unix-style newlines with a newline ending every file\n[*.{js,css}]\nend_of_line = lf\ninsert_final_newline = true\nindent_style = space\nindent_size = 2\n"
  },
  {
    "path": ".gitignore",
    "content": "# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.\n\n# dependencies\nnode_modules\n/.yarn/*\n!/.yarn/patches\n!/.yarn/plugins\n!/.yarn/releases\n!/.yarn/sdks\n!/.yarn/versions\n\n# Swap the comments on the following lines if you don't wish to use zero-installs\n# Documentation here: https://yarnpkg.com/features/zero-installs\n#!/.yarn/cache\n/.pnp.*\n\n\n# testing\n/coverage\n\n# production\nbuild\npkg\ndist\n\n# misc\n.DS_Store\n.env.local\n.env.development.local\n.env.test.local\n.env.production.local\n\nnpm-debug.log*\nyarn-debug.log*\nyarn-error.log*\n\n*.log\n*.aes\ncypress/screenshots\ncypress/videos\ncypress/logs\ncypress/fixtures/profile.json\ncypress/fixtures/users.json\n.history"
  },
  {
    "path": ".np-config.json",
    "content": "{\n    \"yarn\": false\n}"
  },
  {
    "path": ".prettierrc",
    "content": "{\n  \"singleQuote\": true,\n  \"trailingComma\": \"all\"\n}"
  },
  {
    "path": ".travis.yml",
    "content": "language: node_js\n\nnotifications:\n    email:\n        - yiminghe@gmail.com\n\nnode_js:\n  - 16.13.1\n\nbefore_install:\n  - corepack enable\n\nscript:\n  - yarn run coverage\n"
  },
  {
    "path": ".yarnrc.yml",
    "content": "nodeLinker: node-modules"
  },
  {
    "path": "HISTORY.md",
    "content": "# History\n----\n\n## 4.0.0 / 2021-08-11\n\n- full ts support\n- support return transformed value when pass validation(promise and callback): https://github.com/yiminghe/async-validator/pull/277\n\n## 3.5.0 / 2020-11-12\n\n- https://github.com/yiminghe/async-validator/pull/256/files\n\n## 3.4.0 / 2020-08-05\n\n- https://github.com/yiminghe/async-validator/pull/247\n- https://github.com/yiminghe/async-validator/pull/246\n- https://github.com/yiminghe/async-validator/pull/245\n- https://github.com/yiminghe/async-validator/pull/240\n\n## 3.3.0 / 2020-05-07\n\n- expose validators: https://github.com/yiminghe/async-validator/pull/232\n\n## 3.2.0 / 2019-10-16\n\n- support `any` type: https://github.com/yiminghe/async-validator/pull/190\n\n## 3.1.0 / 2019-09-09\n\n- add d.ts\n\n## 3.0.0 / 2019-08-07\n\n- Enum validates `false` value: https://github.com/yiminghe/async-validator/pull/164\n\n## 2.0.0 / 2019-07-26\n\n- use @pika/pack\n\n## 1.11.3 / 2019-06-28\n\n- support suppressWarning option when validate\n\n## 1.11.1 / 2019-04-22\n\n- support message as function\n\n## 1.11.0 / 2019-03-22\n\n- support promise usage(asyncValidator)\n\n## 1.10.1 / 2018-12-18\n\n- support override warning\n\n## 1.10.0 / 2018-10-17\n\n- revert promise\n\n## 1.9.0 / 2018-10-10\n\n- .validate returns promise\n\n## 1.8.0 / 2017-08-16\n\n- validator support return promise.\n\n## 1.7.0 / 2017-06/09\n\n- add es\n- support string patter\n\n## 1.6.0 / 2016-03-30\n\n- support defaultField\n\n## 1.5.0 / 2016-02-02\n\n- support deep merge with default messages\n- support rule message of any type(exp: jsx)\n\n## 1.4.0 / 2015-01-12\n\n- fix first option. \n- add firstFields option.\n- see tests/validator.spec.js\n"
  },
  {
    "path": "LICENSE.md",
    "content": "The MIT License (MIT)\n\nCopyright (c) 2014-present yiminghe\n\nPermission 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:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE 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.\n"
  },
  {
    "path": "README.md",
    "content": "# async-validator\n\n[![NPM version][npm-image]][npm-url]\n[![build status][travis-image]][travis-url]\n[![Test coverage][coveralls-image]][coveralls-url]\n[![node version][node-image]][node-url]\n[![npm download][download-image]][download-url]\n[![npm bundle size (minified + gzip)][bundlesize-image]][bundlesize-url]\n\n[npm-image]: https://img.shields.io/npm/v/async-validator.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/async-validator\n[travis-image]:https://app.travis-ci.com/yiminghe/async-validator.svg?branch=master\n[travis-url]: https://app.travis-ci.com/github/yiminghe/async-validator\n[coveralls-image]: https://img.shields.io/coveralls/yiminghe/async-validator.svg?style=flat-square\n[coveralls-url]: https://coveralls.io/r/yiminghe/async-validator?branch=master\n[node-image]: https://img.shields.io/badge/node.js-%3E=4.0.0-green.svg?style=flat-square\n[node-url]: https://nodejs.org/download/\n[download-image]: https://img.shields.io/npm/dm/async-validator.svg?style=flat-square\n[download-url]: https://npmjs.org/package/async-validator\n[bundlesize-image]: https://img.shields.io/bundlephobia/minzip/async-validator.svg?label=gzip%20size\n[bundlesize-url]: https://bundlephobia.com/result?p=async-validator\n\nValidate form asynchronous. A variation of https://github.com/freeformsystems/async-validate\n\n## Install\n\n```bash\nnpm i async-validator\n```\n\n## Usage\n\nBasic 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:\n\n```js\nimport Schema from 'async-validator';\nconst descriptor = {\n  name: {\n    type: 'string',\n    required: true,\n    validator: (rule, value) => value === 'muji',\n  },\n  age: {\n    type: 'number',\n    asyncValidator: (rule, value) => {\n      return new Promise((resolve, reject) => {\n        if (value < 18) {\n          reject('too young');  // reject with error message\n        } else {\n          resolve();\n        }\n      });\n    },\n  },\n};\nconst validator = new Schema(descriptor);\nvalidator.validate({ name: 'muji' }, (errors, fields) => {\n  if (errors) {\n    // validation failed, errors is an array of all errors\n    // fields is an object keyed by field name with an array of\n    // errors per field\n    return handleErrors(errors, fields);\n  }\n  // validation passed\n});\n\n// PROMISE USAGE\nvalidator.validate({ name: 'muji', age: 16 }).then(() => {\n  // validation passed or without error message\n}).catch(({ errors, fields }) => {\n  return handleErrors(errors, fields);\n});\n```\n\n## API\n\n### Validate\n\n```js\nfunction(source, [options], callback): Promise\n```\n\n* `source`: The object to validate (required).\n* `options`: An object describing processing options for the validation (optional).\n* `callback`: A callback function to invoke when validation completes (optional).\n\nThe method will return a Promise object like:\n* `then()`，validation passed\n* `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\n\n### Options\n\n* `suppressWarning`: Boolean, whether to suppress internal warning about invalid value.\n\n* `first`: Boolean, Invoke `callback` when the first validation rule generates an error,\nno more validation rules are processed.\nIf your validation involves multiple asynchronous calls (for example, database queries) and you only need the first error use this option.\n\n* `firstFields`: Boolean|String[], Invoke `callback` when the first validation rule of the specified field generates an error,\nno more validation rules of the same field are processed.  `true` means all fields.\n\n### Rules\n\nRules may be functions that perform validation.\n\n```js\nfunction(rule, value, callback, source, options)\n```\n\n* `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.\n* `value`: The value of the source object property being validated.\n* `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 `.\n* `source`: The source object that was passed to the `validate` method.\n* `options`: Additional options.\n* `options.messages`: The object containing validation error messages, will be deep merged with defaultMessages.\n\nThe 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`.\n\n```js\nimport Schema from 'async-validator';\nconst descriptor = {\n  name(rule, value, callback, source, options) {\n    const errors = [];\n    if (!/^[a-z0-9]+$/.test(value)) {\n      errors.push(new Error(\n        util.format('%s must be lowercase alphanumeric characters', rule.field),\n      ));\n    }\n    return errors;\n  },\n};\nconst validator = new Schema(descriptor);\nvalidator.validate({ name: 'Firstname' }, (errors, fields) => {\n  if (errors) {\n    return handleErrors(errors, fields);\n  }\n  // validation passed\n});\n```\n\nIt 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:\n\n```js\nconst descriptor = {\n  email: [\n    { type: 'string', required: true, pattern: Schema.pattern.email },\n    { \n      validator(rule, value, callback, source, options) {\n        const errors = [];\n        // test if email address already exists in a database\n        // and add a validation error to the errors array if it does\n        return errors;\n      },\n    },\n  ],\n};\n```\n\n#### Type\n\nIndicates the `type` of validator to use. Recognised type values are:\n\n* `string`: Must be of type `string`. `This is the default type.`\n* `number`: Must be of type `number`.\n* `boolean`: Must be of type `boolean`.\n* `method`: Must be of type `function`.\n* `regexp`: Must be an instance of `RegExp` or a string that does not generate an exception when creating a new `RegExp`.\n* `integer`: Must be of type `number` and an integer.\n* `float`: Must be of type `number` and a floating point number.\n* `array`: Must be an array as determined by `Array.isArray`.\n* `object`: Must be of type `object` and not `Array.isArray`.\n* `enum`: Value must exist in the `enum`.\n* `date`: Value must be valid as determined by `Date`\n* `url`: Must be of type `url`.\n* `hex`: Must be of type `hex`.\n* `email`: Must be of type `email`.\n* `any`: Can be any type.\n\n#### Required\n\nThe `required` rule property indicates that the field must exist on the source object being validated.\n\n#### Pattern\n\nThe `pattern` rule property indicates a regular expression that the value must match to pass validation.\n\n#### Range\n\nA 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`.\n\n#### Length\n\nTo 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`.\n\nIf the `len` property is combined with the `min` and `max` range properties, `len` takes precedence.\n\n#### Enumerable\n\n> Since version 3.0.0 if you want to validate the values `0` or `false` inside `enum` types, you have to include them explicitly.\n\nTo 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:\n\n```js\nconst descriptor = {\n  role: { type: 'enum', enum: ['admin', 'user', 'guest'] },\n};\n```\n\n#### Whitespace\n\nIt 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.\n\nYou may wish to sanitize user input instead of testing for whitespace, see [transform](#transform) for an example that would allow you to strip whitespace.\n\n\n#### Deep Rules\n\nIf 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.\n\n```js\nconst descriptor = {\n  address: {\n    type: 'object',\n    required: true,\n    fields: {\n      street: { type: 'string', required: true },\n      city: { type: 'string', required: true },\n      zip: { type: 'string', required: true, len: 8, message: 'invalid zip' },\n    },\n  },\n  name: { type: 'string', required: true },\n};\nconst validator = new Schema(descriptor);\nvalidator.validate({ address: {} }, (errors, fields) => {\n  // errors for address.street, address.city, address.zip\n});\n```\n\nNote 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.\n\nDeep rule validation creates a schema for the nested rules so you can also specify the `options` passed to the `schema.validate()` method.\n\n```js\nconst descriptor = {\n  address: {\n    type: 'object',\n    required: true,\n    options: { first: true },\n    fields: {\n      street: { type: 'string', required: true },\n      city: { type: 'string', required: true },\n      zip: { type: 'string', required: true, len: 8, message: 'invalid zip' },\n    },\n  },\n  name: { type: 'string', required: true },\n};\nconst validator = new Schema(descriptor);\n\nvalidator.validate({ address: {} })\n  .catch(({ errors, fields }) => {\n    // now only errors for street and name    \n  });\n```\n\nThe parent rule is also validated so if you have a set of rules such as:\n\n```js\nconst descriptor = {\n  roles: {\n    type: 'array',\n    required: true,\n    len: 3,\n    fields: {\n      0: { type: 'string', required: true },\n      1: { type: 'string', required: true },\n      2: { type: 'string', required: true },\n    },\n  },\n};\n```\n\nAnd 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.\n\n#### defaultField\n\nThe `defaultField` property can be used with the `array` or `object` type for validating all values of the container.\nIt may be an `object` or `array` containing validation rules. For example:\n\n```js\nconst descriptor = {\n  urls: {\n    type: 'array',\n    required: true,\n    defaultField: { type: 'url' },\n  },\n};\n```\n\nNote that `defaultField` is expanded to `fields`, see [deep rules](#deep-rules).\n\n#### Transform\n\nSometimes 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.\n\n```js\nimport Schema from 'async-validator';\nconst descriptor = {\n  name: {\n    type: 'string',\n    required: true,\n    pattern: /^[a-z]+$/,\n    transform(value) {\n      return value.trim();\n    },\n  },\n};\nconst validator = new Schema(descriptor);\nconst source = { name: ' user  ' };\n\nvalidator.validate(source)\n  .then((data) => assert.equal(data.name, 'user'));\n\nvalidator.validate(source,(errors, data)=>{\n  assert.equal(data.name, 'user'));\n});\n```\n\nWithout 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.\n\n\n#### Messages\n\nDepending upon your application requirements, you may need i18n support or you may prefer different validation error messages.\n\nThe easiest way to achieve this is to assign a `message` to a rule:\n\n```js\n{ name: { type: 'string', required: true, message: 'Name is required' } }\n```\n\nMessage can be any type, such as jsx format.\n\n```js\n{ name: { type: 'string', required: true, message: '<b>Name is required</b>' } }\n```\n\nMessage can also be a function, e.g. if you use vue-i18n:\n```js\n{ name: { type: 'string', required: true, message: () => this.$t( 'name is required' ) } }\n```\n\nPotentially 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.\n\nIn this scenario you could just provide your own messages for the language and assign it to the schema:\n\n```js\nimport Schema from 'async-validator';\nconst cn = {\n  required: '%s 必填',\n};\nconst descriptor = { name: { type: 'string', required: true } };\nconst validator = new Schema(descriptor);\n// deep merge with defaultMessages\nvalidator.messages(cn);\n...\n```\n\nIf 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.\n\n#### asyncValidator\n\nYou can customize the asynchronous validation function for the specified field:\n\n```js\nconst fields = {\n  asyncField: {\n    asyncValidator(rule, value, callback) {\n      ajax({\n        url: 'xx',\n        value: value,\n      }).then(function(data) {\n        callback();\n      }, function(error) {\n        callback(new Error(error));\n      });\n    },\n  },\n\n  promiseField: {\n    asyncValidator(rule, value) {\n      return ajax({\n        url: 'xx',\n        value: value,\n      });\n    },\n  },\n};\n```\n\n#### validator\n\nYou can custom validate function for specified field:\n\n```js\nconst fields = {\n  field: {\n    validator(rule, value, callback) {\n      return value === 'test';\n    },\n    message: 'Value is not equal to \"test\".',\n  },\n\n  field2: {\n    validator(rule, value, callback) {\n      return new Error(`${value} is not equal to 'test'.`);\n    },\n  },\n \n  arrField: {\n    validator(rule, value) {\n      return [\n        new Error('Message 1'),\n        new Error('Message 2'),\n      ];\n    },\n  },\n};\n```\n\n## FAQ\n\n### How to avoid global warning\n\n```js\nimport Schema from 'async-validator';\nSchema.warning = function(){};\n```\n\nor\n```js\nglobalThis.ASYNC_VALIDATOR_NO_WARNING = 1;\n```\n\n### How to check if it is `true`\n\nUse `enum` type passing `true` as option.\n\n```js\n{\n  type: 'enum',\n  enum: [true],\n  message: '',\n}\n```\n\n## Test Case\n\n```bash\nnpm test\n```\n\n## Coverage\n\n```bash\nnpm run coverage\n```\n\nOpen coverage/ dir\n\n## License\n\nEverything is [MIT](https://en.wikipedia.org/wiki/MIT_License).\n"
  },
  {
    "path": "__tests__/any.spec.ts",
    "content": "import Schema from '../src';\n\nconst testNoErrorsFor = value => done => {\n  new Schema({\n    v: {\n      type: 'any',\n    },\n  }).validate(\n    {\n      v: value,\n    },\n    errors => {\n      expect(errors).toBe(null);\n      done();\n    },\n  );\n};\n\nconst testRequiredErrorFor = value => done => {\n  new Schema({\n    v: {\n      required: true,\n      type: 'string',\n    },\n  }).validate(\n    {\n      v: value,\n    },\n    errors => {\n      expect(errors.length).toBe(1);\n      expect(errors[0].message).toBe('v is required');\n      done();\n    },\n  );\n};\n\ndescribe('any', () => {\n  it('allows null', testNoErrorsFor(null));\n  it('allows undefined', testNoErrorsFor(undefined));\n  it('allows strings', testNoErrorsFor('foo'));\n  it('allows numbers', testNoErrorsFor(1));\n  it('allows booleans', testNoErrorsFor(false));\n  it('allows arrays', testNoErrorsFor([]));\n  it('allows objects', testNoErrorsFor({}));\n  it('rejects undefined when required', testRequiredErrorFor(undefined));\n  it('rejects null when required', testRequiredErrorFor(null));\n});\n"
  },
  {
    "path": "__tests__/array.spec.ts",
    "content": "import Schema from '../src';\n\ndescribe('array', () => {\n  it('works for type', done => {\n    new Schema({\n      v: {\n        type: 'array',\n      },\n    }).validate(\n      {\n        v: '',\n      },\n      errors => {\n        expect(errors.length).toBe(1);\n        expect(errors[0].message).toBe('v is not an array');\n        done();\n      },\n    );\n  });\n\n  it('works for type and required', done => {\n    new Schema({\n      v: {\n        required: true,\n        type: 'array',\n      },\n    }).validate(\n      {\n        v: '',\n      },\n      (errors, fields) => {\n        expect(errors.length).toBe(1);\n        expect(fields).toMatchInlineSnapshot(`\n          Object {\n            \"v\": Array [\n              Object {\n                \"field\": \"v\",\n                \"fieldValue\": \"\",\n                \"message\": \"v is not an array\",\n              },\n            ],\n          }\n        `);\n        expect(errors[0].message).toBe('v is not an array');\n        done();\n      },\n    );\n  });\n\n  it('works for none require', done => {\n    new Schema({\n      v: {\n        type: 'array',\n      },\n    }).validate(\n      {\n        v: [],\n      },\n      errors => {\n        expect(errors).toBe(null);\n        done();\n      },\n    );\n  });\n\n  it('works for empty array', done => {\n    new Schema({\n      v: {\n        required: true,\n        type: 'array',\n      },\n    }).validate(\n      {\n        v: [],\n      },\n      errors => {\n        expect(errors.length).toBe(1);\n        expect(errors[0].message).toBe('v is required');\n        done();\n      },\n    );\n  });\n\n  it('works for undefined array', done => {\n    new Schema({\n      v: {\n        type: 'array',\n      },\n    }).validate(\n      {\n        v: undefined,\n      },\n      errors => {\n        expect(errors).toBe(null);\n        done();\n      },\n    );\n  });\n\n  it('works for undefined array and required', done => {\n    new Schema({\n      v: {\n        required: true,\n        type: 'array',\n      },\n    }).validate(\n      {\n        v: undefined,\n      },\n      errors => {\n        expect(errors.length).toBe(1);\n        expect(errors[0].message).toBe('v is required');\n        done();\n      },\n    );\n  });\n\n  it('works for undefined array and defaultField', done => {\n    new Schema({\n      v: {\n        type: 'array',\n        defaultField: { type: 'string' },\n      },\n    }).validate(\n      {\n        v: undefined,\n      },\n      errors => {\n        expect(errors).toBe(null);\n        done();\n      },\n    );\n  });\n\n  it('works for null array', done => {\n    new Schema({\n      v: {\n        required: true,\n        type: 'array',\n      },\n    }).validate(\n      {\n        v: null,\n      },\n      errors => {\n        expect(errors.length).toBe(1);\n        expect(errors[0].message).toBe('v is required');\n        done();\n      },\n    );\n  });\n\n  it('works for none empty', done => {\n    new Schema({\n      v: {\n        required: true,\n        type: 'array',\n        message: 'haha',\n      },\n    }).validate(\n      {\n        v: [1],\n      },\n      errors => {\n        expect(errors).toBe(null);\n        done();\n      },\n    );\n  });\n\n  it('works for empty array with min', done => {\n    new Schema({\n      v: {\n        min: 1,\n        max: 3,\n        type: 'array',\n      },\n    }).validate(\n      {\n        v: [],\n      },\n      errors => {\n        expect(errors.length).toBe(1);\n        expect(errors[0].message).toBe('v must be between 1 and 3 in length');\n        done();\n      },\n    );\n  });\n\n  it('works for empty array with max', done => {\n    new Schema({\n      v: {\n        min: 1,\n        max: 3,\n        type: 'array',\n      },\n    }).validate(\n      {\n        v: [1, 2, 3, 4],\n      },\n      errors => {\n        expect(errors.length).toBe(1);\n        expect(errors[0].message).toBe('v must be between 1 and 3 in length');\n        done();\n      },\n    );\n  });\n});\n"
  },
  {
    "path": "__tests__/date.spec.ts",
    "content": "import Schema from '../src';\n\ndescribe('date', () => {\n  it('required works for undefined', done => {\n    new Schema({\n      v: {\n        type: 'date',\n        required: true,\n      },\n    }).validate(\n      {\n        v: undefined,\n      },\n      errors => {\n        expect(errors.length).toBe(1);\n        expect(errors[0].message).toBe('v is required');\n        done();\n      },\n    );\n  });\n\n  it('required works for \"\"', done => {\n    new Schema({\n      v: {\n        type: 'date',\n        required: true,\n      },\n    }).validate(\n      {\n        v: '',\n      },\n      errors => {\n        expect(errors.length).toBe(1);\n        expect(errors[0].message).toBe('v is required');\n        done();\n      },\n    );\n  });\n\n  it('required works for non-date type', done => {\n    new Schema({\n      v: {\n        type: 'date',\n        required: true,\n      },\n    }).validate(\n      {\n        v: {},\n      },\n      errors => {\n        expect(errors.length).toBe(1);\n        expect(errors[0].message).toBe('v is not a date');\n        done();\n      },\n    );\n  });\n\n  it('required works for \"timestamp\"', done => {\n    new Schema({\n      v: {\n        type: 'date',\n        required: true,\n      },\n    }).validate(\n      {\n        v: 1530374400000,\n      },\n      errors => {\n        expect(errors).toBe(null);\n        done();\n      },\n    );\n  });\n});\n"
  },
  {
    "path": "__tests__/deep.spec.ts",
    "content": "import Schema, { Rules } from '../src';\n\ndescribe('deep', () => {\n  it('deep array specific validation', done => {\n    new Schema({\n      v: {\n        required: true,\n        type: 'array',\n        fields: {\n          '0': [{ type: 'string' }],\n          '1': [{ type: 'string' }],\n        },\n      },\n    }).validate(\n      {\n        v: [1, 'b'],\n      },\n      (errors, fields) => {\n        expect(errors.length).toBe(1);\n        expect(fields).toMatchInlineSnapshot(`\n          Object {\n            \"v.0\": Array [\n              Object {\n                \"field\": \"v.0\",\n                \"fieldValue\": 1,\n                \"message\": \"v.0 is not a string\",\n              },\n            ],\n          }\n        `);\n        expect(errors[0].message).toBe('v.0 is not a string');\n        done();\n      },\n    );\n  });\n\n  it('deep object specific validation', done => {\n    new Schema({\n      v: {\n        required: true,\n        type: 'object',\n        fields: {\n          a: [{ type: 'string' }],\n          b: [{ type: 'string' }],\n        },\n      },\n    }).validate(\n      {\n        v: {\n          a: 1,\n          b: 'c',\n        },\n      },\n      (errors, fields) => {\n        expect(errors.length).toBe(1);\n        expect(fields).toMatchInlineSnapshot(`\n          Object {\n            \"v.a\": Array [\n              Object {\n                \"field\": \"v.a\",\n                \"fieldValue\": 1,\n                \"message\": \"v.a is not a string\",\n              },\n            ],\n          }\n        `);\n        expect(errors[0].message).toBe('v.a is not a string');\n        done();\n      },\n    );\n  });\n\n  describe('defaultField', () => {\n    it('deep array all values validation', done => {\n      new Schema({\n        v: {\n          required: true,\n          type: 'array',\n          defaultField: [{ type: 'string' }],\n        },\n      }).validate(\n        {\n          v: [1, 2, 'c'],\n        },\n        (errors, fields) => {\n          expect(errors.length).toBe(2);\n          expect(fields).toMatchInlineSnapshot(`\n            Object {\n              \"v.0\": Array [\n                Object {\n                  \"field\": \"v.0\",\n                  \"fieldValue\": 1,\n                  \"message\": \"v.0 is not a string\",\n                },\n              ],\n              \"v.1\": Array [\n                Object {\n                  \"field\": \"v.1\",\n                  \"fieldValue\": 2,\n                  \"message\": \"v.1 is not a string\",\n                },\n              ],\n            }\n          `);\n          expect(errors[0].message).toBe('v.0 is not a string');\n          expect(errors[1].message).toBe('v.1 is not a string');\n          done();\n        },\n      );\n    });\n\n    it('deep transform array all values validation', done => {\n      new Schema({\n        v: {\n          required: true,\n          type: 'array',\n          defaultField: [{ type: 'number', max: 0, transform: Number }],\n        },\n      }).validate(\n        {\n          v: ['1', '2'],\n        },\n        (errors, fields) => {\n          expect(errors.length).toBe(2);\n          expect(fields).toMatchInlineSnapshot(`\n            Object {\n              \"v.0\": Array [\n                Object {\n                  \"field\": \"v.0\",\n                  \"fieldValue\": 1,\n                  \"message\": \"v.0 cannot be greater than 0\",\n                },\n              ],\n              \"v.1\": Array [\n                Object {\n                  \"field\": \"v.1\",\n                  \"fieldValue\": 2,\n                  \"message\": \"v.1 cannot be greater than 0\",\n                },\n              ],\n            }\n          `);\n          expect(errors).toMatchInlineSnapshot(`\n            Array [\n              Object {\n                \"field\": \"v.0\",\n                \"fieldValue\": 1,\n                \"message\": \"v.0 cannot be greater than 0\",\n              },\n              Object {\n                \"field\": \"v.1\",\n                \"fieldValue\": 2,\n                \"message\": \"v.1 cannot be greater than 0\",\n              },\n            ]\n          `);\n          done();\n        },\n      );\n    });\n\n    it('will merge top validation', () => {\n      const obj = {\n        value: '',\n        test: [\n          {\n            name: 'aa',\n          },\n        ],\n      };\n\n      const descriptor: Rules = {\n        test: {\n          type: 'array',\n          min: 2,\n          required: true,\n          message: '至少两项',\n          defaultField: [\n            {\n              type: 'object',\n              required: true,\n              message: 'test 必须有',\n              fields: {\n                name: {\n                  type: 'string',\n                  required: true,\n                  message: 'name 必须有',\n                },\n              },\n            },\n          ],\n        },\n      };\n\n      new Schema(descriptor).validate(obj, errors => {\n        expect(errors).toMatchInlineSnapshot(`\n          Array [\n            Object {\n              \"field\": \"test\",\n              \"fieldValue\": Array [\n                Object {\n                  \"name\": \"aa\",\n                },\n              ],\n              \"message\": \"至少两项\",\n            },\n          ]\n        `);\n      });\n    });\n\n    it('array & required works', done => {\n      const descriptor: Rules = {\n        testArray: {\n          type: 'array',\n          required: true,\n          defaultField: [{ type: 'string' }],\n        },\n      };\n      const record = {\n        testArray: [],\n      };\n      const validator = new Schema(descriptor);\n      validator.validate(record, (errors, fields) => {\n        done();\n      });\n    });\n\n    it('deep object all values validation', done => {\n      new Schema({\n        v: {\n          required: true,\n          type: 'object',\n          defaultField: [{ type: 'string' }],\n        },\n      }).validate(\n        {\n          v: {\n            a: 1,\n            b: 'c',\n          },\n        },\n        errors => {\n          expect(errors.length).toBe(1);\n          expect(errors[0].message).toBe('v.a is not a string');\n          done();\n        },\n      );\n    });\n  });\n});\n"
  },
  {
    "path": "__tests__/enum.spec.ts",
    "content": "import Schema from '../src';\n\ndescribe('enum', () => {\n  it('run validation on `false`', done => {\n    new Schema({\n      v: {\n        type: 'enum',\n        enum: [true],\n      },\n    }).validate(\n      {\n        v: false,\n      },\n      errors => {\n        expect(errors.length).toBe(1);\n        expect(errors[0].message).toBe('v must be one of true');\n        done();\n      },\n    );\n  });\n});\n"
  },
  {
    "path": "__tests__/messages.spec.ts",
    "content": "import Schema, { ValidateMessages } from '../src';\n\ndescribe('messages', () => {\n  it('can call messages', done => {\n    const messages = {\n      required(f) {\n        return `${f} required!`;\n      },\n    };\n    const schema = new Schema({\n      v: {\n        required: true,\n      },\n      v2: {\n        type: 'array',\n      },\n    });\n    schema.messages(messages);\n    schema.validate(\n      {\n        v: '',\n        v2: '1',\n      },\n      errors => {\n        expect(errors.length).toBe(2);\n        expect(errors[0].message).toBe('v required!');\n        expect(errors[1].message).toBe('v2 is not an array');\n        expect(Object.keys(messages).length).toBe(1);\n        done();\n      },\n    );\n  });\n\n  it('can use options.messages', done => {\n    const messages = {\n      required(f) {\n        return `${f} required!`;\n      },\n    };\n    const schema = new Schema({\n      v: {\n        required: true,\n      },\n      v2: {\n        type: 'array',\n      },\n    });\n    schema.validate(\n      {\n        v: '',\n        v2: '1',\n      },\n      {\n        messages,\n      },\n      errors => {\n        expect(errors.length).toBe(2);\n        expect(errors[0].message).toBe('v required!');\n        expect(errors[1].message).toBe('v2 is not an array');\n        expect(Object.keys(messages).length).toBe(1);\n        done();\n      },\n    );\n  });\n\n  it('messages with parameters', done => {\n    const messages = {\n      required: 'Field %s required!',\n    };\n    const schema = new Schema({\n      v: {\n        required: true,\n      },\n    });\n    schema.messages(messages);\n    schema.validate(\n      {\n        v: '',\n      },\n      errors => {\n        expect(errors).toBeTruthy();\n        expect(errors.length).toBe(1);\n        expect(errors[0].message).toBe('Field v required!');\n        expect(Object.keys(messages).length).toBe(1);\n        done();\n      },\n    );\n  });\n\n  it('messages can be without parameters', done => {\n    const messages = {\n      required: 'required!',\n    };\n    const schema = new Schema({\n      v: {\n        required: true,\n      },\n    });\n    schema.messages(messages);\n    schema.validate(\n      {\n        v: '',\n      },\n      errors => {\n        expect(errors).toBeTruthy();\n        expect(errors.length).toBe(1);\n        expect(errors[0].message).toBe('required!');\n        expect(Object.keys(messages).length).toBe(1);\n        expect(messages.required).toBe('required!');\n        done();\n      },\n    );\n  });\n\n  it('message can be a function', done => {\n    const message = 'this is a function';\n    new Schema({\n      v: {\n        required: true,\n        message: () => message,\n      },\n    }).validate(\n      {\n        v: '', // provide empty value, this will trigger the message.\n      },\n      errors => {\n        expect(errors).toBeTruthy();\n        expect(errors.length).toBe(1);\n        expect(errors[0].message).toBe(message);\n        done();\n      },\n    );\n  });\n});\n"
  },
  {
    "path": "__tests__/number.spec.ts",
    "content": "import Schema from '../src';\n\ndescribe('number', () => {\n  it('works', done => {\n    new Schema({\n      v: {\n        type: 'number',\n      },\n    }).validate(\n      {\n        v: '1',\n      },\n      errors => {\n        expect(errors.length).toBe(1);\n        expect(errors[0].message).toBe('v is not a number');\n        done();\n      },\n    );\n  });\n\n  it('works for no-required', done => {\n    new Schema({\n      v: {\n        type: 'number',\n      },\n    }).validate(\n      {\n        v: undefined,\n      },\n      errors => {\n        expect(errors).toBeFalsy();\n        done();\n      },\n    );\n  });\n\n  it('works for no-required in case of empty string', done => {\n    new Schema({\n      v: {\n        type: 'number',\n        required: false,\n      },\n    }).validate(\n      {\n        v: '',\n      },\n      errors => {\n        expect(errors).toBeFalsy();\n        done();\n      },\n    );\n  });\n\n  it('works for required', done => {\n    new Schema({\n      v: {\n        type: 'number',\n        required: true,\n      },\n    }).validate(\n      {\n        v: undefined,\n      },\n      errors => {\n        expect(errors.length).toBe(1);\n        expect(errors[0].message).toBe('v is required');\n        done();\n      },\n    );\n  });\n\n  it('transform does not change value', done => {\n    const value = {\n      v: '1',\n    };\n    new Schema({\n      v: {\n        type: 'number',\n        transform: Number,\n      },\n    }).validate(value, (errors, data) => {\n      expect(data).toEqual({\n        v: 1,\n      });\n      expect(value.v).toBe('1');\n      expect(errors).toBeFalsy();\n      done();\n    });\n  });\n\n  it('return transformed value in promise.then', done => {\n    const value = {\n      v: '1',\n    };\n    new Schema({\n      v: {\n        type: 'number',\n        transform: Number,\n      },\n    })\n      .validate(value, errors => {\n        expect(value.v).toBe('1');\n        expect(errors).toBeFalsy();\n      })\n      .then(source => {\n        expect(source).toEqual({\n          v: 1,\n        });\n        done();\n      });\n  });\n});\n"
  },
  {
    "path": "__tests__/object.spec.ts",
    "content": "import Schema from '../src';\n\ndescribe('object', () => {\n  it('works for the required object with fields in case of empty string', done => {\n    new Schema({\n      v: {\n        type: 'object',\n        required: true,\n        fields: {},\n      },\n    }).validate(\n      {\n        v: '',\n      },\n      errors => {\n        expect(errors.length).toBe(1);\n        expect(errors[0].message).toBe('v is not an object');\n        done();\n      },\n    );\n  });\n});\n"
  },
  {
    "path": "__tests__/pattern.spec.ts",
    "content": "import Schema from '../src';\n\ndescribe('pattern', () => {\n  it('works for non-required empty string', done => {\n    new Schema({\n      v: {\n        pattern: /^\\d+$/,\n        message: 'haha',\n      },\n    }).validate(\n      {\n        // useful for web, input's value defaults to ''\n        v: '',\n      },\n      errors => {\n        expect(errors).toBe(null);\n        done();\n      },\n    );\n  });\n\n  it('work for non-required empty string with string regexp', done => {\n    new Schema({\n      v: {\n        pattern: '^\\\\d+$',\n        message: 'haha',\n      },\n    }).validate(\n      {\n        // useful for web, input's value defaults to ''\n        v: 's',\n      },\n      errors => {\n        expect(errors.length).toBe(1);\n        expect(errors[0].message).toBe('haha');\n        done();\n      },\n    );\n  });\n\n  it('works for required empty string', done => {\n    new Schema({\n      v: {\n        pattern: /^\\d+$/,\n        message: 'haha',\n        required: true,\n      },\n    }).validate(\n      {\n        // useful for web, input's value defaults to ''\n        v: '',\n      },\n      errors => {\n        expect(errors.length).toBe(1);\n        expect(errors[0].message).toBe('haha');\n        done();\n      },\n    );\n  });\n\n  it('works for non-required null', done => {\n    new Schema({\n      v: {\n        pattern: /^\\d+$/,\n        message: 'haha',\n      },\n    }).validate(\n      {\n        v: null,\n      },\n      errors => {\n        expect(errors).toBe(null);\n        done();\n      },\n    );\n  });\n\n  it('works for non-required undefined', done => {\n    new Schema({\n      v: {\n        pattern: /^\\d+$/,\n        message: 'haha',\n      },\n    }).validate(\n      {\n        v: undefined,\n      },\n      errors => {\n        expect(errors).toBe(null);\n        done();\n      },\n    );\n  });\n\n  it('works', done => {\n    new Schema({\n      v: {\n        pattern: /^\\d+$/,\n        message: 'haha',\n      },\n    }).validate(\n      {\n        v: ' ',\n      },\n      errors => {\n        expect(errors.length).toBe(1);\n        expect(errors[0].message).toBe('haha');\n        done();\n      },\n    );\n  });\n\n  it('works for RegExp with global flag', done => {\n    const schema = new Schema({\n      v: {\n        pattern: /global/g,\n        message: 'haha',\n      },\n    });\n\n    schema.validate(\n      {\n        v: 'globalflag',\n      },\n      errors => {\n        expect(errors).toBe(null);\n      },\n    );\n\n    schema.validate(\n      {\n        v: 'globalflag',\n      },\n      errors => {\n        expect(errors).toBe(null);\n        done();\n      },\n    );\n  });\n});\n"
  },
  {
    "path": "__tests__/promise.spec.ts",
    "content": "import Schema from '../src';\n\ndescribe('asyncValidator', () => {\n  it('works', done => {\n    new Schema({\n      v: [\n        {\n          asyncValidator(rule, value) {\n            return Promise.reject(new Error('e1'));\n          },\n        },\n        {\n          asyncValidator(rule, value) {\n            return Promise.reject(new Error('e2'));\n          },\n        },\n      ],\n      v2: [\n        {\n          asyncValidator(rule, value) {\n            return Promise.reject(new Error('e3'));\n          },\n        },\n      ],\n    }).validate(\n      {\n        v: 2,\n      },\n      errors => {\n        expect(errors.length).toBe(3);\n        expect(errors[0].message).toBe('e1');\n        expect(errors[1].message).toBe('e2');\n        expect(errors[2].message).toBe('e3');\n        done();\n      },\n    );\n  });\n\n  it('first works', done => {\n    new Schema({\n      v: [\n        {\n          asyncValidator(rule, value) {\n            return Promise.reject(new Error('e1'));\n          },\n        },\n        {\n          asyncValidator(rule, value) {\n            return Promise.reject(new Error('e2'));\n          },\n        },\n      ],\n      v2: [\n        {\n          asyncValidator(rule, value) {\n            return Promise.reject(new Error('e3'));\n          },\n        },\n      ],\n    }).validate(\n      {\n        v: 2,\n        v2: 1,\n      },\n      {\n        first: true,\n      },\n      errors => {\n        expect(errors.length).toBe(1);\n        expect(errors[0].message).toBe('e1');\n        done();\n      },\n    );\n  });\n\n  describe('firstFields', () => {\n    it('works for true', done => {\n      new Schema({\n        v: [\n          {\n            asyncValidator(rule, value) {\n              return Promise.reject(new Error('e1'));\n            },\n          },\n          {\n            asyncValidator(rule, value) {\n              return Promise.reject(new Error('e2'));\n            },\n          },\n        ],\n\n        v2: [\n          {\n            asyncValidator(rule, value) {\n              return Promise.reject(new Error('e3'));\n            },\n          },\n        ],\n        v3: [\n          {\n            asyncValidator(rule, value) {\n              return Promise.reject(new Error('e4'));\n            },\n          },\n          {\n            asyncValidator(rule, value) {\n              return Promise.reject(new Error('e5'));\n            },\n          },\n        ],\n      }).validate(\n        {\n          v: 1,\n          v2: 1,\n          v3: 1,\n        },\n        {\n          firstFields: true,\n        },\n        errors => {\n          expect(errors.length).toBe(3);\n          expect(errors[0].message).toBe('e1');\n          expect(errors[1].message).toBe('e3');\n          expect(errors[2].message).toBe('e4');\n          done();\n        },\n      );\n    });\n\n    it('works for array', done => {\n      new Schema({\n        v: [\n          {\n            asyncValidator: (rule, value) => {\n              return Promise.reject(new Error('e1'));\n            },\n          },\n          {\n            asyncValidator(rule, value) {\n              return Promise.reject(new Error('e2'));\n            },\n          },\n        ],\n\n        v2: [\n          {\n            asyncValidator(rule, value) {\n              return Promise.reject(new Error('e3'));\n            },\n          },\n        ],\n        v3: [\n          {\n            asyncValidator(rule, value) {\n              return Promise.reject(new Error('e4'));\n            },\n          },\n          {\n            asyncValidator(rule, value) {\n              return Promise.reject(new Error('e5'));\n            },\n          },\n        ],\n        v4: [\n          {\n            asyncValidator: () =>\n              new Promise((resolve, reject) => {\n                setTimeout(resolve, 100);\n              }),\n          },\n          {\n            asyncValidator: () =>\n              new Promise((resolve, reject) => {\n                setTimeout(() => reject(new Error('e6')), 100);\n              }),\n          },\n          {\n            asyncValidator: () =>\n              new Promise((resolve, reject) => {\n                setTimeout(() => reject(new Error('')), 100);\n              }),\n          },\n        ],\n      }).validate(\n        {\n          v: 1,\n          v2: 1,\n          v3: 1,\n        },\n        {\n          firstFields: ['v'],\n        },\n        errors => {\n          expect(errors.length).toBe(6);\n          expect(errors[0].message).toBe('e1');\n          expect(errors[1].message).toBe('e3');\n          expect(errors[2].message).toBe('e4');\n          expect(errors[3].message).toBe('e5');\n          expect(errors[4].message).toBe('e6');\n          expect(errors[5].message).toBe('');\n          done();\n        },\n      );\n    });\n    it(\"Whether to remove the 'Uncaught (in promise)' warning\", async () => {\n      let allCorrect = true;\n      try {\n        await new Schema({\n          async: {\n            asyncValidator(rule, value) {\n              return new Promise((resolve, reject) => {\n                setTimeout(() => {\n                  reject([\n                    new Error(\n                      typeof rule.message === 'function'\n                        ? rule.message()\n                        : rule.message,\n                    ),\n                  ]);\n                }, 100);\n              });\n            },\n            message: 'async fails',\n          },\n        }).validate({\n          v: 1,\n        });\n      } catch ({ errors }) {\n        allCorrect = errors.length === 1;\n      }\n      expect(allCorrect).toBe(true);\n    });\n  });\n});\n"
  },
  {
    "path": "__tests__/required.spec.ts",
    "content": "import Schema from '../src';\nconst required = true;\n\ndescribe('required', () => {\n  it('works for array required=true', done => {\n    new Schema({\n      v: [\n        {\n          required,\n          message: 'no',\n        },\n      ],\n    }).validate(\n      {\n        v: [],\n      },\n      errors => {\n        expect(errors.length).toBe(1);\n        expect(errors[0].message).toBe('no');\n        done();\n      },\n    );\n  });\n\n  it('works for array required=true & custom message', done => {\n    // allow custom message\n    new Schema({\n      v: [\n        {\n          required,\n          message: 'no',\n        },\n      ],\n    }).validate(\n      {\n        v: [1],\n      },\n      errors => {\n        expect(errors).toBeFalsy();\n        done();\n      },\n    );\n  });\n\n  it('works for array required=false', done => {\n    new Schema({\n      v: {\n        required: false,\n      },\n    }).validate(\n      {\n        v: [],\n      },\n      errors => {\n        expect(errors).toBeFalsy();\n        done();\n      },\n    );\n  });\n\n  it('works for string required=true', done => {\n    new Schema({\n      v: {\n        required,\n      },\n    }).validate(\n      {\n        v: '',\n      },\n      errors => {\n        expect(errors.length).toBe(1);\n        expect(errors[0].message).toBe('v is required');\n        done();\n      },\n    );\n  });\n\n  it('works for string required=false', done => {\n    new Schema({\n      v: {\n        required: false,\n      },\n    }).validate(\n      {\n        v: '',\n      },\n      errors => {\n        expect(errors).toBeFalsy();\n        done();\n      },\n    );\n  });\n\n  it('works for number required=true', done => {\n    new Schema({\n      v: {\n        required,\n      },\n    }).validate(\n      {\n        v: 1,\n      },\n      errors => {\n        expect(errors).toBeFalsy();\n        done();\n      },\n    );\n  });\n\n  it('works for number required=false', done => {\n    new Schema({\n      v: {\n        required: false,\n      },\n    }).validate(\n      {\n        v: 1,\n      },\n      errors => {\n        expect(errors).toBeFalsy();\n        done();\n      },\n    );\n  });\n\n  it('works for null required=true', done => {\n    new Schema({\n      v: {\n        required,\n      },\n    }).validate(\n      {\n        v: null,\n      },\n      errors => {\n        expect(errors.length).toBe(1);\n        expect(errors[0].message).toBe('v is required');\n        done();\n      },\n    );\n  });\n\n  it('works for null required=false', done => {\n    new Schema({\n      v: {\n        required: false,\n      },\n    }).validate(\n      {\n        v: null,\n      },\n      errors => {\n        expect(errors).toBeFalsy();\n        done();\n      },\n    );\n  });\n\n  it('works for undefined required=true', done => {\n    new Schema({\n      v: {\n        required,\n      },\n    }).validate(\n      {\n        v: undefined,\n      },\n      errors => {\n        expect(errors.length).toBe(1);\n        expect(errors[0].message).toBe('v is required');\n        done();\n      },\n    );\n  });\n\n  it('works for undefined required=false', done => {\n    new Schema({\n      v: {\n        required: false,\n      },\n    }).validate(\n      {\n        v: undefined,\n      },\n      errors => {\n        expect(errors).toBeFalsy();\n        done();\n      },\n    );\n  });\n\n  it('should support empty string message', done => {\n    new Schema({\n      v: {\n        required,\n        message: '',\n      },\n    }).validate(\n      {\n        v: '',\n      },\n      errors => {\n        expect(errors.length).toBe(1);\n        expect(errors[0].message).toBe('');\n        done();\n      },\n    );\n  });\n});\n"
  },
  {
    "path": "__tests__/string.spec.ts",
    "content": "import Schema from '../src';\n\ndescribe('string', () => {\n  it('works for none require', done => {\n    let data = {\n      v: '',\n    };\n    new Schema({\n      v: {\n        type: 'string',\n      },\n    }).validate(data, (errors, d) => {\n      expect(errors).toBe(null);\n      expect(d).toEqual(data);\n      done();\n    });\n  });\n\n  it('works for empty string', done => {\n    new Schema({\n      v: {\n        required: true,\n        type: 'string',\n      },\n    }).validate(\n      {\n        v: '',\n      },\n      errors => {\n        expect(errors.length).toBe(1);\n        expect(errors[0].message).toBe('v is required');\n        done();\n      },\n    );\n  });\n\n  it('works for undefined string', done => {\n    new Schema({\n      v: {\n        required: true,\n        type: 'string',\n      },\n    }).validate(\n      {\n        v: undefined,\n      },\n      errors => {\n        expect(errors.length).toBe(1);\n        expect(errors[0].message).toBe('v is required');\n        done();\n      },\n    );\n  });\n\n  it('works for null string', done => {\n    new Schema({\n      v: {\n        required: true,\n        type: 'string',\n      },\n    }).validate(\n      {\n        v: null,\n      },\n      errors => {\n        expect(errors.length).toBe(1);\n        expect(errors[0].message).toBe('v is required');\n        done();\n      },\n    );\n  });\n\n  it('works for message', done => {\n    new Schema({\n      v: {\n        required: true,\n        type: 'string',\n        message: 'haha',\n      },\n    }).validate(\n      {\n        v: null,\n      },\n      errors => {\n        expect(errors.length).toBe(1);\n        expect(errors[0].message).toBe('haha');\n        done();\n      },\n    );\n  });\n\n  it('works for none empty', done => {\n    new Schema({\n      v: {\n        required: true,\n        type: 'string',\n        message: 'haha',\n      },\n    }).validate(\n      {\n        v: ' ',\n      },\n      errors => {\n        expect(errors).toBe(null);\n        done();\n      },\n    );\n  });\n\n  it('works for whitespace empty', done => {\n    new Schema({\n      v: {\n        required: true,\n        type: 'string',\n        whitespace: true,\n        message: 'haha',\n      },\n    }).validate(\n      {\n        v: ' ',\n      },\n      errors => {\n        expect(errors.length).toBe(1);\n        expect(errors[0].message).toBe('haha');\n        done();\n      },\n    );\n  });\n});\n"
  },
  {
    "path": "__tests__/unicode.spec.ts",
    "content": "import Schema from '../src';\n\ndescribe('unicode', () => {\n  it('works for unicode U+0000 to U+FFFF ', done => {\n    new Schema({\n      v: {\n        type: 'string',\n        len: 4,\n      },\n    }).validate(\n      {\n        v: '吉吉吉吉',\n      },\n      errors => {\n        expect(errors).toBe(null);\n        done();\n      },\n    );\n  });\n\n  it('works for unicode gt U+FFFF ', done => {\n    new Schema({\n      v: {\n        type: 'string',\n        len: 4, // 原来length属性应该为8，更正之后应该为4\n      },\n    }).validate(\n      {\n        v: '𠮷𠮷𠮷𠮷',\n      },\n      errors => {\n        expect(errors).toBe(null);\n        done();\n      },\n    );\n  });\n\n  it('Rich Text Format', done => {\n    new Schema({\n      v: {\n        type: 'string',\n        len: 2,\n      },\n    }).validate(\n      {\n        v: '💩💩',\n      },\n      errors => {\n        expect(errors).toBe(null);\n        done();\n      },\n    );\n  });\n});\n"
  },
  {
    "path": "__tests__/url.spec.ts",
    "content": "import Schema from '../src';\n\ndescribe('url', () => {\n  it('works for empty string', done => {\n    new Schema({\n      v: {\n        type: 'url',\n      },\n    }).validate(\n      {\n        v: '',\n      },\n      errors => {\n        expect(errors).toBe(null);\n        done();\n      },\n    );\n  });\n\n  it('works for ip url', done => {\n    new Schema({\n      v: {\n        type: 'url',\n      },\n    }).validate(\n      {\n        v: 'http://10.218.136.29/talent-tree/src/index.html',\n      },\n      errors => {\n        expect(errors).toBe(null);\n        done();\n      },\n    );\n  });\n\n  it('works for required empty string', done => {\n    new Schema({\n      v: {\n        type: 'url',\n        required: true,\n      },\n    }).validate(\n      {\n        v: '',\n      },\n      errors => {\n        expect(errors.length).toBe(1);\n        expect(errors[0].message).toBe('v is required');\n        done();\n      },\n    );\n  });\n\n  it('works for type url', done => {\n    new Schema({\n      v: {\n        type: 'url',\n      },\n    }).validate(\n      {\n        v: 'http://www.taobao.com',\n      },\n      errors => {\n        expect(errors).toBe(null);\n        done();\n      },\n    );\n  });\n\n  it('works for type url has query', done => {\n    new Schema({\n      v: {\n        type: 'url',\n      },\n    }).validate(\n      {\n        v: 'http://www.taobao.com/abc?a=a',\n      },\n      errors => {\n        expect(errors).toBe(null);\n        done();\n      },\n    );\n  });\n\n  it('works for type url has hash', done => {\n    new Schema({\n      v: {\n        type: 'url',\n      },\n    }).validate(\n      {\n        v: 'http://www.taobao.com/abc#!abc',\n      },\n      errors => {\n        expect(errors).toBe(null);\n        done();\n      },\n    );\n  });\n\n  it('works for type url has query and has', done => {\n    new Schema({\n      v: {\n        type: 'url',\n      },\n    }).validate(\n      {\n        v: 'http://www.taobao.com/abc?abc=%23&b=a~c#abc',\n      },\n      errors => {\n        expect(errors).toBe(null);\n        done();\n      },\n    );\n  });\n\n  it('works for type url has multi hyphen', done => {\n    new Schema({\n      v: {\n        type: 'url',\n      },\n    }).validate(\n      {\n        v: 'https://www.tao---bao.com',\n      },\n      errors => {\n        expect(errors).toBe(null);\n        done();\n      },\n    );\n  });\n\n  it('works for type not a valid url', done => {\n    new Schema({\n      v: {\n        type: 'url',\n      },\n    }).validate(\n      {\n        v: 'http://www.taobao.com/abc?abc=%23&b=  a~c#abc    ',\n      },\n      errors => {\n        expect(errors.length).toBe(1);\n        expect(errors[0].message).toBe('v is not a valid url');\n        done();\n      },\n    );\n  });\n\n  it('support skip schema', done => {\n    new Schema({\n      v: {\n        type: 'url',\n      },\n    }).validate(\n      {\n        v: '//g.cn',\n      },\n      errors => {\n        expect(errors).toBe(null);\n        done();\n      },\n    );\n  });\n});\n"
  },
  {
    "path": "__tests__/validator.spec.ts",
    "content": "import Schema from '../src';\n\ndescribe('validator', () => {\n  it('works', done => {\n    new Schema({\n      v: [\n        {\n          validator(rule, value, callback) {\n            callback(new Error('e1'));\n          },\n        },\n        {\n          validator(rule, value, callback) {\n            callback(new Error('e2'));\n          },\n        },\n      ],\n      v2: [\n        {\n          validator(rule, value, callback) {\n            callback(new Error('e3'));\n          },\n        },\n      ],\n      v3: [\n        {\n          validator() {\n            return false;\n          },\n        },\n        {\n          validator() {\n            return new Error('e5');\n          },\n        },\n        {\n          validator() {\n            return false;\n          },\n          message: 'e6',\n        },\n        {\n          validator() {\n            return true;\n          },\n        },\n        // Customize with empty message\n        {\n          validator() {\n            return false;\n          },\n          message: '',\n        },\n      ],\n    }).validate(\n      {\n        v: 2,\n      },\n      errors => {\n        expect(errors.length).toBe(7);\n        expect(errors[0].message).toBe('e1');\n        expect(errors[1].message).toBe('e2');\n        expect(errors[2].message).toBe('e3');\n        expect(errors[3].message).toBe('v3 fails');\n        expect(errors[4].message).toBe('e5');\n        expect(errors[5].message).toBe('e6');\n        expect(errors[6].message).toBe('');\n        done();\n      },\n    );\n  });\n\n  it('first works', done => {\n    new Schema({\n      v: [\n        {\n          validator(rule, value, callback) {\n            callback(new Error('e1'));\n          },\n        },\n        {\n          validator(rule, value, callback) {\n            callback(new Error('e2'));\n          },\n        },\n      ],\n      v2: [\n        {\n          validator(rule, value, callback) {\n            callback(new Error('e3'));\n          },\n        },\n      ],\n    }).validate(\n      {\n        v: 2,\n        v2: 1,\n      },\n      {\n        first: true,\n      },\n      errors => {\n        expect(errors.length).toBe(1);\n        expect(errors[0].message).toBe('e1');\n        done();\n      },\n    );\n  });\n\n  describe('firstFields', () => {\n    it('works for true', done => {\n      new Schema({\n        v: [\n          {\n            validator(rule, value, callback) {\n              callback(new Error('e1'));\n            },\n          },\n          {\n            validator(rule, value, callback) {\n              callback(new Error('e2'));\n            },\n          },\n        ],\n\n        v2: [\n          {\n            validator(rule, value, callback) {\n              callback(new Error('e3'));\n            },\n          },\n        ],\n        v3: [\n          {\n            validator(rule, value, callback) {\n              callback(new Error('e4'));\n            },\n          },\n          {\n            validator(rule, value, callback) {\n              callback(new Error('e5'));\n            },\n          },\n        ],\n      }).validate(\n        {\n          v: 1,\n          v2: 1,\n          v3: 1,\n        },\n        {\n          firstFields: true,\n        },\n        errors => {\n          expect(errors.length).toBe(3);\n          expect(errors[0].message).toBe('e1');\n          expect(errors[1].message).toBe('e3');\n          expect(errors[2].message).toBe('e4');\n          done();\n        },\n      );\n    });\n\n    it('works for array', done => {\n      new Schema({\n        v: [\n          {\n            validator(rule, value, callback) {\n              callback(new Error('e1'));\n            },\n          },\n          {\n            validator(rule, value, callback) {\n              callback(new Error('e2'));\n            },\n          },\n        ],\n\n        v2: [\n          {\n            validator(rule, value, callback) {\n              callback(new Error('e3'));\n            },\n          },\n        ],\n        v3: [\n          {\n            validator(rule, value, callback) {\n              callback(new Error('e4'));\n            },\n          },\n          {\n            validator(rule, value, callback) {\n              callback(new Error('e5'));\n            },\n          },\n        ],\n      }).validate(\n        {\n          v: 1,\n          v2: 1,\n          v3: 1,\n        },\n        {\n          firstFields: ['v'],\n        },\n        errors => {\n          expect(errors.length).toBe(4);\n          expect(errors[0].message).toBe('e1');\n          expect(errors[1].message).toBe('e3');\n          expect(errors[2].message).toBe('e4');\n          expect(errors[3].message).toBe('e5');\n          done();\n        },\n      );\n    });\n  });\n\n  describe('promise api', () => {\n    it('works', done => {\n      new Schema({\n        v: [\n          {\n            validator(rule, value, callback) {\n              callback(new Error('e1'));\n            },\n          },\n          {\n            validator(rule, value, callback) {\n              callback(new Error('e2'));\n            },\n          },\n        ],\n        v2: [\n          {\n            validator(rule, value, callback) {\n              callback(new Error('e3'));\n            },\n          },\n        ],\n        v3: [\n          {\n            validator() {\n              return false;\n            },\n          },\n          {\n            validator() {\n              return new Error('e5');\n            },\n          },\n          {\n            validator() {\n              return false;\n            },\n            message: 'e6',\n          },\n          {\n            validator() {\n              return true;\n            },\n          },\n        ],\n      })\n        .validate({\n          v: 2,\n        })\n        .catch(({ errors, fields }) => {\n          expect(errors.length).toBe(6);\n          expect(errors[0].message).toBe('e1');\n          expect(errors[1].message).toBe('e2');\n          expect(errors[2].message).toBe('e3');\n          expect(errors[3].message).toBe('v3 fails');\n          expect(errors[4].message).toBe('e5');\n          expect(errors[5].message).toBe('e6');\n          expect(fields.v[0].fieldValue).toBe(2);\n          expect(fields).toMatchInlineSnapshot(`\n            Object {\n              \"v\": Array [\n                [Error: e1],\n                [Error: e2],\n              ],\n              \"v2\": Array [\n                [Error: e3],\n              ],\n              \"v3\": Array [\n                Object {\n                  \"field\": \"v3\",\n                  \"fieldValue\": undefined,\n                  \"message\": \"v3 fails\",\n                },\n                Object {\n                  \"field\": \"v3\",\n                  \"fieldValue\": undefined,\n                  \"message\": \"e5\",\n                },\n                Object {\n                  \"field\": \"v3\",\n                  \"fieldValue\": undefined,\n                  \"message\": \"e6\",\n                },\n              ],\n            }\n          `);\n          done();\n        });\n    });\n\n    it('first works', done => {\n      new Schema({\n        v: [\n          {\n            validator(rule, value, callback) {\n              callback(new Error('e1'));\n            },\n          },\n          {\n            validator(rule, value, callback) {\n              callback(new Error('e2'));\n            },\n          },\n        ],\n        v2: [\n          {\n            validator(rule, value, callback) {\n              callback(new Error('e3'));\n            },\n          },\n        ],\n      })\n        .validate(\n          {\n            v: 2,\n            v2: 1,\n          },\n          {\n            first: true,\n          },\n        )\n        .catch(({ errors }) => {\n          expect(errors.length).toBe(1);\n          expect(errors[0].message).toBe('e1');\n          done();\n        });\n    });\n\n    describe('firstFields', () => {\n      it('works for true', done => {\n        new Schema({\n          v: [\n            {\n              validator(rule, value, callback) {\n                callback(new Error('e1'));\n              },\n            },\n            {\n              validator(rule, value, callback) {\n                callback(new Error('e2'));\n              },\n            },\n          ],\n\n          v2: [\n            {\n              validator(rule, value, callback) {\n                callback(new Error('e3'));\n              },\n            },\n          ],\n          v3: [\n            {\n              validator(rule, value, callback) {\n                callback(new Error('e4'));\n              },\n            },\n            {\n              validator(rule, value, callback) {\n                callback(new Error('e5'));\n              },\n            },\n          ],\n        })\n          .validate(\n            {\n              v: 1,\n              v2: 1,\n              v3: 1,\n            },\n            {\n              firstFields: true,\n            },\n          )\n          .catch(({ errors }) => {\n            expect(errors.length).toBe(3);\n            expect(errors[0].message).toBe('e1');\n            expect(errors[1].message).toBe('e3');\n            expect(errors[2].message).toBe('e4');\n            done();\n          });\n      });\n\n      it('works for array', done => {\n        new Schema({\n          v: [\n            {\n              validator(rule, value, callback) {\n                callback(new Error('e1'));\n              },\n            },\n            {\n              validator(rule, value, callback) {\n                callback(new Error('e2'));\n              },\n            },\n          ],\n\n          v2: [\n            {\n              validator(rule, value, callback) {\n                callback(new Error('e3'));\n              },\n            },\n          ],\n          v3: [\n            {\n              validator(rule, value, callback) {\n                callback(new Error('e4'));\n              },\n            },\n            {\n              validator(rule, value, callback) {\n                callback(new Error('e5'));\n              },\n            },\n          ],\n        })\n          .validate(\n            {\n              v: 1,\n              v2: 1,\n              v3: 1,\n            },\n            {\n              firstFields: ['v'],\n            },\n          )\n          .catch(({ errors }) => {\n            expect(errors.length).toBe(4);\n            expect(errors[0].message).toBe('e1');\n            expect(errors[1].message).toBe('e3');\n            expect(errors[2].message).toBe('e4');\n            expect(errors[3].message).toBe('e5');\n            done();\n          });\n      });\n\n      it('works for no rules fields', done => {\n        new Schema({\n          v: [],\n          v2: [],\n        })\n          .validate({\n            v: 2,\n            v2: 1,\n          })\n          .then(source => {\n            expect(source).toMatchObject({ v: 2, v2: 1 });\n            done();\n          });\n      });\n    });\n  });\n\n  it('custom validate function throw error', done => {\n    new Schema({\n      v: [\n        {\n          validator(rule, value, callback) {\n            throw new Error('something wrong');\n          },\n        },\n      ],\n    })\n      .validate(\n        { v: '' },\n        {\n          suppressValidatorError: true,\n        },\n      )\n      .catch(({ errors }) => {\n        expect(errors.length).toBe(1);\n        expect(errors[0].message).toBe('something wrong');\n        done();\n      });\n  });\n});\n"
  },
  {
    "path": "package.json",
    "content": "{\n  \"name\": \"async-validator\",\n  \"version\": \"4.2.5\",\n  \"description\": \"validate form asynchronous\",\n  \"typings\": \"typings/index.d.ts\",\n  \"keywords\": [\n    \"validator\",\n    \"validate\",\n    \"async\"\n  ],\n  \"homepage\": \"https://github.com/yiminghe/async-validator\",\n  \"author\": \"yiminghe@gmail.com\",\n  \"repository\": {\n    \"type\": \"git\",\n    \"url\": \"git@github.com:yiminghe/async-validator.git\"\n  },\n  \"@pika/pack\": {\n    \"pipeline\": [\n      [\n        \"pika-plugin-ts-types\",\n        {\n          \"args\": [\n            \"--rootDir\",\n            \"src\"\n          ]\n        }\n      ],\n      [\n        \"pika-plugin-build-web-babel\",\n        {\n          \"format\": \"cjs\"\n        }\n      ],\n      [\n        \"pika-plugin-build-web-babel\"\n      ]\n    ]\n  },\n  \"jest\": {\n    \"collectCoverageFrom\": [\n      \"src/*\"\n    ],\n    \"testMatch\": [\n      \"**/__tests__/**/*.spec.[j|t]s?(x)\"\n    ]\n  },\n  \"bugs\": {\n    \"url\": \"https://github.com/yiminghe/async-validator/issues\"\n  },\n  \"license\": \"MIT\",\n  \"config\": {\n    \"port\": 8010\n  },\n  \"scripts\": {\n    \"test-url\": \"yarn ts-node tests/url.ts\",\n    \"lint-staged\": \"lint-staged\",\n    \"prettier\": \"prettier --write \\\"{src,__tests__,tests}/**/*.{js,tsx,ts}\\\"\",\n    \"pub\": \"np --no-cleanup --no-publish --no-release-draft && npm run build && cd pkg && npm publish\",\n    \"build\": \"pika-pack build\",\n    \"test\": \"jest\",\n    \"test:watch\": \"jest --watch\",\n    \"test:debug\": \"node --inspect-brk node_modules/.bin/jest --runInBand\",\n    \"coverage\": \"jest --coverage && cat ./coverage/lcov.info | coveralls\",\n    \"coverage:gha\": \"jest --coverage\",\n    \"version\": \"npm run build\"\n  },\n  \"devDependencies\": {\n    \"@babel/core\": \"^7.15.0\",\n    \"@babel/node\": \"^7.14.9\",\n    \"@babel/preset-env\": \"^7.8.7\",\n    \"@babel/preset-typescript\": \"^7.13.0\",\n    \"@pika/pack\": \"^0.5.0\",\n    \"@types/jest\": \"27.x\",\n    \"babel-jest\": \"27.x\",\n    \"coveralls\": \"^2.13.1\",\n    \"jest\": \"27.x\",\n    \"lint-staged\": \"^7.2.0\",\n    \"np\": \"7.x\",\n    \"pika-plugin-build-web-babel\": \"^0.10.0\",\n    \"pika-plugin-ts-types\": \"0.1.x\",\n    \"pre-commit\": \"^1.2.2\",\n    \"prettier\": \"^1.11.1\",\n    \"ts-node\": \"^10.8.1\",\n    \"typescript\": \"^4.3.2\"\n  },\n  \"lint-staged\": {\n    \"*.{tsx,js,jsx,ts}\": [\n      \"prettier --write\",\n      \"git add\"\n    ]\n  },\n  \"pre-commit\": [\n    \"lint-staged\"\n  ],\n  \"packageManager\": \"yarn@3.2.2\"\n}\n"
  },
  {
    "path": "scripts/runTest.ts",
    "content": "import Schema, {\n  ValidateCallback,\n  ValidateFieldsError,\n  Values,\n} from '../src/index';\n\nconst callback: ValidateCallback = (errors, fields) => {\n  if (errors === null) {\n    const f: Values = fields;\n    console.log('transformed values:', JSON.stringify(f));\n  } else {\n    const f: ValidateFieldsError = fields;\n    console.log('validate error:', JSON.stringify(f));\n  }\n};\n\nnew Schema({\n  v: {\n    required: true,\n    type: 'array',\n    defaultField: [{ type: 'number', max: 0, transform: i => Number(i) }],\n  },\n}).validate(\n  {\n    v: ['1', '2'],\n  },\n  callback,\n);\n"
  },
  {
    "path": "scripts/test.sh",
    "content": "NODE_ENV=test npx babel-node -x \".ts,.js,.jsx\" scripts/runTest.ts"
  },
  {
    "path": "src/index.ts",
    "content": "import {\n  format,\n  complementError,\n  asyncMap,\n  warning,\n  deepMerge,\n  convertFieldsError,\n} from './util';\nimport validators from './validator/index';\nimport { messages as defaultMessages, newMessages } from './messages';\nimport {\n  InternalRuleItem,\n  InternalValidateMessages,\n  Rule,\n  RuleItem,\n  Rules,\n  ValidateCallback,\n  ValidateMessages,\n  ValidateOption,\n  Values,\n  RuleValuePackage,\n  ValidateError,\n  ValidateFieldsError,\n  SyncErrorType,\n  ValidateResult,\n} from './interface';\n\nexport * from './interface';\n\n/**\n *  Encapsulates a validation schema.\n *\n *  @param descriptor An object declaring validation rules\n *  for this schema.\n */\nclass Schema {\n  // ========================= Static =========================\n  static register = function register(type: string, validator) {\n    if (typeof validator !== 'function') {\n      throw new Error(\n        'Cannot register a validator by type, validator is not a function',\n      );\n    }\n    validators[type] = validator;\n  };\n\n  static warning = warning;\n\n  static messages = defaultMessages;\n\n  static validators = validators;\n\n  // ======================== Instance ========================\n  rules: Record<string, RuleItem[]> = null;\n  _messages: InternalValidateMessages = defaultMessages;\n\n  constructor(descriptor: Rules) {\n    this.define(descriptor);\n  }\n\n  define(rules: Rules) {\n    if (!rules) {\n      throw new Error('Cannot configure a schema with no rules');\n    }\n    if (typeof rules !== 'object' || Array.isArray(rules)) {\n      throw new Error('Rules must be an object');\n    }\n    this.rules = {};\n\n    Object.keys(rules).forEach(name => {\n      const item: Rule = rules[name];\n      this.rules[name] = Array.isArray(item) ? item : [item];\n    });\n  }\n\n  messages(messages?: ValidateMessages) {\n    if (messages) {\n      this._messages = deepMerge(newMessages(), messages);\n    }\n    return this._messages;\n  }\n\n  validate(\n    source: Values,\n    option?: ValidateOption,\n    callback?: ValidateCallback,\n  ): Promise<Values>;\n  validate(source: Values, callback: ValidateCallback): Promise<Values>;\n  validate(source: Values): Promise<Values>;\n\n  validate(source_: Values, o: any = {}, oc: any = () => {}): Promise<Values> {\n    let source: Values = source_;\n    let options: ValidateOption = o;\n    let callback: ValidateCallback = oc;\n    if (typeof options === 'function') {\n      callback = options;\n      options = {};\n    }\n    if (!this.rules || Object.keys(this.rules).length === 0) {\n      if (callback) {\n        callback(null, source);\n      }\n      return Promise.resolve(source);\n    }\n\n    function complete(results: (ValidateError | ValidateError[])[]) {\n      let errors: ValidateError[] = [];\n      let fields: ValidateFieldsError = {};\n\n      function add(e: ValidateError | ValidateError[]) {\n        if (Array.isArray(e)) {\n          errors = errors.concat(...e);\n        } else {\n          errors.push(e);\n        }\n      }\n\n      for (let i = 0; i < results.length; i++) {\n        add(results[i]);\n      }\n      if (!errors.length) {\n        callback(null, source);\n      } else {\n        fields = convertFieldsError(errors);\n        (callback as (\n          errors: ValidateError[],\n          fields: ValidateFieldsError,\n        ) => void)(errors, fields);\n      }\n    }\n\n    if (options.messages) {\n      let messages = this.messages();\n      if (messages === defaultMessages) {\n        messages = newMessages();\n      }\n      deepMerge(messages, options.messages);\n      options.messages = messages;\n    } else {\n      options.messages = this.messages();\n    }\n\n    const series: Record<string, RuleValuePackage[]> = {};\n    const keys = options.keys || Object.keys(this.rules);\n    keys.forEach(z => {\n      const arr = this.rules[z];\n      let value = source[z];\n      arr.forEach(r => {\n        let rule: InternalRuleItem = r;\n        if (typeof rule.transform === 'function') {\n          if (source === source_) {\n            source = { ...source };\n          }\n          value = source[z] = rule.transform(value);\n        }\n        if (typeof rule === 'function') {\n          rule = {\n            validator: rule,\n          };\n        } else {\n          rule = { ...rule };\n        }\n\n        // Fill validator. Skip if nothing need to validate\n        rule.validator = this.getValidationMethod(rule);\n        if (!rule.validator) {\n          return;\n        }\n\n        rule.field = z;\n        rule.fullField = rule.fullField || z;\n        rule.type = this.getType(rule);\n        series[z] = series[z] || [];\n        series[z].push({\n          rule,\n          value,\n          source,\n          field: z,\n        });\n      });\n    });\n    const errorFields = {};\n    return asyncMap(\n      series,\n      options,\n      (data, doIt) => {\n        const rule = data.rule;\n        let deep =\n          (rule.type === 'object' || rule.type === 'array') &&\n          (typeof rule.fields === 'object' ||\n            typeof rule.defaultField === 'object');\n        deep = deep && (rule.required || (!rule.required && data.value));\n        rule.field = data.field;\n\n        function addFullField(key: string, schema: RuleItem) {\n          return {\n            ...schema,\n            fullField: `${rule.fullField}.${key}`,\n            fullFields: rule.fullFields ? [...rule.fullFields, key] : [key],\n          };\n        }\n\n        function cb(e: SyncErrorType | SyncErrorType[] = []) {\n          let errorList = Array.isArray(e) ? e : [e];\n          if (!options.suppressWarning && errorList.length) {\n            Schema.warning('async-validator:', errorList);\n          }\n          if (errorList.length && rule.message !== undefined) {\n            errorList = [].concat(rule.message);\n          }\n\n          // Fill error info\n          let filledErrors = errorList.map(complementError(rule, source));\n\n          if (options.first && filledErrors.length) {\n            errorFields[rule.field] = 1;\n            return doIt(filledErrors);\n          }\n          if (!deep) {\n            doIt(filledErrors);\n          } else {\n            // if rule is required but the target object\n            // does not exist fail at the rule level and don't\n            // go deeper\n            if (rule.required && !data.value) {\n              if (rule.message !== undefined) {\n                filledErrors = []\n                  .concat(rule.message)\n                  .map(complementError(rule, source));\n              } else if (options.error) {\n                filledErrors = [\n                  options.error(\n                    rule,\n                    format(options.messages.required, rule.field),\n                  ),\n                ];\n              }\n              return doIt(filledErrors);\n            }\n\n            let fieldsSchema: Record<string, Rule> = {};\n            if (rule.defaultField) {\n              Object.keys(data.value).map(key => {\n                fieldsSchema[key] = rule.defaultField;\n              });\n            }\n            fieldsSchema = {\n              ...fieldsSchema,\n              ...data.rule.fields,\n            };\n\n            const paredFieldsSchema: Record<string, RuleItem[]> = {};\n\n            Object.keys(fieldsSchema).forEach(field => {\n              const fieldSchema = fieldsSchema[field];\n              const fieldSchemaList = Array.isArray(fieldSchema)\n                ? fieldSchema\n                : [fieldSchema];\n              paredFieldsSchema[field] = fieldSchemaList.map(\n                addFullField.bind(null, field),\n              );\n            });\n            const schema = new Schema(paredFieldsSchema);\n            schema.messages(options.messages);\n            if (data.rule.options) {\n              data.rule.options.messages = options.messages;\n              data.rule.options.error = options.error;\n            }\n            schema.validate(data.value, data.rule.options || options, errs => {\n              const finalErrors = [];\n              if (filledErrors && filledErrors.length) {\n                finalErrors.push(...filledErrors);\n              }\n              if (errs && errs.length) {\n                finalErrors.push(...errs);\n              }\n              doIt(finalErrors.length ? finalErrors : null);\n            });\n          }\n        }\n\n        let res: ValidateResult;\n        if (rule.asyncValidator) {\n          res = rule.asyncValidator(rule, data.value, cb, data.source, options);\n        } else if (rule.validator) {\n          try {\n            res = rule.validator(rule, data.value, cb, data.source, options);\n          } catch (error) {\n            console.error?.(error);\n            // rethrow to report error\n            if (!options.suppressValidatorError) {\n              setTimeout(() => {\n                throw error;\n              }, 0);\n            }\n            cb(error.message);\n          }\n          if (res === true) {\n            cb();\n          } else if (res === false) {\n            cb(\n              typeof rule.message === 'function'\n                ? rule.message(rule.fullField || rule.field)\n                : rule.message || `${rule.fullField || rule.field} fails`,\n            );\n          } else if (res instanceof Array) {\n            cb(res);\n          } else if (res instanceof Error) {\n            cb(res.message);\n          }\n        }\n        if (res && (res as Promise<void>).then) {\n          (res as Promise<void>).then(\n            () => cb(),\n            e => cb(e),\n          );\n        }\n      },\n      results => {\n        complete(results);\n      },\n      source,\n    );\n  }\n\n  getType(rule: InternalRuleItem) {\n    if (rule.type === undefined && rule.pattern instanceof RegExp) {\n      rule.type = 'pattern';\n    }\n    if (\n      typeof rule.validator !== 'function' &&\n      rule.type &&\n      !validators.hasOwnProperty(rule.type)\n    ) {\n      throw new Error(format('Unknown rule type %s', rule.type));\n    }\n    return rule.type || 'string';\n  }\n\n  getValidationMethod(rule: InternalRuleItem) {\n    if (typeof rule.validator === 'function') {\n      return rule.validator;\n    }\n    const keys = Object.keys(rule);\n    const messageIndex = keys.indexOf('message');\n    if (messageIndex !== -1) {\n      keys.splice(messageIndex, 1);\n    }\n    if (keys.length === 1 && keys[0] === 'required') {\n      return validators.required;\n    }\n    return validators[this.getType(rule)] || undefined;\n  }\n}\n\nexport default Schema;\n"
  },
  {
    "path": "src/interface.ts",
    "content": "// >>>>> Rule\n// Modified from https://github.com/yiminghe/async-validator/blob/0d51d60086a127b21db76f44dff28ae18c165c47/src/index.d.ts\nexport type RuleType =\n  | 'string'\n  | 'number'\n  | 'boolean'\n  | 'method'\n  | 'regexp'\n  | 'integer'\n  | 'float'\n  | 'array'\n  | 'object'\n  | 'enum'\n  | 'date'\n  | 'url'\n  | 'hex'\n  | 'email'\n  | 'pattern'\n  | 'any';\n\nexport interface ValidateOption {\n  // whether to suppress internal warning\n  suppressWarning?: boolean;\n\n  // whether to suppress validator error\n  suppressValidatorError?: boolean;\n\n  // when the first validation rule generates an error stop processed\n  first?: boolean;\n\n  // when the first validation rule of the specified field generates an error stop the field processed, 'true' means all fields.\n  firstFields?: boolean | string[];\n\n  messages?: Partial<ValidateMessages>;\n\n  /** The name of rules need to be trigger. Will validate all rules if leave empty */\n  keys?: string[];\n\n  error?: (rule: InternalRuleItem, message: string) => ValidateError;\n}\n\nexport type SyncErrorType = Error | string;\nexport type SyncValidateResult = boolean | SyncErrorType | SyncErrorType[];\nexport type ValidateResult = void | Promise<void> | SyncValidateResult;\n\nexport interface RuleItem {\n  type?: RuleType; // default type is 'string'\n  required?: boolean;\n  pattern?: RegExp | string;\n  min?: number; // Range of type 'string' and 'array'\n  max?: number; // Range of type 'string' and 'array'\n  len?: number; // Length of type 'string' and 'array'\n  enum?: Array<string | number | boolean | null | undefined>; // possible values of type 'enum'\n  whitespace?: boolean;\n  fields?: Record<string, Rule>; // ignore when without required\n  options?: ValidateOption;\n  defaultField?: Rule; // 'object' or 'array' containing validation rules\n  transform?: (value: Value) => Value;\n  message?: string | ((a?: string) => string);\n  asyncValidator?: (\n    rule: InternalRuleItem,\n    value: Value,\n    callback: (error?: string | Error) => void,\n    source: Values,\n    options: ValidateOption,\n  ) => void | Promise<void>;\n  validator?: (\n    rule: InternalRuleItem,\n    value: Value,\n    callback: (error?: string | Error) => void,\n    source: Values,\n    options: ValidateOption,\n  ) => SyncValidateResult | void;\n}\n\nexport type Rule = RuleItem | RuleItem[];\n\nexport type Rules = Record<string, Rule>;\n\n/**\n *  Rule for validating a value exists in an enumerable list.\n *\n *  @param rule The validation rule.\n *  @param value The value of the field on the source object.\n *  @param source The source object being validated.\n *  @param errors An array of errors that this rule may add\n *  validation errors to.\n *  @param options The validation options.\n *  @param options.messages The validation messages.\n *  @param type Rule type\n */\nexport type ExecuteRule = (\n  rule: InternalRuleItem,\n  value: Value,\n  source: Values,\n  errors: string[],\n  options: ValidateOption,\n  type?: string,\n) => void;\n\n/**\n *  Performs validation for any type.\n *\n *  @param rule The validation rule.\n *  @param value The value of the field on the source object.\n *  @param callback The callback function.\n *  @param source The source object being validated.\n *  @param options The validation options.\n *  @param options.messages The validation messages.\n */\nexport type ExecuteValidator = (\n  rule: InternalRuleItem,\n  value: Value,\n  callback: (error?: string[]) => void,\n  source: Values,\n  options: ValidateOption,\n) => void;\n\n// >>>>> Message\ntype ValidateMessage<T extends any[] = unknown[]> =\n  | string\n  | ((...args: T) => string);\ntype FullField = string | undefined;\ntype EnumString = string | undefined;\ntype Pattern = string | RegExp | undefined;\ntype Range = number | undefined;\ntype Type = string | undefined;\n\nexport interface ValidateMessages {\n  default?: ValidateMessage;\n  required?: ValidateMessage<[FullField]>;\n  enum?: ValidateMessage<[FullField, EnumString]>;\n  whitespace?: ValidateMessage<[FullField]>;\n  date?: {\n    format?: ValidateMessage;\n    parse?: ValidateMessage;\n    invalid?: ValidateMessage;\n  };\n  types?: {\n    string?: ValidateMessage<[FullField, Type]>;\n    method?: ValidateMessage<[FullField, Type]>;\n    array?: ValidateMessage<[FullField, Type]>;\n    object?: ValidateMessage<[FullField, Type]>;\n    number?: ValidateMessage<[FullField, Type]>;\n    date?: ValidateMessage<[FullField, Type]>;\n    boolean?: ValidateMessage<[FullField, Type]>;\n    integer?: ValidateMessage<[FullField, Type]>;\n    float?: ValidateMessage<[FullField, Type]>;\n    regexp?: ValidateMessage<[FullField, Type]>;\n    email?: ValidateMessage<[FullField, Type]>;\n    url?: ValidateMessage<[FullField, Type]>;\n    hex?: ValidateMessage<[FullField, Type]>;\n  };\n  string?: {\n    len?: ValidateMessage<[FullField, Range]>;\n    min?: ValidateMessage<[FullField, Range]>;\n    max?: ValidateMessage<[FullField, Range]>;\n    range?: ValidateMessage<[FullField, Range, Range]>;\n  };\n  number?: {\n    len?: ValidateMessage<[FullField, Range]>;\n    min?: ValidateMessage<[FullField, Range]>;\n    max?: ValidateMessage<[FullField, Range]>;\n    range?: ValidateMessage<[FullField, Range, Range]>;\n  };\n  array?: {\n    len?: ValidateMessage<[FullField, Range]>;\n    min?: ValidateMessage<[FullField, Range]>;\n    max?: ValidateMessage<[FullField, Range]>;\n    range?: ValidateMessage<[FullField, Range, Range]>;\n  };\n  pattern?: {\n    mismatch?: ValidateMessage<[FullField, Value, Pattern]>;\n  };\n}\n\nexport interface InternalValidateMessages extends ValidateMessages {\n  clone: () => InternalValidateMessages;\n}\n\n// >>>>> Values\nexport type Value = any;\nexport type Values = Record<string, Value>;\n\n// >>>>> Validate\nexport interface ValidateError {\n  message?: string;\n  fieldValue?: Value;\n  field?: string;\n}\n\nexport type ValidateFieldsError = Record<string, ValidateError[]>;\n\nexport type ValidateCallback = (\n  errors: ValidateError[] | null,\n  fields: ValidateFieldsError | Values,\n) => void;\n\nexport interface RuleValuePackage {\n  rule: InternalRuleItem;\n  value: Value;\n  source: Values;\n  field: string;\n}\n\nexport interface InternalRuleItem extends Omit<RuleItem, 'validator'> {\n  field?: string;\n  fullField?: string;\n  fullFields?: string[];\n  validator?: RuleItem['validator'] | ExecuteValidator;\n}\n"
  },
  {
    "path": "src/messages.ts",
    "content": "import { InternalValidateMessages } from './interface';\n\nexport function newMessages(): InternalValidateMessages {\n  return {\n    default: 'Validation error on field %s',\n    required: '%s is required',\n    enum: '%s must be one of %s',\n    whitespace: '%s cannot be empty',\n    date: {\n      format: '%s date %s is invalid for format %s',\n      parse: '%s date could not be parsed, %s is invalid ',\n      invalid: '%s date %s is invalid',\n    },\n    types: {\n      string: '%s is not a %s',\n      method: '%s is not a %s (function)',\n      array: '%s is not an %s',\n      object: '%s is not an %s',\n      number: '%s is not a %s',\n      date: '%s is not a %s',\n      boolean: '%s is not a %s',\n      integer: '%s is not an %s',\n      float: '%s is not a %s',\n      regexp: '%s is not a valid %s',\n      email: '%s is not a valid %s',\n      url: '%s is not a valid %s',\n      hex: '%s is not a valid %s',\n    },\n    string: {\n      len: '%s must be exactly %s characters',\n      min: '%s must be at least %s characters',\n      max: '%s cannot be longer than %s characters',\n      range: '%s must be between %s and %s characters',\n    },\n    number: {\n      len: '%s must equal %s',\n      min: '%s cannot be less than %s',\n      max: '%s cannot be greater than %s',\n      range: '%s must be between %s and %s',\n    },\n    array: {\n      len: '%s must be exactly %s in length',\n      min: '%s cannot be less than %s in length',\n      max: '%s cannot be greater than %s in length',\n      range: '%s must be between %s and %s in length',\n    },\n    pattern: {\n      mismatch: '%s value %s does not match pattern %s',\n    },\n    clone() {\n      const cloned = JSON.parse(JSON.stringify(this));\n      cloned.clone = this.clone;\n      return cloned;\n    },\n  };\n}\n\nexport const messages = newMessages();\n"
  },
  {
    "path": "src/rule/enum.ts",
    "content": "import { ExecuteRule } from '../interface';\nimport { format } from '../util';\n\nconst ENUM = 'enum' as const;\n\nconst enumerable: ExecuteRule = (rule, value, source, errors, options) => {\n  rule[ENUM] = Array.isArray(rule[ENUM]) ? rule[ENUM] : [];\n  if (rule[ENUM].indexOf(value) === -1) {\n    errors.push(\n      format(options.messages[ENUM], rule.fullField, rule[ENUM].join(', ')),\n    );\n  }\n};\n\nexport default enumerable;\n"
  },
  {
    "path": "src/rule/index.ts",
    "content": "import required from './required';\nimport whitespace from './whitespace';\nimport type from './type';\nimport range from './range';\nimport enumRule from './enum';\nimport pattern from './pattern';\n\nexport default {\n  required,\n  whitespace,\n  type,\n  range,\n  enum: enumRule,\n  pattern,\n};\n"
  },
  {
    "path": "src/rule/pattern.ts",
    "content": "import { ExecuteRule } from '../interface';\nimport { format } from '../util';\n\nconst pattern: ExecuteRule = (rule, value, source, errors, options) => {\n  if (rule.pattern) {\n    if (rule.pattern instanceof RegExp) {\n      // if a RegExp instance is passed, reset `lastIndex` in case its `global`\n      // flag is accidentally set to `true`, which in a validation scenario\n      // is not necessary and the result might be misleading\n      rule.pattern.lastIndex = 0;\n      if (!rule.pattern.test(value)) {\n        errors.push(\n          format(\n            options.messages.pattern.mismatch,\n            rule.fullField,\n            value,\n            rule.pattern,\n          ),\n        );\n      }\n    } else if (typeof rule.pattern === 'string') {\n      const _pattern = new RegExp(rule.pattern);\n      if (!_pattern.test(value)) {\n        errors.push(\n          format(\n            options.messages.pattern.mismatch,\n            rule.fullField,\n            value,\n            rule.pattern,\n          ),\n        );\n      }\n    }\n  }\n};\n\nexport default pattern;\n"
  },
  {
    "path": "src/rule/range.ts",
    "content": "import { ExecuteRule } from '../interface';\nimport { format } from '../util';\n\nconst range: ExecuteRule = (rule, value, source, errors, options) => {\n  const len = typeof rule.len === 'number';\n  const min = typeof rule.min === 'number';\n  const max = typeof rule.max === 'number';\n  // 正则匹配码点范围从U+010000一直到U+10FFFF的文字（补充平面Supplementary Plane）\n  const spRegexp = /[\\uD800-\\uDBFF][\\uDC00-\\uDFFF]/g;\n  let val = value;\n  let key = null;\n  const num = typeof value === 'number';\n  const str = typeof value === 'string';\n  const arr = Array.isArray(value);\n  if (num) {\n    key = 'number';\n  } else if (str) {\n    key = 'string';\n  } else if (arr) {\n    key = 'array';\n  }\n  // if the value is not of a supported type for range validation\n  // the validation rule rule should use the\n  // type property to also test for a particular type\n  if (!key) {\n    return false;\n  }\n  if (arr) {\n    val = value.length;\n  }\n  if (str) {\n    // 处理码点大于U+010000的文字length属性不准确的bug，如\"𠮷𠮷𠮷\".length !== 3\n    val = value.replace(spRegexp, '_').length;\n  }\n  if (len) {\n    if (val !== rule.len) {\n      errors.push(format(options.messages[key].len, rule.fullField, rule.len));\n    }\n  } else if (min && !max && val < rule.min) {\n    errors.push(format(options.messages[key].min, rule.fullField, rule.min));\n  } else if (max && !min && val > rule.max) {\n    errors.push(format(options.messages[key].max, rule.fullField, rule.max));\n  } else if (min && max && (val < rule.min || val > rule.max)) {\n    errors.push(\n      format(options.messages[key].range, rule.fullField, rule.min, rule.max),\n    );\n  }\n};\n\nexport default range;\n"
  },
  {
    "path": "src/rule/required.ts",
    "content": "import { ExecuteRule } from '../interface';\nimport { format, isEmptyValue } from '../util';\n\nconst required: ExecuteRule = (rule, value, source, errors, options, type) => {\n  if (\n    rule.required &&\n    (!source.hasOwnProperty(rule.field) ||\n      isEmptyValue(value, type || rule.type))\n  ) {\n    errors.push(format(options.messages.required, rule.fullField));\n  }\n};\n\nexport default required;\n"
  },
  {
    "path": "src/rule/type.ts",
    "content": "import { ExecuteRule, Value } from '../interface';\nimport { format } from '../util';\nimport required from './required';\nimport getUrlRegex from './url';\n/* eslint max-len:0 */\n\nconst pattern = {\n  // http://emailregex.com/\n  email: /^(([^<>()\\[\\]\\\\.,;:\\s@\"]+(\\.[^<>()\\[\\]\\\\.,;:\\s@\"]+)*)|(\".+\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}])|(([a-zA-Z\\-0-9\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF]+\\.)+[a-zA-Z\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF]{2,}))$/,\n  // url: new RegExp(\n  //   '^(?!mailto:)(?:(?:http|https|ftp)://|//)(?:\\\\S+(?::\\\\S*)?@)?(?:(?:(?:[1-9]\\\\d?|1\\\\d\\\\d|2[01]\\\\d|22[0-3])(?:\\\\.(?:1?\\\\d{1,2}|2[0-4]\\\\d|25[0-5])){2}(?:\\\\.(?:[0-9]\\\\d?|1\\\\d\\\\d|2[0-4]\\\\d|25[0-4]))|(?:(?:[a-z\\\\u00a1-\\\\uffff0-9]+-*)*[a-z\\\\u00a1-\\\\uffff0-9]+)(?:\\\\.(?:[a-z\\\\u00a1-\\\\uffff0-9]+-*)*[a-z\\\\u00a1-\\\\uffff0-9]+)*(?:\\\\.(?:[a-z\\\\u00a1-\\\\uffff]{2,})))|localhost)(?::\\\\d{2,5})?(?:(/|\\\\?|#)[^\\\\s]*)?$',\n  //   'i',\n  // ),\n  hex: /^#?([a-f0-9]{6}|[a-f0-9]{3})$/i,\n};\n\nconst types = {\n  integer(value: Value) {\n    return types.number(value) && parseInt(value, 10) === value;\n  },\n  float(value: Value) {\n    return types.number(value) && !types.integer(value);\n  },\n  array(value: Value) {\n    return Array.isArray(value);\n  },\n  regexp(value: Value) {\n    if (value instanceof RegExp) {\n      return true;\n    }\n    try {\n      return !!new RegExp(value);\n    } catch (e) {\n      return false;\n    }\n  },\n  date(value: Value) {\n    return (\n      typeof value.getTime === 'function' &&\n      typeof value.getMonth === 'function' &&\n      typeof value.getYear === 'function' &&\n      !isNaN(value.getTime())\n    );\n  },\n  number(value: Value) {\n    if (isNaN(value)) {\n      return false;\n    }\n    return typeof value === 'number';\n  },\n  object(value: Value) {\n    return typeof value === 'object' && !types.array(value);\n  },\n  method(value: Value) {\n    return typeof value === 'function';\n  },\n  email(value: Value) {\n    return (\n      typeof value === 'string' &&\n      value.length <= 320 &&\n      !!value.match(pattern.email)\n    );\n  },\n  url(value: Value) {\n    return (\n      typeof value === 'string' &&\n      value.length <= 2048 &&\n      !!value.match(getUrlRegex())\n    );\n  },\n  hex(value: Value) {\n    return typeof value === 'string' && !!value.match(pattern.hex);\n  },\n};\n\nconst type: ExecuteRule = (rule, value, source, errors, options) => {\n  if (rule.required && value === undefined) {\n    required(rule, value, source, errors, options);\n    return;\n  }\n  const custom = [\n    'integer',\n    'float',\n    'array',\n    'regexp',\n    'object',\n    'method',\n    'email',\n    'number',\n    'date',\n    'url',\n    'hex',\n  ];\n  const ruleType = rule.type;\n  if (custom.indexOf(ruleType) > -1) {\n    if (!types[ruleType](value)) {\n      errors.push(\n        format(options.messages.types[ruleType], rule.fullField, rule.type),\n      );\n    }\n    // straight typeof check\n  } else if (ruleType && typeof value !== rule.type) {\n    errors.push(\n      format(options.messages.types[ruleType], rule.fullField, rule.type),\n    );\n  }\n};\n\nexport default type;\n"
  },
  {
    "path": "src/rule/url.ts",
    "content": "// https://github.com/kevva/url-regex/blob/master/index.js\nlet urlReg: RegExp;\n\nexport default () => {\n  if (urlReg) {\n    return urlReg;\n  }\n\n  const word = '[a-fA-F\\\\d:]';\n  const b = options =>\n    options && options.includeBoundaries\n      ? `(?:(?<=\\\\s|^)(?=${word})|(?<=${word})(?=\\\\s|$))`\n      : '';\n\n  const v4 =\n    '(?:25[0-5]|2[0-4]\\\\d|1\\\\d\\\\d|[1-9]\\\\d|\\\\d)(?:\\\\.(?:25[0-5]|2[0-4]\\\\d|1\\\\d\\\\d|[1-9]\\\\d|\\\\d)){3}';\n\n  const v6seg = '[a-fA-F\\\\d]{1,4}';\n  const v6 = `\n(?:\n(?:${v6seg}:){7}(?:${v6seg}|:)|                                    // 1:2:3:4:5:6:7::  1:2:3:4:5:6:7:8\n(?:${v6seg}:){6}(?:${v4}|:${v6seg}|:)|                             // 1:2:3:4:5:6::    1:2:3:4:5:6::8   1:2:3:4:5:6::8  1:2:3:4:5:6::1.2.3.4\n(?:${v6seg}:){5}(?::${v4}|(?::${v6seg}){1,2}|:)|                   // 1:2:3:4:5::      1:2:3:4:5::7:8   1:2:3:4:5::8    1:2:3:4:5::7:1.2.3.4\n(?:${v6seg}:){4}(?:(?::${v6seg}){0,1}:${v4}|(?::${v6seg}){1,3}|:)| // 1:2:3:4::        1:2:3:4::6:7:8   1:2:3:4::8      1:2:3:4::6:7:1.2.3.4\n(?:${v6seg}:){3}(?:(?::${v6seg}){0,2}:${v4}|(?::${v6seg}){1,4}|:)| // 1:2:3::          1:2:3::5:6:7:8   1:2:3::8        1:2:3::5:6:7:1.2.3.4\n(?:${v6seg}:){2}(?:(?::${v6seg}){0,3}:${v4}|(?::${v6seg}){1,5}|:)| // 1:2::            1:2::4:5:6:7:8   1:2::8          1:2::4:5:6:7:1.2.3.4\n(?:${v6seg}:){1}(?:(?::${v6seg}){0,4}:${v4}|(?::${v6seg}){1,6}|:)| // 1::              1::3:4:5:6:7:8   1::8            1::3:4:5:6:7:1.2.3.4\n(?::(?:(?::${v6seg}){0,5}:${v4}|(?::${v6seg}){1,7}|:))             // ::2:3:4:5:6:7:8  ::2:3:4:5:6:7:8  ::8             ::1.2.3.4\n)(?:%[0-9a-zA-Z]{1,})?                                             // %eth0            %1\n`\n    .replace(/\\s*\\/\\/.*$/gm, '')\n    .replace(/\\n/g, '')\n    .trim();\n\n  // Pre-compile only the exact regexes because adding a global flag make regexes stateful\n  const v46Exact = new RegExp(`(?:^${v4}$)|(?:^${v6}$)`);\n  const v4exact = new RegExp(`^${v4}$`);\n  const v6exact = new RegExp(`^${v6}$`);\n\n  const ip = options =>\n    options && options.exact\n      ? v46Exact\n      : new RegExp(\n          `(?:${b(options)}${v4}${b(options)})|(?:${b(options)}${v6}${b(\n            options,\n          )})`,\n          'g',\n        );\n\n  ip.v4 = (options?) =>\n    options && options.exact\n      ? v4exact\n      : new RegExp(`${b(options)}${v4}${b(options)}`, 'g');\n  ip.v6 = (options?) =>\n    options && options.exact\n      ? v6exact\n      : new RegExp(`${b(options)}${v6}${b(options)}`, 'g');\n\n  const protocol = `(?:(?:[a-z]+:)?//)`;\n  const auth = '(?:\\\\S+(?::\\\\S*)?@)?';\n  const ipv4 = ip.v4().source;\n  const ipv6 = ip.v6().source;\n  const host = '(?:(?:[a-z\\\\u00a1-\\\\uffff0-9][-_]*)*[a-z\\\\u00a1-\\\\uffff0-9]+)';\n  const domain =\n    '(?:\\\\.(?:[a-z\\\\u00a1-\\\\uffff0-9]-*)*[a-z\\\\u00a1-\\\\uffff0-9]+)*';\n  const tld = `(?:\\\\.(?:[a-z\\\\u00a1-\\\\uffff]{2,}))`;\n  const port = '(?::\\\\d{2,5})?';\n  const path = '(?:[/?#][^\\\\s\"]*)?';\n  const regex = `(?:${protocol}|www\\\\.)${auth}(?:localhost|${ipv4}|${ipv6}|${host}${domain}${tld})${port}${path}`;\n  urlReg = new RegExp(`(?:^${regex}$)`, 'i');\n  return urlReg;\n};\n"
  },
  {
    "path": "src/rule/whitespace.ts",
    "content": "import { ExecuteRule } from '../interface';\nimport { format } from '../util';\n\n/**\n *  Rule for validating whitespace.\n *\n *  @param rule The validation rule.\n *  @param value The value of the field on the source object.\n *  @param source The source object being validated.\n *  @param errors An array of errors that this rule may add\n *  validation errors to.\n *  @param options The validation options.\n *  @param options.messages The validation messages.\n */\nconst whitespace: ExecuteRule = (rule, value, source, errors, options) => {\n  if (/^\\s+$/.test(value) || value === '') {\n    errors.push(format(options.messages.whitespace, rule.fullField));\n  }\n};\n\nexport default whitespace;\n"
  },
  {
    "path": "src/util.ts",
    "content": "/* eslint no-console:0 */\n\nimport {\n  ValidateError,\n  ValidateOption,\n  RuleValuePackage,\n  InternalRuleItem,\n  SyncErrorType,\n  RuleType,\n  Value,\n  Values,\n} from './interface';\n\nconst formatRegExp = /%[sdj%]/g;\n\ndeclare var ASYNC_VALIDATOR_NO_WARNING;\n\nexport let warning: (type: string, errors: SyncErrorType[]) => void = () => {};\n\n// don't print warning message when in production env or node runtime\nif (\n  typeof process !== 'undefined' &&\n  process.env &&\n  process.env.NODE_ENV !== 'production' &&\n  typeof window !== 'undefined' &&\n  typeof document !== 'undefined'\n) {\n  warning = (type, errors) => {\n    if (\n      typeof console !== 'undefined' &&\n      console.warn &&\n      typeof ASYNC_VALIDATOR_NO_WARNING === 'undefined'\n    ) {\n      if (errors.every(e => typeof e === 'string')) {\n        console.warn(type, errors);\n      }\n    }\n  };\n}\n\nexport function convertFieldsError(\n  errors: ValidateError[],\n): Record<string, ValidateError[]> {\n  if (!errors || !errors.length) return null;\n  const fields = {};\n  errors.forEach(error => {\n    const field = error.field;\n    fields[field] = fields[field] || [];\n    fields[field].push(error);\n  });\n  return fields;\n}\n\nexport function format(\n  template: ((...args: any[]) => string) | string,\n  ...args: any[]\n): string {\n  let i = 0;\n  const len = args.length;\n  if (typeof template === 'function') {\n    return template.apply(null, args);\n  }\n  if (typeof template === 'string') {\n    let str = template.replace(formatRegExp, x => {\n      if (x === '%%') {\n        return '%';\n      }\n      if (i >= len) {\n        return x;\n      }\n      switch (x) {\n        case '%s':\n          return String(args[i++]);\n        case '%d':\n          return (Number(args[i++]) as unknown) as string;\n        case '%j':\n          try {\n            return JSON.stringify(args[i++]);\n          } catch (_) {\n            return '[Circular]';\n          }\n          break;\n        default:\n          return x;\n      }\n    });\n    return str;\n  }\n  return template;\n}\n\nfunction isNativeStringType(type: string) {\n  return (\n    type === 'string' ||\n    type === 'url' ||\n    type === 'hex' ||\n    type === 'email' ||\n    type === 'date' ||\n    type === 'pattern'\n  );\n}\n\nexport function isEmptyValue(value: Value, type?: string) {\n  if (value === undefined || value === null) {\n    return true;\n  }\n  if (type === 'array' && Array.isArray(value) && !value.length) {\n    return true;\n  }\n  if (isNativeStringType(type) && typeof value === 'string' && !value) {\n    return true;\n  }\n  return false;\n}\n\nexport function isEmptyObject(obj: object) {\n  return Object.keys(obj).length === 0;\n}\n\nfunction asyncParallelArray(\n  arr: RuleValuePackage[],\n  func: ValidateFunc,\n  callback: (errors: ValidateError[]) => void,\n) {\n  const results: ValidateError[] = [];\n  let total = 0;\n  const arrLength = arr.length;\n\n  function count(errors: ValidateError[]) {\n    results.push(...(errors || []));\n    total++;\n    if (total === arrLength) {\n      callback(results);\n    }\n  }\n\n  arr.forEach(a => {\n    func(a, count);\n  });\n}\n\nfunction asyncSerialArray(\n  arr: RuleValuePackage[],\n  func: ValidateFunc,\n  callback: (errors: ValidateError[]) => void,\n) {\n  let index = 0;\n  const arrLength = arr.length;\n\n  function next(errors: ValidateError[]) {\n    if (errors && errors.length) {\n      callback(errors);\n      return;\n    }\n    const original = index;\n    index = index + 1;\n    if (original < arrLength) {\n      func(arr[original], next);\n    } else {\n      callback([]);\n    }\n  }\n\n  next([]);\n}\n\nfunction flattenObjArr(objArr: Record<string, RuleValuePackage[]>) {\n  const ret: RuleValuePackage[] = [];\n  Object.keys(objArr).forEach(k => {\n    ret.push(...(objArr[k] || []));\n  });\n  return ret;\n}\n\nexport class AsyncValidationError extends Error {\n  errors: ValidateError[];\n  fields: Record<string, ValidateError[]>;\n\n  constructor(\n    errors: ValidateError[],\n    fields: Record<string, ValidateError[]>,\n  ) {\n    super('Async Validation Error');\n    this.errors = errors;\n    this.fields = fields;\n  }\n}\n\ntype ValidateFunc = (\n  data: RuleValuePackage,\n  doIt: (errors: ValidateError[]) => void,\n) => void;\n\nexport function asyncMap(\n  objArr: Record<string, RuleValuePackage[]>,\n  option: ValidateOption,\n  func: ValidateFunc,\n  callback: (errors: ValidateError[]) => void,\n  source: Values,\n): Promise<Values> {\n  if (option.first) {\n    const pending = new Promise<Values>((resolve, reject) => {\n      const next = (errors: ValidateError[]) => {\n        callback(errors);\n        return errors.length\n          ? reject(new AsyncValidationError(errors, convertFieldsError(errors)))\n          : resolve(source);\n      };\n      const flattenArr = flattenObjArr(objArr);\n      asyncSerialArray(flattenArr, func, next);\n    });\n    pending.catch(e => e);\n    return pending;\n  }\n  const firstFields =\n    option.firstFields === true\n      ? Object.keys(objArr)\n      : option.firstFields || [];\n\n  const objArrKeys = Object.keys(objArr);\n  const objArrLength = objArrKeys.length;\n  let total = 0;\n  const results: ValidateError[] = [];\n  const pending = new Promise<Values>((resolve, reject) => {\n    const next = (errors: ValidateError[]) => {\n      results.push.apply(results, errors);\n      total++;\n      if (total === objArrLength) {\n        callback(results);\n        return results.length\n          ? reject(\n              new AsyncValidationError(results, convertFieldsError(results)),\n            )\n          : resolve(source);\n      }\n    };\n    if (!objArrKeys.length) {\n      callback(results);\n      resolve(source);\n    }\n    objArrKeys.forEach(key => {\n      const arr = objArr[key];\n      if (firstFields.indexOf(key) !== -1) {\n        asyncSerialArray(arr, func, next);\n      } else {\n        asyncParallelArray(arr, func, next);\n      }\n    });\n  });\n  pending.catch(e => e);\n  return pending;\n}\n\nfunction isErrorObj(\n  obj: ValidateError | string | (() => string),\n): obj is ValidateError {\n  return !!(obj && (obj as ValidateError).message !== undefined);\n}\n\nfunction getValue(value: Values, path: string[]) {\n  let v = value;\n  for (let i = 0; i < path.length; i++) {\n    if (v == undefined) {\n      return v;\n    }\n    v = v[path[i]];\n  }\n  return v;\n}\n\nexport function complementError(rule: InternalRuleItem, source: Values) {\n  return (oe: ValidateError | (() => string) | string): ValidateError => {\n    let fieldValue;\n    if (rule.fullFields) {\n      fieldValue = getValue(source, rule.fullFields);\n    } else {\n      fieldValue = source[(oe as any).field || rule.fullField];\n    }\n    if (isErrorObj(oe)) {\n      oe.field = oe.field || rule.fullField;\n      oe.fieldValue = fieldValue;\n      return oe;\n    }\n    return {\n      message: typeof oe === 'function' ? oe() : oe,\n      fieldValue,\n      field: ((oe as unknown) as ValidateError).field || rule.fullField,\n    };\n  };\n}\n\nexport function deepMerge<T extends object>(target: T, source: Partial<T>): T {\n  if (source) {\n    for (const s in source) {\n      if (source.hasOwnProperty(s)) {\n        const value = source[s];\n        if (typeof value === 'object' && typeof target[s] === 'object') {\n          target[s] = {\n            ...target[s],\n            ...value,\n          };\n        } else {\n          target[s] = value;\n        }\n      }\n    }\n  }\n  return target;\n}\n"
  },
  {
    "path": "src/validator/any.ts",
    "content": "import { ExecuteValidator } from '../interface';\nimport rules from '../rule';\nimport { isEmptyValue } from '../util';\n\nconst any: ExecuteValidator = (rule, value, callback, source, options) => {\n  const errors: string[] = [];\n  const validate =\n    rule.required || (!rule.required && source.hasOwnProperty(rule.field));\n  if (validate) {\n    if (isEmptyValue(value) && !rule.required) {\n      return callback();\n    }\n    rules.required(rule, value, source, errors, options);\n  }\n  callback(errors);\n};\n\nexport default any;\n"
  },
  {
    "path": "src/validator/array.ts",
    "content": "import { ExecuteValidator } from '../interface';\nimport rules from '../rule/index';\n\nconst array: ExecuteValidator = (rule, value, callback, source, options) => {\n  const errors: string[] = [];\n  const validate =\n    rule.required || (!rule.required && source.hasOwnProperty(rule.field));\n  if (validate) {\n    if ((value === undefined || value === null) && !rule.required) {\n      return callback();\n    }\n    rules.required(rule, value, source, errors, options, 'array');\n    if (value !== undefined && value !== null) {\n      rules.type(rule, value, source, errors, options);\n      rules.range(rule, value, source, errors, options);\n    }\n  }\n  callback(errors);\n};\n\nexport default array;\n"
  },
  {
    "path": "src/validator/boolean.ts",
    "content": "import { isEmptyValue } from '../util';\nimport rules from '../rule';\nimport { ExecuteValidator } from '../interface';\n\nconst boolean: ExecuteValidator = (rule, value, callback, source, options) => {\n  const errors: string[] = [];\n  const validate =\n    rule.required || (!rule.required && source.hasOwnProperty(rule.field));\n  if (validate) {\n    if (isEmptyValue(value) && !rule.required) {\n      return callback();\n    }\n    rules.required(rule, value, source, errors, options);\n    if (value !== undefined) {\n      rules.type(rule, value, source, errors, options);\n    }\n  }\n  callback(errors);\n};\n\nexport default boolean;\n"
  },
  {
    "path": "src/validator/date.ts",
    "content": "import { ExecuteValidator } from '../interface';\nimport rules from '../rule';\nimport { isEmptyValue } from '../util';\n\nconst date: ExecuteValidator = (rule, value, callback, source, options) => {\n  // console.log('integer rule called %j', rule);\n  const errors: string[] = [];\n  const validate =\n    rule.required || (!rule.required && source.hasOwnProperty(rule.field));\n  // console.log('validate on %s value', value);\n  if (validate) {\n    if (isEmptyValue(value, 'date') && !rule.required) {\n      return callback();\n    }\n    rules.required(rule, value, source, errors, options);\n    if (!isEmptyValue(value, 'date')) {\n      let dateObject;\n\n      if (value instanceof Date) {\n        dateObject = value;\n      } else {\n        dateObject = new Date(value);\n      }\n\n      rules.type(rule, dateObject, source, errors, options);\n      if (dateObject) {\n        rules.range(rule, dateObject.getTime(), source, errors, options);\n      }\n    }\n  }\n  callback(errors);\n};\n\nexport default date;\n"
  },
  {
    "path": "src/validator/enum.ts",
    "content": "import { ExecuteValidator } from '../interface';\nimport rules from '../rule';\nimport { isEmptyValue } from '../util';\n\nconst ENUM = 'enum' as const;\n\nconst enumerable: ExecuteValidator = (\n  rule,\n  value,\n  callback,\n  source,\n  options,\n) => {\n  const errors: string[] = [];\n  const validate =\n    rule.required || (!rule.required && source.hasOwnProperty(rule.field));\n  if (validate) {\n    if (isEmptyValue(value) && !rule.required) {\n      return callback();\n    }\n    rules.required(rule, value, source, errors, options);\n    if (value !== undefined) {\n      rules[ENUM](rule, value, source, errors, options);\n    }\n  }\n  callback(errors);\n};\n\nexport default enumerable;\n"
  },
  {
    "path": "src/validator/float.ts",
    "content": "import { ExecuteValidator } from '../interface';\nimport rules from '../rule';\nimport { isEmptyValue } from '../util';\n\nconst floatFn: ExecuteValidator = (rule, value, callback, source, options) => {\n  const errors: string[] = [];\n  const validate =\n    rule.required || (!rule.required && source.hasOwnProperty(rule.field));\n  if (validate) {\n    if (isEmptyValue(value) && !rule.required) {\n      return callback();\n    }\n    rules.required(rule, value, source, errors, options);\n    if (value !== undefined) {\n      rules.type(rule, value, source, errors, options);\n      rules.range(rule, value, source, errors, options);\n    }\n  }\n  callback(errors);\n};\n\nexport default floatFn;\n"
  },
  {
    "path": "src/validator/index.ts",
    "content": "import string from './string';\nimport method from './method';\nimport number from './number';\nimport boolean from './boolean';\nimport regexp from './regexp';\nimport integer from './integer';\nimport float from './float';\nimport array from './array';\nimport object from './object';\nimport enumValidator from './enum';\nimport pattern from './pattern';\nimport date from './date';\nimport required from './required';\nimport type from './type';\nimport any from './any';\n\nexport default {\n  string,\n  method,\n  number,\n  boolean,\n  regexp,\n  integer,\n  float,\n  array,\n  object,\n  enum: enumValidator,\n  pattern,\n  date,\n  url: type,\n  hex: type,\n  email: type,\n  required,\n  any,\n};\n"
  },
  {
    "path": "src/validator/integer.ts",
    "content": "import { ExecuteValidator } from '../interface';\nimport rules from '../rule';\nimport { isEmptyValue } from '../util';\n\nconst integer: ExecuteValidator = (rule, value, callback, source, options) => {\n  const errors: string[] = [];\n  const validate =\n    rule.required || (!rule.required && source.hasOwnProperty(rule.field));\n  if (validate) {\n    if (isEmptyValue(value) && !rule.required) {\n      return callback();\n    }\n    rules.required(rule, value, source, errors, options);\n    if (value !== undefined) {\n      rules.type(rule, value, source, errors, options);\n      rules.range(rule, value, source, errors, options);\n    }\n  }\n  callback(errors);\n};\n\nexport default integer;\n"
  },
  {
    "path": "src/validator/method.ts",
    "content": "import { ExecuteValidator } from '../interface';\nimport rules from '../rule';\nimport { isEmptyValue } from '../util';\n\nconst method: ExecuteValidator = (rule, value, callback, source, options) => {\n  const errors: string[] = [];\n  const validate =\n    rule.required || (!rule.required && source.hasOwnProperty(rule.field));\n  if (validate) {\n    if (isEmptyValue(value) && !rule.required) {\n      return callback();\n    }\n    rules.required(rule, value, source, errors, options);\n    if (value !== undefined) {\n      rules.type(rule, value, source, errors, options);\n    }\n  }\n  callback(errors);\n};\n\nexport default method;\n"
  },
  {
    "path": "src/validator/number.ts",
    "content": "import { ExecuteValidator } from '../interface';\nimport rules from '../rule';\nimport { isEmptyValue } from '../util';\n\nconst number: ExecuteValidator = (rule, value, callback, source, options) => {\n  const errors: string[] = [];\n  const validate =\n    rule.required || (!rule.required && source.hasOwnProperty(rule.field));\n  if (validate) {\n    if (value === '') {\n      value = undefined;\n    }\n    if (isEmptyValue(value) && !rule.required) {\n      return callback();\n    }\n    rules.required(rule, value, source, errors, options);\n    if (value !== undefined) {\n      rules.type(rule, value, source, errors, options);\n      rules.range(rule, value, source, errors, options);\n    }\n  }\n  callback(errors);\n};\n\nexport default number;\n"
  },
  {
    "path": "src/validator/object.ts",
    "content": "import { ExecuteValidator } from '../interface';\nimport rules from '../rule';\nimport { isEmptyValue } from '../util';\n\nconst object: ExecuteValidator = (rule, value, callback, source, options) => {\n  const errors: string[] = [];\n  const validate =\n    rule.required || (!rule.required && source.hasOwnProperty(rule.field));\n  if (validate) {\n    if (isEmptyValue(value) && !rule.required) {\n      return callback();\n    }\n    rules.required(rule, value, source, errors, options);\n    if (value !== undefined) {\n      rules.type(rule, value, source, errors, options);\n    }\n  }\n  callback(errors);\n};\n\nexport default object;\n"
  },
  {
    "path": "src/validator/pattern.ts",
    "content": "import { ExecuteValidator } from '../interface';\nimport rules from '../rule';\nimport { isEmptyValue } from '../util';\n\nconst pattern: ExecuteValidator = (rule, value, callback, source, options) => {\n  const errors: string[] = [];\n  const validate =\n    rule.required || (!rule.required && source.hasOwnProperty(rule.field));\n  if (validate) {\n    if (isEmptyValue(value, 'string') && !rule.required) {\n      return callback();\n    }\n    rules.required(rule, value, source, errors, options);\n    if (!isEmptyValue(value, 'string')) {\n      rules.pattern(rule, value, source, errors, options);\n    }\n  }\n  callback(errors);\n};\n\nexport default pattern;\n"
  },
  {
    "path": "src/validator/regexp.ts",
    "content": "import { ExecuteValidator } from '../interface';\nimport rules from '../rule';\nimport { isEmptyValue } from '../util';\n\nconst regexp: ExecuteValidator = (rule, value, callback, source, options) => {\n  const errors: string[] = [];\n  const validate =\n    rule.required || (!rule.required && source.hasOwnProperty(rule.field));\n  if (validate) {\n    if (isEmptyValue(value) && !rule.required) {\n      return callback();\n    }\n    rules.required(rule, value, source, errors, options);\n    if (!isEmptyValue(value)) {\n      rules.type(rule, value, source, errors, options);\n    }\n  }\n  callback(errors);\n};\n\nexport default regexp;\n"
  },
  {
    "path": "src/validator/required.ts",
    "content": "import { ExecuteValidator } from '../interface';\nimport rules from '../rule';\n\nconst required: ExecuteValidator = (rule, value, callback, source, options) => {\n  const errors: string[] = [];\n  const type = Array.isArray(value) ? 'array' : typeof value;\n  rules.required(rule, value, source, errors, options, type);\n  callback(errors);\n};\n\nexport default required;\n"
  },
  {
    "path": "src/validator/string.ts",
    "content": "import { ExecuteValidator } from '../interface';\nimport rules from '../rule';\nimport { isEmptyValue } from '../util';\n\nconst string: ExecuteValidator = (rule, value, callback, source, options) => {\n  const errors: string[] = [];\n  const validate =\n    rule.required || (!rule.required && source.hasOwnProperty(rule.field));\n  if (validate) {\n    if (isEmptyValue(value, 'string') && !rule.required) {\n      return callback();\n    }\n    rules.required(rule, value, source, errors, options, 'string');\n    if (!isEmptyValue(value, 'string')) {\n      rules.type(rule, value, source, errors, options);\n      rules.range(rule, value, source, errors, options);\n      rules.pattern(rule, value, source, errors, options);\n      if (rule.whitespace === true) {\n        rules.whitespace(rule, value, source, errors, options);\n      }\n    }\n  }\n  callback(errors);\n};\n\nexport default string;\n"
  },
  {
    "path": "src/validator/type.ts",
    "content": "import { ExecuteValidator } from '../interface';\nimport rules from '../rule';\nimport { isEmptyValue } from '../util';\n\nconst type: ExecuteValidator = (rule, value, callback, source, options) => {\n  const ruleType = rule.type;\n  const errors: string[] = [];\n  const validate =\n    rule.required || (!rule.required && source.hasOwnProperty(rule.field));\n  if (validate) {\n    if (isEmptyValue(value, ruleType) && !rule.required) {\n      return callback();\n    }\n    rules.required(rule, value, source, errors, options, ruleType);\n    if (!isEmptyValue(value, ruleType)) {\n      rules.type(rule, value, source, errors, options);\n    }\n  }\n  callback(errors);\n};\n\nexport default type;\n"
  },
  {
    "path": "tests/url.ts",
    "content": "import AsyncValidator from '../src';\n\nconst validator = new AsyncValidator({\n  v: {\n    type: 'url',\n  },\n});\n\nfor (var i = 1; i <= 1000; i++) {\n  var time = Date.now();\n  var attack_str = '//a.b' + 'c1'.repeat(i) + 'a';\n  validator.validate({\n    v: attack_str,\n  });\n  var time_cost = Date.now() - time;\n  console.log(\n    'attack_str.length: ' + attack_str.length + ': ' + time_cost + ' ms',\n  );\n}\n\nif (false) {\n  console.log('*'.repeat(10));\n\n  for (var i = 1; i <= 50000; i++) {\n    var time = Date.now();\n    var attack_str = '//' + ':'.repeat(i * 10000) + '@';\n    validator.validate({\n      v: attack_str,\n    });\n    var time_cost = Date.now() - time;\n    console.log(\n      'attack_str.length: ' + attack_str.length + ': ' + time_cost + ' ms',\n    );\n  }\n}\n"
  },
  {
    "path": "tsconfig.json",
    "content": "{\n  \"compilerOptions\": {\n    \"outDir\": \"lib\",\n    \"module\": \"commonjs\",\n    \"target\": \"ES2020\",\n    \"lib\": [\n      \"es2016\",\n      \"dom\",\n      \"es5\"\n    ],\n    \"jsx\": \"preserve\",\n    \"resolveJsonModule\": true,\n    \"experimentalDecorators\": true,\n    \"isolatedModules\": true,\n    \"skipLibCheck\": true,\n    \"declaration\": true,\n    \"strictFunctionTypes\": true,\n    \"allowSyntheticDefaultImports\": true,\n    \"moduleResolution\": \"node\",\n    \"plugins\": [\n      {\n        \"transform\": \"@zerollup/ts-transform-paths\"\n      }\n    ]\n  },\n  \"include\": [\t\t\n    \"src/\"\n  ],\n  \"exclude\": [\n    \"node_modules/\"\n  ]\n}"
  }
]