{"_id":"@ahassani/validate","_rev":"1-684f6ccc6f88c2bda6867c411f0fff21","name":"@ahassani/validate","dist-tags":{"latest":"0.0.1-alpha"},"versions":{"0.0.1-alpha":{"name":"@ahassani/validate","description":"Validate object properties in javascript.","version":"0.0.1-alpha","author":{"name":"Ayoub HASSANI","email":"hassani.ayoub@gmail.com"},"repository":{"type":"git","url":"http://git.hassani-lab.fr/final/Validate.git"},"keywords":["validation","validate","valid","object"],"scripts":{"cov":"codecov","test":"jest","test-cov":"jest --coverage --runInBand --forceExit","doc":"documentation readme index.js --section=API","doc:html":"documentation build ./src/*.js -f html -o docs","lint":"eslint src test","build":"npm run build1 && npm run build2 && npm run build3","build1":"babel -d build src","build2":"babel ./package.json --out-dir build --copy-files","build3":"babel ./readme.md --out-dir build --copy-files","prepublish":"npm run build"},"engines":{"node":">=7.6"},"dependencies":{"@ahassani/dot":"^0.0.1-alpha","@ahassani/type":"^0.0.1","babel-preset-minify":"^0.5.1","install":"^0.13.0","npm":"^7.19.0"},"devDependencies":{"@babel/cli":"^7.14.5","@babel/core":"^7.14.6","@babel/preset-env":"^7.14.7","babel-jest":"^27.0.5","babel-plugin-add-module-exports":"^1.0.4","codecov":"^3.8.2","documentation":"^13.2.5","eslint":"^7.29.0","eslint-config-standard":"^16.0.3","eslint-plugin-import":"^2.23.4","eslint-plugin-node":"^11.1.0","eslint-plugin-promise":"^5.1.0","eslint-plugin-standard":"^5.0.0","jest":"^27.0.5"},"jest":{"transformIgnorePatterns":["/node_modules/","\\.pnp\\.[^\\/]+$","/test/"],"testMatch":["<rootDir>/test/**/*.js"],"coverageReporters":["text-summary","lcov"],"bail":true,"testEnvironment":"node"},"main":"schema.js","_id":"@ahassani/validate@0.0.1-alpha","_nodeVersion":"16.3.0","_npmVersion":"7.17.0","dist":{"integrity":"sha512-jPUda0gBILGut7DLkvJnwq5JUbKv7mRrLupHpY0rDoPByIkDgAmPbkNL1Bp4svFOlpoC2/p9fU2uJu1Z5G52xw==","shasum":"e8e29d622a85b6e76b04c6e0bf242724eac6e16b","tarball":"https://registry.npmjs.org/@ahassani/validate/-/validate-0.0.1-alpha.tgz","fileCount":10,"unpackedSize":46622,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJg2bGHCRA9TVsSAnZWagAAtkAP/R9b8amGdj5qY82pG4IU\nNnDSl54arlu7vjLrfcKmrrPpZqjhcJ7MP+2mbcFDEhsFpNRtOVpqo+RXQLeJ\nDsVtrQlAuKq7GAtn5M94uc2Iyjei9a4qJ551JhkNG9zcBClCFJsDkGj9BvaS\nTQiV2+S+9yFVl1E+D1Ylk65DyOBTpMfB6jHWxqEkfc/WiPigFf1PKmpkg1um\nVSEKzLu/V5S8vyEY4G7jxG28KciMSp8dr2BHh1K5f4ev4lXGV9Lcw3ggi7OA\nempKCH98/4K8qV1auHnzu6/awjf0vUEKyyKxed20VbJaQ6FJjzq0CqIbOMZA\nwFjHlKykikSaE2nRBWhj+oSXkbGYeRL6xslIJeV9fSoeeOqqtoh9SF4BELpH\nStPP0D41hUPuEz0OxNWu4bM+LCZKpGgqeGwCTAGXfdMb+4Mbp92orUeNMRm4\nWFS7VdFcA74CkbqFdYRN3MK1Jq6rvdcFvxud9Y+9mUwTmMfvnGVnI1mxzxTh\nXSh1ePQHIfNZq5s1txMF5bR0n4nhiBs84llcMhPufV+ZjimeKhtAF8RflzWR\nAM/HeoU0gNUMK7GbMFOPMhDlmGRSrzTVFLhApWLgAsCd1oxGSonx+nb3IA1Z\nJh1lC3XdU7NJUwE2du05bI7EObF4GzKla7GzWwkSWG3UptVxl13/RECaE1Lb\nsWmI\r\n=wYlK\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCna3JjpUBjjkr6MNBBLOIoZeUmFh9PY4CGubPc9QejVgIhAOhrd7Ft819BZKi1XzlHXWls/QXCBBzZ1M6xr8u8yAGd"}]},"_npmUser":{"name":"a.hassani","email":"hassani.ayoub@gmail.com"},"directories":{},"maintainers":[{"name":"a.hassani","email":"hassani.ayoub@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/validate_0.0.1-alpha_1624879495491_0.3937299370264935"},"_hasShrinkwrap":false}},"time":{"created":"2021-06-28T11:24:55.152Z","0.0.1-alpha":"2021-06-28T11:24:55.632Z","modified":"2022-04-04T12:12:00.082Z"},"maintainers":[{"name":"a.hassani","email":"hassani.ayoub@gmail.com"}],"description":"Validate object properties in javascript.","keywords":["validation","validate","valid","object"],"repository":{"type":"git","url":"http://git.hassani-lab.fr/final/Validate.git"},"author":{"name":"Ayoub HASSANI","email":"hassani.ayoub@gmail.com"},"readme":"# validate\n\nValidate object properties in javascript.\n\n## Usage\n\nDefine a schema and call `.validate()` with the object you want to validate.\nThe `.validate()` function returns an array of validation errors.\n\n```javascript\nimport Schema from '@ahassani/validate'\n\nconst user = new Schema({\n  username: {\n    type: String,\n    required: true,\n    length: { min: 3, max: 32 }\n  },\n  pets: [{\n    name: {\n      type: String\n      required: true\n    },\n    animal: {\n      type: String\n      enum: ['cat', 'dog', 'cow']\n    }\n  }],\n  address: {\n    street: {\n      type: String,\n      required: true\n    },\n    city: {\n      type: String,\n      required: true\n    }\n    zip: {\n      type: String,\n      match: /^[0-9]+$/,\n      required: true\n    }\n  }\n})\n\nconst errors = user.validate(obj)\n```\n\nEach error has a `.path`, describing the full path of the property that failed validation, and a `.message` describing the error.\n\n```js\nerrors[0].path //=> 'address.street'\nerrors[0].message //=> 'address.street is required.'\n```\n\n### Custom error messages\n\nYou can override the default error messages by passing an object to `Schema#message()`.\n\n```js\nconst post = new Schema({\n  title: { required: true }\n})\n\npost.message({\n  required: (path) => `${path} can not be empty.`\n})\n\nconst [error] = post.validate({})\nassert(error.message = 'title can not be empty.')\n```\n\nIt is also possible to define messages for individual properties:\n\n```js\nconst post = new Schema({\n  title: {\n    required: true,\n    message: 'Title is required.'\n  }\n})\n```\n\nAnd for individual validators:\n\n```js\nconst post = new Schema({\n  title: {\n    type: String,\n    required: true,\n    message: {\n      type: 'Title must be a string.',\n      required: 'Title is required.'\n    }\n  }\n})\n```\n\n### Nesting\n\nObjects and arrays can be nested as deep as you want:\n\n```js\nconst event = new Schema({\n  title: {\n    type: String,\n    required: true\n  },\n  participants: [{\n    name: String,\n    email: {\n      type: String,\n      required: true\n    },\n    things: [{\n      name: String,\n      amount: Number\n    }]\n  }]\n})\n```\n\nArrays can be defined implicitly, like in the above example, or explicitly:\n\n```js\nconst post = new Schema({\n  keywords: {\n    type: Array,\n    each: { type: String }\n  }\n})\n```\n\nArray elements can also be defined individually:\n\n```js\nconst user = new Schema({\n  something: {\n    type: Array,\n    elements: [\n      { type: Number },\n      { type: String }\n    ]\n  }\n})\n```\n\nNesting also works with schemas:\n\n```js\nconst user = new Schema({\n  name: {\n    type: String,\n    required: true\n  },\n  email: {\n    type: String,\n    required: true\n  }\n})\n\nconst post = new Schema({\n  title: {\n    type: String,\n    required: true\n  },\n  content: {\n    type: String,\n    required: true\n  },\n  author: user\n})\n```\n\nIf you think it should work, it probably works.\n\n#### Naming conflicts\n\nValidate will naively assume that a nested object where *all* property names are validators is not a nested object.\n\n```js\nconst schema = new Schema({\n  pet: {\n    type: {\n      required: true,\n      type: String,\n      enum: ['cat', 'dog']\n    }\n  }\n});\n```\n\nIn this example, the `pet.type` property will be interpreted as a `type` rule, and the validations will not work as intended. To work around this we could use the slightly more verbose `properties` rule:\n\n```js\nconst schema = new Schema({\n  pet: {\n    properties: {\n      type: {\n        required: true,\n        type: String,\n        enum: ['cat', 'dog']\n      }\n    }\n  }\n});\n```\n\nIn this case the `type` property of `pets.properties` will be interpreted as a nested property, and the validations will work as intended.\n\n### Custom validators\n\nCustom validators can be defined by passing an object with named validators to `.use`:\n\n```js\nconst hexColor = val => /^#[0-9a-fA-F]$/.test(val)\n\nconst car = new Schema({\n  color: {\n    type: String,\n    use: { hexColor }\n  }\n})\n```\n\nDefine a custom error message for the validator:\n\n```js\ncar.message({\n  hexColor: path => `${path} must be a valid color.`\n})\n```\n\n### Custom types\n\nPass a constructor to `.type` to validate against a custom type:\n\n```js\nclass Car {}\n\nconst user = new Schema({\n  car: { type: Car }\n})\n```\n\n### Chainable API\n\nIf you want to avoid constructing large objects, you can add paths to a schema by using the chainable API:\n\n```js\nconst user = new Schema()\n\nuser\n  .path('username').type(String).required()\n  .path('address.zip').type(String).required()\n```\n\nArray elements can be defined by using `$` as a placeholder for indices:\n\n```js\nconst user = new Schema()\nuser.path('pets.$').type(String)\n```\n\nThis is equivalent to writing\n\n```js\nconst user = new Schema({ pets: [{ type: String }]})\n```\n\n### Typecasting\n\nValues can be automatically typecast before validation.\nTo enable typecasting, pass an options object to the `Schema` constructor with `typecast` set to `true`.\n\n```js\nconst user = new Schema(definition, { typecast: true })\n```\n\nYou can override this setting by passing an option to `.validate()`.\n\n```js\nuser.validate(obj, { typecast: false })\n```\n\nTo typecast custom types, you can register a typecaster:\n\n```js\nclass Car {}\n\nconst user = new Schema({\n  car: { type: Car }\n})\n\nuser.typecaster({\n  Car: (val) => new Car(val)\n})\n```\n\n### Property stripping\n\nBy default, all values not defined in the schema will be stripped from the object.\nSet `.strip = false` on the options object to disable this behavior. This will likely be changed in a future version.\n\n### Strict mode\n\nWhen strict mode is enabled, properties that are not defined in the schema will trigger a validation error. Set `.strict = true` on the options object to enable strict mode.\n\n## API\n\n<!-- Generated by documentation.js. Update this documentation by updating the source code. -->\n\n#### Table of Contents\n\n*   [Property](#property)\n    *   [Parameters](#parameters)\n    *   [message](#message)\n        *   [Parameters](#parameters-1)\n        *   [Examples](#examples)\n    *   [schema](#schema)\n        *   [Parameters](#parameters-2)\n        *   [Examples](#examples-1)\n    *   [use](#use)\n        *   [Parameters](#parameters-3)\n        *   [Examples](#examples-2)\n    *   [required](#required)\n        *   [Parameters](#parameters-4)\n        *   [Examples](#examples-3)\n    *   [type](#type)\n        *   [Parameters](#parameters-5)\n        *   [Examples](#examples-4)\n    *   [string](#string)\n        *   [Examples](#examples-5)\n    *   [number](#number)\n        *   [Examples](#examples-6)\n    *   [array](#array)\n        *   [Examples](#examples-7)\n    *   [date](#date)\n        *   [Examples](#examples-8)\n    *   [length](#length)\n        *   [Parameters](#parameters-6)\n        *   [Examples](#examples-9)\n    *   [size](#size)\n        *   [Parameters](#parameters-7)\n        *   [Examples](#examples-10)\n    *   [enum](#enum)\n        *   [Parameters](#parameters-8)\n        *   [Examples](#examples-11)\n    *   [match](#match)\n        *   [Parameters](#parameters-9)\n        *   [Examples](#examples-12)\n    *   [each](#each)\n        *   [Parameters](#parameters-10)\n        *   [Examples](#examples-13)\n    *   [elements](#elements)\n        *   [Parameters](#parameters-11)\n        *   [Examples](#examples-14)\n    *   [properties](#properties)\n        *   [Parameters](#parameters-12)\n        *   [Examples](#examples-15)\n    *   [path](#path)\n        *   [Parameters](#parameters-13)\n        *   [Examples](#examples-16)\n    *   [typecast](#typecast)\n        *   [Parameters](#parameters-14)\n        *   [Examples](#examples-17)\n    *   [validate](#validate)\n        *   [Parameters](#parameters-15)\n        *   [Examples](#examples-18)\n*   [Schema](#schema-1)\n    *   [Parameters](#parameters-16)\n    *   [Examples](#examples-19)\n    *   [path](#path-1)\n        *   [Parameters](#parameters-17)\n        *   [Examples](#examples-20)\n    *   [validate](#validate-1)\n        *   [Parameters](#parameters-18)\n        *   [Examples](#examples-21)\n    *   [assert](#assert)\n        *   [Parameters](#parameters-19)\n        *   [Examples](#examples-22)\n    *   [message](#message-1)\n        *   [Parameters](#parameters-20)\n        *   [Examples](#examples-23)\n    *   [validator](#validator)\n        *   [Parameters](#parameters-21)\n        *   [Examples](#examples-24)\n    *   [typecaster](#typecaster)\n        *   [Parameters](#parameters-22)\n        *   [Examples](#examples-25)\n\n### Property\n\nA property instance gets returned whenever you call `schema.path()`.\nProperties are also created internally when an object is passed to the Schema constructor.\n\n#### Parameters\n\n*   `name` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the name of the property\n*   `schema` **[Schema](#schema)** parent schema\n\n#### message\n\nRegisters messages.\n\n##### Parameters\n\n*   `messages` **([Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object) | [String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String))** \n\n##### Examples\n\n```javascript\nprop.message('something is wrong')\nprop.message({ required: 'thing is required.' })\n```\n\nReturns **[Property](#property)** \n\n#### schema\n\nMount given `schema` on current path.\n\n##### Parameters\n\n*   `schema` **[Schema](#schema)** the schema to mount\n\n##### Examples\n\n```javascript\nconst user = new Schema({ email: String })\nprop.schema(user)\n```\n\nReturns **[Property](#property)** \n\n#### use\n\nValidate using named functions from the given object.\nError messages can be defined by providing an object with\nnamed error messages/generators to `schema.message()`\n\nThe message generator receives the value being validated,\nthe object it belongs to and any additional arguments.\n\n##### Parameters\n\n*   `fns` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** object with named validation functions to call\n\n##### Examples\n\n```javascript\nconst schema = new Schema()\nconst prop = schema.path('some.path')\n\nschema.message({\n  binary: (path, ctx) => `${path} must be binary.`,\n  bits: (path, ctx, bits) => `${path} must be ${bits}-bit`\n})\n\nprop.use({\n  binary: (val, ctx) => /^[01]+$/i.test(val),\n  bits: [(val, ctx, bits) => val.length == bits, 32]\n})\n```\n\nReturns **[Property](#property)** \n\n#### required\n\nRegisters a validator that checks for presence.\n\n##### Parameters\n\n*   `bool` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** `true` if required, `false` otherwise (optional, default `true`)\n\n##### Examples\n\n```javascript\nprop.required()\n```\n\nReturns **[Property](#property)** \n\n#### type\n\nRegisters a validator that checks if a value is of a given `type`\n\n##### Parameters\n\n*   `type` **([String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | [Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function))** type to check for\n\n##### Examples\n\n```javascript\nprop.type(String)\n```\n\n```javascript\nprop.type('string')\n```\n\nReturns **[Property](#property)** \n\n#### string\n\nConvenience method for setting type to `String`\n\n##### Examples\n\n```javascript\nprop.string()\n```\n\nReturns **[Property](#property)** \n\n#### number\n\nConvenience method for setting type to `Number`\n\n##### Examples\n\n```javascript\nprop.number()\n```\n\nReturns **[Property](#property)** \n\n#### array\n\nConvenience method for setting type to `Array`\n\n##### Examples\n\n```javascript\nprop.array()\n```\n\nReturns **[Property](#property)** \n\n#### date\n\nConvenience method for setting type to `Date`\n\n##### Examples\n\n```javascript\nprop.date()\n```\n\nReturns **[Property](#property)** \n\n#### length\n\nRegisters a validator that checks length.\n\n##### Parameters\n\n*   `rules` **([Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object) | [Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number))** object with `.min` and `.max` properties or a number\n\n    *   `rules.min` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** minimum length\n    *   `rules.max` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** maximum length\n\n##### Examples\n\n```javascript\nprop.length({ min: 8, max: 255 })\nprop.length(10)\n```\n\nReturns **[Property](#property)** \n\n#### size\n\nRegisters a validator that checks size.\n\n##### Parameters\n\n*   `rules` **([Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object) | [Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number))** object with `.min` and `.max` properties or a number\n\n    *   `rules.min` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** minimum size\n    *   `rules.max` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** maximum size\n\n##### Examples\n\n```javascript\nprop.size({ min: 8, max: 255 })\nprop.size(10)\n```\n\nReturns **[Property](#property)** \n\n#### enum\n\nRegisters a validator for enums.\n\n##### Parameters\n\n*   `enums`  \n*   `rules` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** allowed values\n\n##### Examples\n\n```javascript\nprop.enum(['cat', 'dog'])\n```\n\nReturns **[Property](#property)** \n\n#### match\n\nRegisters a validator that checks if a value matches given `regexp`.\n\n##### Parameters\n\n*   `regexp` **[RegExp](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/RegExp)** regular expression to match\n\n##### Examples\n\n```javascript\nprop.match(/some\\sregular\\sexpression/)\n```\n\nReturns **[Property](#property)** \n\n#### each\n\nRegisters a validator that checks each value in an array against given `rules`.\n\n##### Parameters\n\n*   `rules` **([Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array) | [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object) | [Schema](#schema) | [Property](#property))** rules to use\n\n##### Examples\n\n```javascript\nprop.each({ type: String })\nprop.each([{ type: Number }])\nprop.each({ things: [{ type: String }]})\nprop.each(schema)\n```\n\nReturns **[Property](#property)** \n\n#### elements\n\nRegisters paths for array elements on the parent schema, with given array of rules.\n\n##### Parameters\n\n*   `arr` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** array of rules to use\n\n##### Examples\n\n```javascript\nprop.elements([{ type: String }, { type: Number }])\n```\n\nReturns **[Property](#property)** \n\n#### properties\n\nRegisters all properties from the given object as nested properties\n\n##### Parameters\n\n*   `props` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** properties with rules\n\n##### Examples\n\n```javascript\nprop.properties({\n  name: String,\n  email: String\n})\n```\n\nReturns **[Property](#property)** \n\n#### path\n\nProxy method for schema path. Makes chaining properties together easier.\n\n##### Parameters\n\n*   `args` **...any** \n\n##### Examples\n\n```javascript\nschema\n  .path('name').type(String).required()\n  .path('email').type(String).required()\n```\n\n#### typecast\n\nTypecast given `value`\n\n##### Parameters\n\n*   `value` **Mixed** value to typecast\n\n##### Examples\n\n```javascript\nprop.type(String)\nprop.typecast(123) // => '123'\n```\n\nReturns **Mixed** \n\n#### validate\n\nValidate given `value`\n\n##### Parameters\n\n*   `value` **Mixed** value to validate\n*   `ctx` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** the object containing the value\n*   `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** path of the value being validated (optional, default `this.name`)\n\n##### Examples\n\n```javascript\nprop.type(Number)\nassert(prop.validate(2) == null)\nassert(prop.validate('hello world') instanceof Error)\n```\n\nReturns **ValidationError** \n\n### Schema\n\nA Schema defines the structure that objects should be validated against.\n\n#### Parameters\n\n*   `obj` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** schema definition (optional, default `{}`)\n*   `opts` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** options (optional, default `{}`)\n\n    *   `opts.typecast` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** typecast values before validation (optional, default `false`)\n    *   `opts.strip` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** strip properties not defined in the schema (optional, default `true`)\n    *   `opts.strict` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** validation fails when object contains properties not defined in the schema (optional, default `false`)\n\n#### Examples\n\n```javascript\nconst post = new Schema({\n  title: {\n    type: String,\n    required: true,\n    length: { min: 1, max: 255 }\n  },\n  content: {\n    type: String,\n    required: true\n  },\n  published: {\n    type: Date,\n    required: true\n  },\n  keywords: [{ type: String }]\n})\n```\n\n```javascript\nconst author = new Schema({\n  name: {\n    type: String,\n    required: true\n  },\n  email: {\n    type: String,\n    required: true\n  },\n  posts: [post]\n})\n```\n\n#### path\n\nCreate or update `path` with given `rules`.\n\n##### Parameters\n\n*   `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** full path using dot-notation\n*   `rules` **([Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object) | [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array) | [String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | [Schema](#schema) | [Property](#property))?** rules to apply\n\n##### Examples\n\n```javascript\nconst schema = new Schema()\nschema.path('name.first', { type: String })\nschema.path('name.last').type(String).required()\n```\n\nReturns **[Property](#property)** \n\n#### validate\n\nValidate given `obj`.\n\n##### Parameters\n\n*   `obj` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** the object to validate\n*   `opts` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** options, see [Schema](#schema-1) (optional, default `{}`)\n\n##### Examples\n\n```javascript\nconst schema = new Schema({ name: { required: true }})\nconst errors = schema.validate({})\nassert(errors.length == 1)\nassert(errors[0].message == 'name is required')\nassert(errors[0].path == 'name')\n```\n\nReturns **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** \n\n#### assert\n\nAssert that given `obj` is valid.\n\n##### Parameters\n\n*   `obj` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** \n*   `opts` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** \n\n##### Examples\n\n```javascript\nconst schema = new Schema({ name: String })\nschema.assert({ name: 1 }) // Throws an error\n```\n\n#### message\n\nOverride default error messages.\n\n##### Parameters\n\n*   `name` **([String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object))** name of the validator or an object with name-message pairs\n*   `message` **([String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | [Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function))?** the message or message generator to use\n\n##### Examples\n\n```javascript\nconst hex = (val) => /^0x[0-9a-f]+$/.test(val)\nschema.path('some.path').use({ hex })\nschema.message('hex', path => `${path} must be hexadecimal`)\n```\n\n```javascript\nschema.message({ hex: path => `${path} must be hexadecimal` })\n```\n\nReturns **[Schema](#schema)** \n\n#### validator\n\nOverride default validators.\n\n##### Parameters\n\n*   `name` **([String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object))** name of the validator or an object with name-function pairs\n*   `fn` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)?** the function to use\n\n##### Examples\n\n```javascript\nschema.validator('required', val => val != null)\n```\n\n```javascript\nschema.validator({ required: val => val != null })\n```\n\nReturns **[Schema](#schema)** \n\n#### typecaster\n\nOverride default typecasters.\n\n##### Parameters\n\n*   `name` **([String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object))** name of the validator or an object with name-function pairs\n*   `fn` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)?** the function to use\n\n##### Examples\n\n```javascript\nschema.typecaster('SomeClass', val => new SomeClass(val))\n```\n\n```javascript\nschema.typecaster({ SomeClass: val => new SomeClass(val) })\n```\n\nReturns **[Schema](#schema)** \n\n","readmeFilename":"readme.md"}