{"_id":"@asalmi/o-val","_rev":"2-c35a355f908263ae7990901263f9aff9","name":"@asalmi/o-val","dist-tags":{"latest":"1.0.2"},"versions":{"1.0.0":{"name":"@asalmi/o-val","version":"1.0.0","description":"An object validation library for Javascript or Typescript","author":{"name":"Alex Salmi","email":"alexjfsalmi@gmail.com"},"repository":{"type":"git","url":"git+https://github.com/alexsalmi/o-val.git"},"license":"ISC","main":"dist/index.js","module":"dist/index.mjs","types":"dist/index.d.ts","exports":{".":{"require":"./dist/index.cjs","import":"./dist/index.js","types":"./dist/index.d.ts"}},"type":"module","scripts":{"start":"tsup && node .","test":"jest","build":"tsup"},"keywords":["validation","validator","object validation","object validator","input validation","input validator","form validation","form validator"],"devDependencies":{"@types/jest":"^29.5.12","jest":"^29.7.0","ts-jest":"^29.1.2","tsup":"^8.0.2","tsx":"^4.7.1","typescript":"^5.4.2"},"_id":"@asalmi/o-val@1.0.0","gitHead":"7af5303c168c670b1308fbedcbdfd90c70834fbc","bugs":{"url":"https://github.com/alexsalmi/o-val/issues"},"homepage":"https://github.com/alexsalmi/o-val#readme","_nodeVersion":"20.11.1","_npmVersion":"10.2.4","dist":{"integrity":"sha512-W0QvKI9xzzvvN+No/8/y4YfOjaI9LYQgB2HYMuU9aR2+riiHbX05cRw/P8F+GmNbyrb1QV8FQizTo6nA8E7ONQ==","shasum":"0d2c2ea66f6e7e7f49f90030baf1b3a12410d1e0","tarball":"https://registry.npmjs.org/@asalmi/o-val/-/o-val-1.0.0.tgz","fileCount":8,"unpackedSize":197761,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDMsD+12eXiMvmxNiAWiBJd2N+q5pe3yZOfQunU/NeZugIgcxa9YpbTp1Bkpsuc/mejC/V9YdZo1/A77VLu5R/RyTw="}]},"_npmUser":{"name":"asalmi","email":"alexjfsalmi@gmail.com"},"directories":{},"maintainers":[{"name":"asalmi","email":"alexjfsalmi@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/o-val_1.0.0_1711815566004_0.9301439944669612"},"_hasShrinkwrap":false},"1.0.1":{"name":"@asalmi/o-val","version":"1.0.1","description":"An object validation library for Javascript or Typescript","author":{"name":"Alex Salmi","email":"alexjfsalmi@gmail.com"},"repository":{"type":"git","url":"git+https://github.com/alexsalmi/o-val.git"},"license":"ISC","main":"dist/index.js","module":"dist/index.mjs","types":"dist/index.d.ts","exports":{".":{"require":"./dist/index.cjs","import":"./dist/index.js","types":"./dist/index.d.ts"}},"type":"module","scripts":{"start":"tsup && node .","test":"jest","build":"tsup"},"keywords":["validation","validator","object validation","object validator","input validation","input validator","form validation","form validator"],"devDependencies":{"@types/jest":"^29.5.12","jest":"^29.7.0","ts-jest":"^29.1.2","tsup":"^8.0.2","tsx":"^4.7.1","typescript":"^5.4.2"},"_id":"@asalmi/o-val@1.0.1","gitHead":"ab03a0b491a8c09443d1a8500a57942cc40c292a","bugs":{"url":"https://github.com/alexsalmi/o-val/issues"},"homepage":"https://github.com/alexsalmi/o-val#readme","_nodeVersion":"20.11.1","_npmVersion":"10.2.4","dist":{"integrity":"sha512-vnGH2it9U5ewZ23WbSqKar+LS25vtx2xEYoqJcWIjkeuX+3W71VLoH7AaySvytheP5E94cO2AP6wJNRzIARRew==","shasum":"0f993eab1af8a2f9a44a8601369492b3f7ab0d7d","tarball":"https://registry.npmjs.org/@asalmi/o-val/-/o-val-1.0.1.tgz","fileCount":8,"unpackedSize":197699,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIAuoOLfrm8PjMz+RC7wDQTuxJjOiwBav2K5f6rnbm/wJAiB74ceYzWiN1H9C1X2wmgvJzjsfqEuHFU5qEY+lpuGaqQ=="}]},"_npmUser":{"name":"asalmi","email":"alexjfsalmi@gmail.com"},"directories":{},"maintainers":[{"name":"asalmi","email":"alexjfsalmi@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/o-val_1.0.1_1711815789831_0.7337792347817287"},"_hasShrinkwrap":false},"1.0.2":{"name":"@asalmi/o-val","version":"1.0.2","description":"An object validation library for Javascript or Typescript","author":{"name":"Alex Salmi","email":"alexjfsalmi@gmail.com"},"repository":{"type":"git","url":"git+https://github.com/alexsalmi/o-val.git"},"license":"ISC","main":"dist/index.js","module":"dist/index.mjs","types":"dist/index.d.ts","exports":{".":{"require":"./dist/index.cjs","import":"./dist/index.js","types":"./dist/index.d.ts"}},"type":"module","scripts":{"start":"tsup && node .","test":"jest","build":"tsup"},"keywords":["validation","validator","object validation","object validator","input validation","input validator","form validation","form validator"],"devDependencies":{"@types/jest":"^29.5.12","jest":"^29.7.0","ts-jest":"^29.1.2","tsup":"^8.0.2","tsx":"^4.7.1","typescript":"^5.4.2"},"_id":"@asalmi/o-val@1.0.2","gitHead":"ca03599a9a74d5e3965394a151b384184d044925","bugs":{"url":"https://github.com/alexsalmi/o-val/issues"},"homepage":"https://github.com/alexsalmi/o-val#readme","_nodeVersion":"20.11.1","_npmVersion":"10.2.4","dist":{"integrity":"sha512-CZ5/4EskN4hKElTbDXtOO7KDpTlk/eeJEH7/WdjoKk7A7bPeRFP7B8QCCDbEH0DQ0QRtnsG5bBvcRV/OrYd6uw==","shasum":"d3ac4a6d4c32adc746d6db14aa029597260d059a","tarball":"https://registry.npmjs.org/@asalmi/o-val/-/o-val-1.0.2.tgz","fileCount":8,"unpackedSize":197715,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCjKWdYTgpCGqGikQ6lq5L+eVqW8wz7VGDO4gIjUDPGyQIhAJx9l371KqlornEbZjmzZzluurqG47HACU/5T8SkEihx"}]},"_npmUser":{"name":"asalmi","email":"alexjfsalmi@gmail.com"},"directories":{},"maintainers":[{"name":"asalmi","email":"alexjfsalmi@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/o-val_1.0.2_1711815939045_0.3733564237088438"},"_hasShrinkwrap":false}},"time":{"created":"2024-03-30T16:19:25.923Z","1.0.0":"2024-03-30T16:19:26.149Z","modified":"2024-03-30T16:25:39.387Z","1.0.1":"2024-03-30T16:23:10.013Z","1.0.2":"2024-03-30T16:25:39.206Z"},"maintainers":[{"name":"asalmi","email":"alexjfsalmi@gmail.com"}],"description":"An object validation library for Javascript or Typescript","homepage":"https://github.com/alexsalmi/o-val#readme","keywords":["validation","validator","object validation","object validator","input validation","input validator","form validation","form validator"],"repository":{"type":"git","url":"git+https://github.com/alexsalmi/o-val.git"},"author":{"name":"Alex Salmi","email":"alexjfsalmi@gmail.com"},"bugs":{"url":"https://github.com/alexsalmi/o-val/issues"},"license":"ISC","readme":"# O-Val Object Validation Library\r\n\r\n\r\n[![NPM version][npm-image]][npm-url]\r\n[![node version][node-image]][node-url]\r\n\r\n[npm-image]: https://img.shields.io/npm/v/@asalmi/o-val.svg?style=flat-square\r\n[npm-url]: https://www.npmjs.com/package/@asalmi/o-val\r\n[node-image]: https://img.shields.io/badge/node.js-%3E=_20-green.svg?style=flat-square\r\n[node-url]: http://nodejs.org/download/\r\n\r\nO-Val is a validation library for Javascript and Typescript. Can be used for any type of object validation, whether it be input validation in an Express.js app, or form validation in vanilla JS.\r\n\r\n## Installation\r\n```shell\r\nnpm i @asalmi/o-val\r\n```\r\n\r\n## Features\r\n- Enforces all standard Javascript types, as well as extra types like email, phone number, and URL\r\n- Ability to add your own custom types and rules\r\n- Supports as many nested objects and arrays as you need\r\n- Re-usable validator objects, to validate several objects with the same requirements\r\n- Supports both CommonJS and ECMAScript modules\r\n\r\n## Docs\r\n### Object Validation\r\n- [Validating an object](#validating-an-object)\r\n- [Adding rules](#adding-rules)\r\n- [Adding rules with parameters](#adding-rules-with-parameters)\r\n- [Combining rules](#combining-rules)\r\n- [Adding optional parameters](#adding-optional-parameters)\r\n- [Validating nested objects](#validating-nested-objects)\r\n- [Validating nested arrays](#validating-nested-arrays)\r\n- [Strict mode validation](#strict-mode-validation)\r\n### Custom Types and Rules\r\n- [Adding custom types](#adding-custom-types)\r\n- [Adding custom rules](#adding-custom-rules)\r\n- [Adding custom rules with explicit parameters](#adding-custom-ruless-with-explicit-parameters)\r\n- [Adding custom rules with any number of parameters](#adding-custom-rules-with-any-number-of-parameters)\r\n- [Inheriting custom rules](#inheriting-custom-rules)\r\n### Types and Rules\r\n- [Base Type](#base-type)\r\n- [String](#string)\r\n- [Number](#number)\r\n- [Boolean](#boolean)\r\n- [Object](#object)\r\n- [Array](#array)\r\n- [Email](#email)\r\n- [Phone](#phone)\r\n- [Date](#date)\r\n- [URL](#url)\r\n\r\n\r\n## Object Validation\r\n### Validating an object\r\nWhen creating a new Validator, you must pass an object outlining the types and rules for each key. If you only need to specify the type without enforcing any other rules, you can simply pass the type as a string. \r\n\r\nTo validate an object using your Validator, call the 'validate' method, passing the object you'd like to validate.\r\n##### Success Example:\r\n```javascript\r\nconst Validator from 'o-val';\r\n\r\nconst v = new Validator({\r\n\tname: 'string',\r\n\tage: 'number'\r\n});\r\n\r\nconst res = v.validate({\r\n\tname: 'Alvin',\r\n\tage: 23\r\n});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{ \r\n  valid: true, \r\n  errors: {} \r\n}\r\n```\r\n##### Error Example:\r\n```javascript\r\nconst Validator from 'o-val';\r\n\r\nconst v = new Validator({\r\n\tname: 'string',\r\n\tage: 'number'\r\n});\r\n\r\nconst res = v.validate({\r\n\tname: 'Alvin',\r\n\tage: '23'\r\n});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{ \r\n  valid: false, \r\n  errors: { \r\n    age: [ \"'age' must be of type 'number'\" ] \r\n  } \r\n}\r\n```\r\n---\r\n### Adding rules\r\nIf you are adding any further rules other than specifying the type, you must pass all requirements as an array of strings.\r\n##### Example:\r\n```javascript\r\nimport Validator from 'o-val';\r\n\r\nconst v = new Validator({\r\n\tname: ['string', 'isAlpha'],\r\n\tage: ['number', 'isInt']\r\n});\r\n\r\nconst res = v.validate({\r\n\tname: 'Alvin',\r\n\tage: 18.5\r\n});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{ \r\n  valid: false, \r\n  errors: { \r\n    age: [ \"'age' must be an integer\" ] \r\n  } \r\n}\r\n```\r\n---\r\n### Adding rules with parameters\r\nSome rules will require you to pass parameters to compare the validated object's values to. To pass parameters, append an equals sign and a comma separated list of parameters after the rule name.\r\n##### Example:\r\n```javascript\r\nimport Validator from 'o-val';\r\n\r\nconst v = new Validator({\r\n\tname: ['string', 'minLength=3'],\r\n\tage: ['number', 'between=1,18']\r\n});\r\n\r\nconst res = v.validate({\r\n\tname: 'Alvin',\r\n\tage: 19\r\n});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{ \r\n  valid: false, \r\n  errors: { \r\n    age: [ \"'age' must be between 1 and 18\" ] \r\n  } \r\n}\r\n```\r\n---\r\n### Combining rules\r\nYou can provide any number of rules to a field, as long as the rules exist for the specified type for that field. Simply add as many rules as required to the rule array.\r\n##### Example:\r\n```javascript\r\nimport Validator from 'o-val';\r\n\r\nconst v = new Validator({\r\n\tname: ['string', 'isAlpha', 'minLength=1'],\r\n\tage: ['number', 'isInt', 'between=1,18']\r\n});\r\n\r\nconst res = v.validate({\r\n\tname: 'Alvin',\r\n\tage: 19.5\r\n});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{\r\n  valid: false,\r\n  errors: {\r\n    age: [ \r\n      \"'age' must be an integer\", \r\n      \"'age' must be between 1 and 18\"\r\n    ]\r\n  }\r\n}\r\n```\r\n---\r\n### Adding optional parameters\r\nValues are set to required by default, but you can explicitly specify this using the 'required' rule as well. On the flip side, if you'd like to set a rule to be optional, you can use the 'optional' rule. \r\n\r\nIf a field is required and is not present in the validated object, an error will be thrown. If a field is optional and is not present in the validated object, no error will be thrown and the rest of the rules for that field will be skipped. \r\n##### Example:\r\n```javascript\r\nimport Validator from 'o-val';\r\n\r\nconst v = new Validator({\r\n\tname: ['string', 'required'],\r\n\tage: ['number', 'optional']\r\n});\r\n\r\nconst res = v.validate({});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{\r\n  valid: false,\r\n  errors: {\r\n    name: [ \"'name' is required\" ] \r\n  }\r\n}\r\n```\r\n---\r\n### Validating nested objects\r\nWhen validating nested objects and arrays, the specifications for the children must be passed as the last element of the rule array.\r\n##### Example:\r\n```javascript\r\nimport Validator from 'o-val';\r\n\r\nconst v = new Validator({\r\n\tname: ['object', {\r\n\t\tfirst: ['string', 'minLength=7'],\r\n\t\tlast: ['string', 'minLength=7']\r\n\t}]\r\n});\r\n\r\nconst res = v.validate({\r\n\tname: {\r\n\t\tfirst: 'Alvin',\r\n\t\tlast: 'Chipmunk'\r\n\t}\r\n});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{\r\n  valid: false,\r\n  errors: {\r\n    'name.first': [ \"'name.first' must be at least 7 characters long\" ]\r\n  }\r\n}\r\n```\r\n---\r\n### Validating nested arrays\r\nWhen validating arrays, you can specify rules for its elements in a number of ways:\r\n- Specify rules for all elements of the array with the key '*'\r\n- Specify riules for a specific range of elements with a range as the key: '[0,1]'\r\n- Specify a single element with the element's index as the key: '[1]'\r\n##### Example:\r\n```javascript\r\nimport Validator from 'o-val';\r\n\r\nconst v = new Validator({\r\n\tarr: ['array', {\r\n\t\t'*': ['string'],\r\n\t\t'[0,1]': ['string', 'maxLength=5'],\r\n\t\t'[1]': ['string', 'isAlpha']\r\n\t}]\r\n});\r\n\r\nconst res = v.validate({\r\n\tarr: ['test123', 'test1']\r\n});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{\r\n  valid: false,\r\n  errors: {\r\n    arr: [\r\n      \"'arr[0]' must be at most 5 characters long\",\r\n      \"'arr[1]' must only contain alphabetical characters\"\r\n    ]\r\n  }\r\n}\r\n```\r\n---\r\n### Strict mode validation\r\nEnabling strict mode in a Validator will require the object being validated to match the Validator exactly. This includes:\r\n- Any keys included in the object that are not included in the specifications will throw an error\r\n- Any arrays must be the exact length covered by the array's element rules, and may not contain any elements past this defined range.\r\n##### Example:\r\n```javascript\r\nimport Validator from 'o-val';\r\n\r\nconst v = new Validator({\r\n\tname: 'string',\r\n\tarr1: ['array', {\r\n\t\t'[0,2]': 'string'\r\n\t}]\r\n});\r\n\r\nconst res1 = v.validate({\r\n\tname: 'Alvin',\r\n\tarr1: ['This', 'is', 'an', 'example'],\r\n\textra: 'Dave'\r\n});\r\n\r\nconsole.log('res1:', res1);\r\n\r\n// Enable strict mode\r\nv.strict = true;\r\n\r\nconst res2 = v.validate({\r\n\tname: 'Alvin',\r\n\tarr1: ['This', 'is', 'an', 'example'],\r\n\textra: 'Dave'\r\n});\r\n\r\nconsole.log('res2:', res2);\r\n\r\n```\r\n##### Output:\r\n```terminal\r\nres1: { \r\n  valid: true, \r\n  errors: {} \r\n}\r\n\r\nres2: {\r\n  valid: false,\r\n  errors: {\r\n    arr1: [\r\n      \"Array at key 'arr1' contains more elements than defined in the specs\"\r\n    ],\r\n    extra: [ \"Key 'extra' is not included in the specs\" ]\r\n  }\r\n}\r\n```\r\n\r\n## Custom Types and Rules\r\nYou can also import the OValConfig object to customize o-val to your needs. This includes the ability to add custom types that may not be covered by the build in types o-val provides, as well as adding new rules to both your custom types and the existing built in types.\r\n\r\n### Adding custom types\r\nYou can create a custom type using the addType method in the OValConfig object. This method contains three parameters:\r\n- Name: The name you want to give your new type\r\n- Fn: The function that validates whether a value matches your new type. Should accept one parameter of any type, and return a boolean (true if the value matches your type, false if not)\r\n- Proto (optional): The type which your custom type should inherit from. For example, if you pass 'string' as the proto, all of the string rules will also be made available for your new custom type. If this parameter is not provided, the default proto will be the Base type containing all of the base rules.\r\n##### Example:\r\n```javascript\r\nimport Validator, { OValConfig } from 'o-val';\r\n\r\nOValConfig.addType('comment',\r\n\t(value) => {\r\n\t\treturn value.startsWith('//');\r\n\t},\r\n\t'string'\r\n);\r\n\r\nconst v = new Validator({\r\n\tcomment1: 'comment',\r\n\t// Length minLength rule inherited from string type\r\n\tcomment2: ['comment', 'minLength=12'],\r\n\tcomment3: ['comment', 'minLength=12'] \r\n});\r\n\r\nconst res = v.validate({\r\n\tcomment1: 'not a comment',\r\n\tcomment2: '//tooshort',\r\n\tcomment3: '// valid comment'\r\n});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{\r\n  valid: false,\r\n  errors: {\r\n    comment1: [ \"'comment1' must be of type 'comment'\" ],\r\n    comment2: [ \"'comment2' must be at least 12 characters long\" ]\r\n  }\r\n}\r\n```\r\n---\r\n### Adding custom rules\r\nYou can create a custom rule using the addRule method in the OValConfig object. You can add rules to both built in types and custom types. Adding a new rule to a type will also add the rule for all the types that inherit off of it. This method contains four parameters:\r\n- Type: The type your new rule will apply for\r\n- Name: The name you want to give your new rule\r\n- Fn: The function that validates whether a value matches your new rule. Needs to be a nested function. The outer function will take any parameters required when defining a new Validator with this rule (no parameters if none are required). The inner function should accept one parameter of any type, and return a boolean (true if the value passes your rule, false if not)\r\n- Error message: The error message that should be returned if the rule fails. You can include a couple of replacements in the error message, and they will be replaced with the key, value, or arguments as needed:\r\n\t- {key}: Will be replaced with the key of the value that failed the rule\r\n\t- {value}: Will be replaced with the value that failed the rule\r\n\t- {arg0}, {arg1}, etc: Will be replaced with the specific argument passed for the rule\r\n\t- {args}: Will be replaced with all the arguments passed for the rule, comma separated\r\n##### Example:\r\n```javascript\r\nimport Validator, { OValConfig } from 'o-val';\r\n\r\nOValConfig.addRule('string', 'hasX',\r\n\t() => {\r\n\t\treturn (value) => {\r\n\t\t\treturn value.toLowerCase().includes('x');\r\n\t\t}\r\n\t},\r\n\t`Key '{key}' with value {value} has no X`\r\n);\r\n\r\nconst v = new Validator({\r\n\tname: ['string', 'hasX'],\r\n});\r\n\r\nconst res = v.validate({\r\n\tname: 'Alvin'\r\n});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{\r\n  valid: false,\r\n  errors: { \r\n    name: [ 'Key 'name' with value Alvin has no X' ] \r\n  }\r\n}\r\n```\r\n---\r\n### Adding custom rules with explicit parameters\r\nTo create a rule with explicit parameters, pass the parameters in the outer rule function.\r\n##### Example:\r\n```javascript\r\nimport Validator, { OValConfig } from 'o-val';\r\n\r\nOValConfig.addRule('string', 'hasChars',\r\n\t(char1, char2) => {\r\n\t\treturn (value) => {\r\n\t\t\treturn value.toLowerCase().includes(char1)\r\n\t\t\t\t|| value.toLowerCase().includes(char2);\r\n\t\t}\r\n\t},\r\n\t`Key '{key}' with value {value} has neither char {arg0} nor {arg1}`\r\n);\r\n\r\nconst v = new Validator({\r\n\tname: ['string', 'hasChars=z,1'],\r\n});\r\n\r\nconst res = v.validate({\r\n\tname: 'Alvin'\r\n});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{\r\n  valid: false,\r\n  errors: { \r\n    name: [ \"Key 'name' with value Alvin has neither char z nor 1\" ] \r\n  }\r\n}\r\n```\r\n---\r\n### Adding custom rules with any number of parameters\r\nTo create a rule with an undefined number parameters, pass the parameters in the outer rule function as ...args.\r\n##### Example:\r\n```javascript\r\nimport Validator, { OValConfig } from 'o-val';\r\n\r\nOValConfig.addRule('string', 'isOneOf',\r\n\t(...args) => {\r\n\t\treturn (value) => {\r\n\t\t\treturn args.includes(value);\r\n\t\t}\r\n\t},\r\n\t`Key '{key}' with value {value} is none of {args}`\r\n);\r\n\r\nconst v = new Validator({\r\n\tname: ['string', 'isOneOf=z,1,#,!'],\r\n});\r\n\r\nconst res = v.validate({\r\n\tname: 'Alvin'\r\n});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{\r\n  valid: false,\r\n  errors: { \r\n    name: [ \"Key 'name' with value Alvin is none of z, 1, #, !\" ]\r\n  }\r\n}\r\n```\r\n---\r\n### Inheriting custom rules\r\nAdding rule to a parent type will also make that new rule available to any types that inherit off of\r\n##### Example:\r\n```javascript\r\nimport Validator, { OValConfig } from 'o-val';\r\n\r\nOValConfig.addType('comment',\r\n\t(value) => {\r\n\t\treturn value.startsWith('//');\r\n\t},\r\n\t'string'\r\n);\r\n\r\nOValConfig.addRule('string', 'hasX',\r\n\t() => {\r\n\t\treturn (value) => {\r\n\t\t\treturn value.toLowerCase().includes('x');\r\n\t\t}\r\n\t},\r\n\t`Key '{key}' with value {value} has no X`\r\n);\r\n\r\nconst v = new Validator({\r\n\tname: ['string', 'hasX'],\r\n\tcomment: ['comment', 'hasX']\r\n});\r\n\r\nconst res = v.validate({\r\n\tname: 'Alvin',\r\n\tcomment: '// Comment',\r\n});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{\r\n  valid: false,\r\n  errors: {\r\n    name: [ \"'name' must be of type 'comment'\" ],\r\n    comment: [ \"Key 'comment' with value // Comment has no X\" ]\r\n  }\r\n}\r\n```\r\n\r\n## Types and Rules\r\n\r\n### Base Type\r\nThe base type is unaccessible, and cannot be used when defining a Validator. Instead, it is the type that all other types inherit off of, and the rules listed below are accessible by all other types.\r\n\r\n#### <u>Required</u>\r\nSets a field as required. If the field is not present, an error gets thrown. Set by default, adding it to your rule arrays is not necessary.\r\n##### Example:\r\n```javascript\r\nimport Validator from 'o-val';\r\n\r\nconst v = new Validator({\r\n\tname: ['string', 'required']\r\n});\r\n\r\nconst res = v.validate({});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{\r\n  valid: false,\r\n  errors: {\r\n    name: [ \"'name' is required\" ]\r\n  }\r\n}\r\n```\r\n#### <u>Optional</u>\r\nSets a field as optional. If the field is not present, no error is thrown and the rest of the rules for this field are not enforced.\r\n##### Example:\r\n```javascript\r\nimport Validator from 'o-val';\r\n\r\nconst v = new Validator({\r\n\tname: ['string', 'optional']\r\n});\r\n\r\nconst res = v.validate({});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{\r\n  valid: true,\r\n  errors: {}\r\n}\r\n```\r\n#### <u>isIn</u>\r\nChecks to see if the value is one of a list of options.\r\n##### Example:\r\n```javascript\r\nimport Validator from 'o-val';\r\n\r\nconst v = new Validator({\r\n\tname: ['string', 'isIn=Alvin,Simon,Theodore']\r\n});\r\n\r\nconst res = v.validate({\r\n\tname: 'Dave'\r\n});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{\r\n  valid: false,\r\n  errors: { \r\n    name: [ \"'name' must be one of [Alvin, Simon, Theodore]\" ] \r\n  }\r\n}\r\n```\r\n---\r\n\r\n### String\r\nString type\r\n\r\n#### <u>string</u>\r\nString's type rule. Checks if the given value's typeof is 'string'.\r\n##### Example:\r\n```javascript\r\nimport Validator from 'o-val';\r\n\r\nconst v = new Validator({\r\n\tname: 'string'\r\n});\r\n\r\nconst res = v.validate({\r\n\tname: 0\r\n});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{\r\n  valid: false,\r\n  errors: {\r\n    name: [ \"'name' must be of type 'string'\" ]\r\n  }\r\n}\r\n```\r\n#### <u>isEmpty</u>\r\nChecks if the string is empty.\r\n##### Example:\r\n```javascript\r\nimport Validator from 'o-val';\r\n\r\nconst v = new Validator({\r\n\tname: ['string', 'isEmpty']\r\n});\r\n\r\nconst res = v.validate({\r\n\tname: 'Alvin'\r\n});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{\r\n  valid: false,\r\n  errors: {\r\n    name: [ \"'name' must be an empty string\" ]\r\n  }\r\n}\r\n```\r\n#### <u>minLength</u>\r\nChecks if the string is at least a certain length. Takes one number as a parameter.\r\n##### Example:\r\n```javascript\r\nimport Validator from 'o-val';\r\n\r\nconst v = new Validator({\r\n\tname: ['string', 'minLength=6']\r\n});\r\n\r\nconst res = v.validate({\r\n\tname: 'Alvin'\r\n});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{\r\n  valid: false,\r\n  errors: {\r\n    name: [ \"'name' must be at least 6 characters long\" ]\r\n  }\r\n}\r\n```\r\n#### <u>maxLength</u>\r\nChecks if the string is no more than a certain length. Takes one number as a parameter.\r\n##### Example:\r\n```javascript\r\nimport Validator from 'o-val';\r\n\r\nconst v = new Validator({\r\n\tname: ['string', 'maxLength=4']\r\n});\r\n\r\nconst res = v.validate({\r\n\tname: 'Alvin'\r\n});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{\r\n  valid: false,\r\n  errors: {\r\n    name: [ \"'name' must be at most 4 characters long\" ]\r\n  }\r\n}\r\n```\r\n#### <u>matches</u>\r\nChecks if the string matches a given Regex string. Takes one Regex string as a parameter.\r\n##### Example:\r\n```javascript\r\nimport Validator from 'o-val';\r\n\r\nconst v = new Validator({\r\n\tname: ['string', 'matches=[0-9]+']\r\n});\r\n\r\nconst res = v.validate({\r\n\tname: 'Alvin'\r\n});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{\r\n  valid: false,\r\n  errors: {\r\n    name: [ \"'name' must match the format [0-9]+\" ]\r\n  }\r\n}\r\n```\r\n#### <u>isNumeric</u>\r\nChecks if the string only contains numeric characters.\r\n##### Example:\r\n```javascript\r\nimport Validator from 'o-val';\r\n\r\nconst v = new Validator({\r\n\tageStr: ['string', 'isNumeric'],\r\n\tageStr2: ['string', 'isNumeric']\r\n});\r\n\r\nconst res = v.validate({\r\n\tageStr: '123',\r\n\tageStr2: 'abc'\r\n});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{\r\n  valid: false,\r\n  errors: {\r\n    ageStr2: [ \"'ageStr2' must be numeric\" ]\r\n  }\r\n}\r\n```\r\n#### <u>isAlphaNumeric</u>\r\nChecks if the string only contains alphanumeric characters.\r\n##### Example:\r\n```javascript\r\nimport Validator from 'o-val';\r\n\r\nconst v = new Validator({\r\n\tname: ['string', 'isAlphaNumeric'],\r\n\tname2: ['string', 'isAlphaNumeric']\r\n});\r\n\r\nconst res = v.validate({\r\n\tname: 'Alvin1',\r\n\tname2: 'Alvin_2'\r\n});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{\r\n  valid: false,\r\n  errors: {\r\n    name2: [ \"'name2' must be alphanumeric\" ]\r\n  }\r\n}\r\n```\r\n#### <u>isAlpha</u>\r\nChecks if the string only contains alphabetical characters.\r\n##### Example:\r\n```javascript\r\nimport Validator from 'o-val';\r\n\r\nconst v = new Validator({\r\n\tname: ['string', 'isAlpha']\r\n});\r\n\r\nconst res = v.validate({\r\n\tname: 'Alvin1'\r\n});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{\r\n  valid: false,\r\n  errors: {\r\n    name: [ \"'name2' must only contain alphabetical characters\" ]\r\n  }\r\n}\r\n```\r\n#### <u>isUpperCase</u>\r\nChecks if the string only contains uppercase characters.\r\n##### Example:\r\n```javascript\r\nimport Validator from 'o-val';\r\n\r\nconst v = new Validator({\r\n\tname: ['string', 'isUpperCase']\r\n});\r\n\r\nconst res = v.validate({\r\n\tname: 'Alvin'\r\n});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{\r\n  valid: false,\r\n  errors: {\r\n    name: [ \"'name' must only contain uppercase characters\" ]\r\n  }\r\n}\r\n```\r\n#### <u>isLowerCase</u>\r\nChecks if the string only contains lowercase characters.\r\n##### Example:\r\n```javascript\r\nimport Validator from 'o-val';\r\n\r\nconst v = new Validator({\r\n\tname: ['string', 'isLowerCase']\r\n});\r\n\r\nconst res = v.validate({\r\n\tname: 'Alvin'\r\n});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{\r\n  valid: false,\r\n  errors: {\r\n    name: [ \"'name' must only contain lowercase characters\" ]\r\n  }\r\n}\r\n```\r\n---\r\n\r\n### Number\r\nNumber type\r\n\r\n#### <u>number</u>\r\nNumber's type rule. Checks if the given value's typeof is 'number'.\r\n##### Example:\r\n```javascript\r\nimport Validator from 'o-val';\r\n\r\nconst v = new Validator({\r\n\tage: 'number'\r\n});\r\n\r\nconst res = v.validate({\r\n\tage: 'Alvin'\r\n});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{\r\n  valid: false,\r\n  errors: {\r\n    age: [ \"'age' must be of type 'number'\" ]\r\n  }\r\n}\r\n```\r\n#### <u>minValue</u>\r\nChecks if the number is greater than or equal to a given value. Takes one number as a parameter.\r\n##### Example:\r\n```javascript\r\nimport Validator from 'o-val';\r\n\r\nconst v = new Validator({\r\n\tage: ['number', 'minValue=5']\r\n});\r\n\r\nconst res = v.validate({\r\n\tage: 4\r\n});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{\r\n  valid: false,\r\n  errors: {\r\n    age: [ \"'age' must be 5 or greater\" ]\r\n  }\r\n}\r\n```\r\n#### <u>maxValue</u>\r\nChecks if the number is less than or equal to a given value. Takes one number as a parameter.\r\n##### Example:\r\n```javascript\r\nimport Validator from 'o-val';\r\n\r\nconst v = new Validator({\r\n\tage: ['number', 'maxValue=5']\r\n});\r\n\r\nconst res = v.validate({\r\n\tage: 6\r\n});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{\r\n  valid: false,\r\n  errors: {\r\n    age: [ \"'age' must be 5 or less\" ]\r\n  }\r\n}\r\n```\r\n#### <u>between</u>\r\nChecks if the number is between two given values. Takes two numbers as parameters.\r\n##### Example:\r\n```javascript\r\nimport Validator from 'o-val';\r\n\r\nconst v = new Validator({\r\n\tage: ['number', 'between=5,10']\r\n});\r\n\r\nconst res = v.validate({\r\n\tage: 4\r\n});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{\r\n  valid: false,\r\n  errors: {\r\n    age: [ \"'age' must be between 5 and 10\" ]\r\n  }\r\n}\r\n```\r\n#### <u>isInt</u>\r\nChecks if the number is an integer.\r\n##### Example:\r\n```javascript\r\nimport Validator from 'o-val';\r\n\r\nconst v = new Validator({\r\n\tage: ['number', 'isInt']\r\n});\r\n\r\nconst res = v.validate({\r\n\tage: 14.5\r\n});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{\r\n  valid: false,\r\n  errors: {\r\n    age: [ \"'age' must be an integer\" ]\r\n  }\r\n}\r\n```\r\n#### <u>isDecimal</u>\r\nChecks if the number is an decimal value.\r\n##### Example:\r\n```javascript\r\nimport Validator from 'o-val';\r\n\r\nconst v = new Validator({\r\n\tage: ['number', 'isDecimal']\r\n});\r\n\r\nconst res = v.validate({\r\n\tage: 14\r\n});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{\r\n  valid: false,\r\n  errors: {\r\n    age: [ \"'age' must be a decimal\" ]\r\n  }\r\n}\r\n```\r\n---\r\n\r\n### Boolean\r\nBoolean type\r\n\r\n#### <u>boolean</u>\r\nBoolean's type rule. Checks if the given value's typeof is 'boolean'.\r\n##### Example:\r\n```javascript\r\nimport Validator from 'o-val';\r\n\r\nconst v = new Validator({\r\n\tisRegistered: 'boolean'\r\n});\r\n\r\nconst res = v.validate({\r\n\tisRegistered: 'Alvin'\r\n});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{\r\n  valid: false,\r\n  errors: {\r\n    isRegistered: [ \"'isRegistered' must be a boolean'\" ]\r\n  }\r\n}\r\n```\r\n#### <u>isTrue</u>\r\nChecks if the boolean is true.\r\n##### Example:\r\n```javascript\r\nimport Validator from 'o-val';\r\n\r\nconst v = new Validator({\r\n\tisRegistered: ['boolean', 'isTrue']\r\n});\r\n\r\nconst res = v.validate({\r\n\tisRegistered: false\r\n});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{\r\n  valid: false,\r\n  errors: {\r\n    isRegistered: [ \"'isRegistered' must be 'true'\" ]\r\n  }\r\n}\r\n```\r\n#### <u>isFalse</u>\r\nChecks if the boolean is false.\r\n##### Example:\r\n```javascript\r\nimport Validator from 'o-val';\r\n\r\nconst v = new Validator({\r\n\tisRegistered: ['boolean', 'isFalse']\r\n});\r\n\r\nconst res = v.validate({\r\n\tisRegistered: true\r\n});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{\r\n  valid: false,\r\n  errors: {\r\n    isRegistered: [ \"'isRegistered' must be 'false'\" ]\r\n  }\r\n}\r\n```\r\n---\r\n\r\n### Object\r\nObject type\r\n\r\n#### <u>object</u>\r\nObject's type rule. Checks if the given value's typeof is 'object'.\r\n##### Example:\r\n```javascript\r\nimport Validator from 'o-val';\r\n\r\nconst v = new Validator({\r\n\tvalues: ['object', {\r\n\t\tname: 'string'\r\n\t}]\r\n});\r\n\r\nconst res = v.validate({\r\n\tvalues: 'Alvin'\r\n});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{\r\n  valid: false,\r\n  errors: {\r\n    values: [ \"'values' must be an object\" ]\r\n  }\r\n}\r\n```\r\n#### <u>notEmpty</u>\r\nChecks if the object has values.\r\n##### Example:\r\n```javascript\r\nimport Validator from 'o-val';\r\n\r\nconst v = new Validator({\r\n\tvalues: ['object', 'notEmpty', {\r\n\t\tname: 'string'\r\n\t}]\r\n});\r\n\r\nconst res = v.validate({\r\n\tvalues: {}\r\n});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{\r\n  valid: false,\r\n  errors: {\r\n    values: [ \"'values' must not be an empty object\" ]\r\n  }\r\n}\r\n```\r\n---\r\n\r\n### Array\r\nArray type\r\n\r\n#### <u>array</u>\r\nArray's type rule. Checks if the given value is a Javascript Array.\r\n##### Example:\r\n```javascript\r\nimport Validator from 'o-val';\r\n\r\nconst v = new Validator({\r\n\tvalues: ['array', {\r\n\t\t'[*]': 'number'\r\n\t}]\r\n});\r\n\r\nconst res = v.validate({\r\n\tvalues: 1\r\n});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{\r\n  valid: false,\r\n  errors: {\r\n    values: [ \"'values' must be an array\" ]\r\n  }\r\n}\r\n```\r\n#### <u>notEmpty</u>\r\nChecks if the array has values.\r\n##### Example:\r\n```javascript\r\nimport Validator from 'o-val';\r\n\r\nconst v = new Validator({\r\n\tvalues: ['array', 'notEmpty', {\r\n\t\t'[*]': 'number'\r\n\t}]\r\n});\r\n\r\nconst res = v.validate({\r\n\tvalues: []\r\n});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{\r\n  valid: false,\r\n  errors: {\r\n    values: [ \"'values' must not be an empty array\" ]\r\n  }\r\n}\r\n```\r\n#### <u>minLength</u>\r\nChecks if the array has at least a given number of values. Takes one number as a parameter.\r\n##### Example:\r\n```javascript\r\nimport Validator from 'o-val';\r\n\r\nconst v = new Validator({\r\n\tvalues: ['array', 'minLength=3', {\r\n\t\t'[*]': 'number'\r\n\t}]\r\n});\r\n\r\nconst res = v.validate({\r\n\tvalues: [1,2]\r\n});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{\r\n  valid: false,\r\n  errors: {\r\n    values: [ \"'values' must contain at least 3 elements\" ]\r\n  }\r\n}\r\n```\r\n#### <u>maxLength</u>\r\nChecks if the array has at most a given number of values. Takes one number as a parameter.\r\n##### Example:\r\n```javascript\r\nimport Validator from 'o-val';\r\n\r\nconst v = new Validator({\r\n\tvalues: ['array', 'maxLength=3', {\r\n\t\t'[*]': 'number'\r\n\t}]\r\n});\r\n\r\nconst res = v.validate({\r\n\tvalues: [1,2,3,4]\r\n});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{\r\n  valid: false,\r\n  errors: {\r\n    values: [ \"'values' must not contain more than 3 elements\" ]\r\n  }\r\n}\r\n```\r\n#### <u>exactLength</u>\r\nChecks if the array has exactly a given number of values. Takes one number as a parameter.\r\n##### Example:\r\n```javascript\r\nimport Validator from 'o-val';\r\n\r\nconst v = new Validator({\r\n\tvalues: ['array', 'exactLength=3', {\r\n\t\t'[*]': 'number'\r\n\t}]\r\n});\r\n\r\nconst res = v.validate({\r\n\tvalues: [1,2]\r\n});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{\r\n  valid: false,\r\n  errors: {\r\n    values: [ \"'values' must contain exactly 3 elements\" ]\r\n  }\r\n}\r\n```\r\n---\r\n\r\n### Email\r\nEmail type. Inherits from the String type, meaning all of [String's](#string) rules can also be used for Email type values.\r\n\r\n#### <u>email</u>\r\nEmail's type rule. Checks if the given value is string in the format of an email address.\r\n##### Example:\r\n```javascript\r\nimport Validator from 'o-val';\r\n\r\nconst v = new Validator({\r\n\temail: 'email'\r\n});\r\n\r\nconst res = v.validate({\r\n\temail: 'abc'\r\n});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{\r\n  valid: false,\r\n  errors: {\r\n    email: [ \"'email' must be a valid email address\" ]\r\n  }\r\n}\r\n```\r\n#### <u>hasDomain</u>\r\nChecks if the email has a given domain. Takes one string as a parameter.\r\n##### Example:\r\n```javascript\r\nimport Validator from 'o-val';\r\n\r\nconst v = new Validator({\r\n\temail: ['email','hasDomain=asalmi.com'],\r\n\temail2: ['email','hasDomain=asalmi.com']\r\n});\r\n\r\nconst res = v.validate({\r\n\temail: 'abc@asalmi.com',\r\n\temail2: 'abc@gmail.com'\r\n});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{\r\n  valid: false,\r\n  errors: {\r\n    email2: [ \"'email2' must be an email address on the domain 'asalmi.com'\" ]\r\n  }\r\n}\r\n```\r\n---\r\n\r\n### Phone\r\nPhone type. Inherits from the String type, meaning all of [String's](#string) rules can also be used for Phone type values.\r\n\r\n#### <u>phone</u>\r\nPhone's type rule. Checks if the given value is string in the format of a phone number.\r\n##### Example:\r\n```javascript\r\nimport Validator from 'o-val';\r\n\r\nconst v = new Validator({\r\n\tphone: 'phone'\r\n});\r\n\r\nconst res = v.validate({\r\n\tphone: '()123'\r\n});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{\r\n  valid: false,\r\n  errors: {\r\n    phone: [ \"'phone' must be a valid phone number\" ]\r\n  }\r\n}\r\n```\r\n#### <u>hasCountryCode</u>\r\nChecks if the phone number contains a given country code. Takes one string as a parameter.\r\n##### Example:\r\n```javascript\r\nimport Validator from 'o-val';\r\n\r\nconst v = new Validator({\r\n\tphone: ['phone', 'hasCountryCode=+1'],\r\n\tphone2: ['phone', 'hasCountryCode=+1'],\r\n\tphone3: ['phone', 'hasCountryCode=+1']\r\n});\r\n\r\nconst res = v.validate({\r\n\tphone: '+1 (123)456-7890',\r\n\tphone2: '+11234567890',\r\n\tphone3: '+2 1234567890',\r\n});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{\r\n  valid: false,\r\n  errors: {\r\n    phone3: [ \"'phone3' must have country code '+1'\" ]\r\n  }\r\n}\r\n```\r\n---\r\n\r\n### Date\r\nDate type. Inherits from the String type, meaning all of [String's](#string) rules can also be used for Date type values.\r\n\r\n#### <u>date</u>\r\nDate's type rule. Checks if the given value is string in the format of a date, and is a valid date.\r\n##### Example:\r\n```javascript\r\nimport Validator from 'o-val';\r\n\r\nconst v = new Validator({\r\n\tDOB: 'date',\r\n\tDOB2: 'date',\r\n});\r\n\r\nconst res = v.validate({\r\n\tDOB: '31/31/2000',\r\n\tDOB2: '0-0-2000'\r\n});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{\r\n  valid: false,\r\n  errors: {\r\n    DOB: [ \"'DOB' must be a valid date\" ],\r\n    DOB2: [ \"'DOB2' must be a valid date\" ]\r\n  }\r\n}\r\n```\r\n#### <u>before</u>\r\nChecks if the date is before a given date. Takes one string as a parameter.\r\n##### Example:\r\n```javascript\r\nimport Validator from 'o-val';\r\n\r\nconst v = new Validator({\r\n\tDOB: ['date', 'before=01/01/2000']\r\n});\r\n\r\nconst res = v.validate({\r\n\tDOB: '01/01/2000'\r\n});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{\r\n  valid: false,\r\n  errors: {\r\n    DOB: [ \"'DOB' must be a date before 01/01/2000\" ]\r\n  }\r\n}\r\n```\r\n#### <u>after</u>\r\nChecks if the date is after a given date. Takes one string as a parameter.\r\n##### Example:\r\n```javascript\r\nimport Validator from 'o-val';\r\n\r\nconst v = new Validator({\r\n\tDOB: ['date', 'after=01/01/2000']\r\n});\r\n\r\nconst res = v.validate({\r\n\tDOB: '01/01/2000'\r\n});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{\r\n  valid: false,\r\n  errors: {\r\n    DOB: [ \"'DOB' must be a date after 01/01/2000\" ]\r\n  }\r\n}\r\n```\r\n#### <u>between</u>\r\nChecks if the date is between two given dates. Takes two strings as parameters.\r\n##### Example:\r\n```javascript\r\nimport Validator from 'o-val';\r\n\r\nconst v = new Validator({\r\n\tDOB: ['date', 'between=01/01/2000,12/31/2000']\r\n});\r\n\r\nconst res = v.validate({\r\n\tDOB: '01/01/2000'\r\n});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{\r\n  valid: false,\r\n  errors: {\r\n    DOB: [ \"'DOB' must be a date between 01/01/2000 and 12/31/2000\" ]\r\n  }\r\n}\r\n```\r\n#### <u>exactDate</u>\r\nChecks if the date is the same as a given date. Takes one string as a parameter.\r\n##### Example:\r\n```javascript\r\nimport Validator from 'o-val';\r\n\r\nconst v = new Validator({\r\n\tDOB: ['date', 'exactDate=01/01/2000']\r\n});\r\n\r\nconst res = v.validate({\r\n\tDOB: '01/02/2000'\r\n});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{\r\n  valid: false,\r\n  errors: {\r\n    DOB: [ \"'DOB' must be 01/01/2000\" ]\r\n  }\r\n}\r\n```\r\n#### <u>inYear</u>\r\nChecks if the date is in a given year. Takes one string as a parameter.\r\n##### Example:\r\n```javascript\r\nimport Validator from 'o-val';\r\n\r\nconst v = new Validator({\r\n\tDOB: ['date', 'inYear=2000']\r\n});\r\n\r\nconst res = v.validate({\r\n\tDOB: '01/01/2001'\r\n});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{\r\n  valid: false,\r\n  errors: {\r\n    DOB: [ \"'DOB' must be in the year 2000\" ]\r\n  }\r\n}\r\n```\r\n#### <u>inMonth</u>\r\nChecks if the date is in a given month. Takes one string as a parameter.\r\n##### Example:\r\n```javascript\r\nimport Validator from 'o-val';\r\n\r\nconst v = new Validator({\r\n\tDOB: ['date', 'inMonth=1']\r\n});\r\n\r\nconst res = v.validate({\r\n\tDOB: '02/01/2001'\r\n});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{\r\n  valid: false,\r\n  errors: {\r\n    DOB: [ \"'DOB' must be in the month 1'\" ]\r\n  }\r\n}\r\n```\r\n---\r\n\r\n### URL\r\nURL type. Inherits from the String type, meaning all of [String's](#string) rules can also be used for URL type values.\r\n\r\n#### <u>url</u>\r\nURL's type rule. Checks if the given value is string in the format of a URL.\r\n##### Example:\r\n```javascript\r\nimport Validator from 'o-val';\r\n\r\nconst v = new Validator({\r\n\thomepage: 'url'\r\n});\r\n\r\nconst res = v.validate({\r\n\thomepage: 'asalmi'\r\n});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{\r\n  valid: false,\r\n  errors: {\r\n    homepage: [ \"'homepage' must be a valid URL\" ]\r\n  }\r\n}\r\n```\r\n#### <u>hasDomain</u>\r\nChecks if the URL has a given domain. Takes one string as a parameter.\r\n##### Example:\r\n```javascript\r\nimport Validator from 'o-val';\r\n\r\nconst v = new Validator({\r\n\thomepage: ['url', 'hasDomain=asalmi.com'],\r\n\thomepage2: ['url', 'hasDomain=asalmi.com']\r\n});\r\n\r\nconst res = v.validate({\r\n\thomepage: 'https://www.asalmi.com',\r\n\thomepage2: 'https://www.google.com'\r\n});\r\n\r\nconsole.log(res);\r\n```\r\n##### Output:\r\n```terminal\r\n{\r\n  valid: false,\r\n  errors: {\r\n    homepage2: [ \"'homepage2' must be a URL with the domain 'asalmi.com'\" ]\r\n  }\r\n}\r\n```\r\n---","readmeFilename":"README.md"}