{"_id":"@10pearls/revalidator","_rev":"16-7dec1ee724eeeb9e5eec5081ca7a2b09","name":"@10pearls/revalidator","description":"A cross-browser / node.js validator powered by JSON Schema","dist-tags":{"latest":"0.3.1"},"versions":{"0.3.1":{"name":"@10pearls/revalidator","version":"0.3.1","description":"A cross-browser / node.js validator powered by JSON Schema","license":"Apache-2.0","author":{"name":"Charlie Robbins","email":"charlie.robbins@gmail.com"},"maintainers":[{"name":"cloudhead","email":"alexis@cloudhead.io"},{"name":"indutny","email":"fedor.indutny@gmail.com"},{"name":"alyyousuf7","email":"aly.yousuf7@gmail.com"}],"repository":{"type":"git","url":"git+ssh://git@github.com/10pearls/revalidator.git"},"devDependencies":{"vows":"0.8.x"},"main":"./lib/revalidator","scripts":{"test":"vows test/*-test.js --spec"},"engines":{"node":">= 0.8.0"},"gitHead":"23cdbdea277e5b64429eeea2493dd6219d163774","bugs":{"url":"https://github.com/10pearls/revalidator/issues"},"homepage":"https://github.com/10pearls/revalidator#readme","_id":"@10pearls/revalidator@0.3.1","_npmVersion":"5.0.3","_nodeVersion":"8.0.0","_npmUser":{"name":"mohuk","email":"mohammad.umair.k@gmail.com"},"dist":{"integrity":"sha512-5vgFdhrc/kCbuZLQught/XDC5OBai5AZLXXND8hatMlPXZyLrn6kccg8O0Cr5YcNo2aQi3MaNcCsPpz5o6yKwg==","shasum":"30be959d9bc09b8b8ee0d768ebbf40615bb78f51","tarball":"https://registry.npmjs.org/@10pearls/revalidator/-/revalidator-0.3.1.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCS0jJLndkhjocRGlh9jUofkKcSyW+2mrFqXEsNwIpXGgIgMkum6c60wW2XMrP27RSbd6HRA4XkxC0fopfAN1eywUQ="}]},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/revalidator-0.3.1.tgz_1497515231812_0.663235402898863"},"directories":{}}},"readme":"# revalidator [![Build Status](https://secure.travis-ci.org/flatiron/revalidator.png)](http://travis-ci.org/flatiron/revalidator)\n\nA cross-browser / node.js validator with [JSONSchema](http://tools.ietf.org/html/draft-zyp-json-schema-04) compatibility as the primary goal.\n\n## Example\nThe core of `revalidator` is simple and succinct: `revalidator.validate(obj, schema)`:\n\n``` js\n  var revalidator = require('revalidator');\n\n  console.dir(revalidator.validate(someObject, {\n    properties: {\n      url: {\n        description: 'the url the object should be stored at',\n        type: 'string',\n        pattern: '^/[^#%&*{}\\\\:<>?\\/+]+$',\n        required: true\n      },\n      challenge: {\n        description: 'a means of protecting data (insufficient for production, used as example)',\n        type: 'string',\n        minLength: 5\n      },\n      body: {\n        description: 'what to store at the url',\n        type: 'any',\n        default: null\n      }\n    }\n  }));\n```\n\nThis will return with a value indicating if the `obj` conforms to the `schema`. If it does not, a descriptive object will be returned containing the errors encountered with validation.\n\n``` js\n  {\n    valid: true // or false\n    errors: [/* Array of errors if valid is false */]\n  }\n```\n\nIn the browser, the validation function is exposed on `window.validate` by simply including `revalidator.js`.\n\n## Installation\n\n### Installing npm (node package manager)\n``` bash\n  $ curl http://npmjs.org/install.sh | sh\n```\n\n### Installing revalidator\n``` bash\n  $ [sudo] npm install revalidator\n```\n\n## Usage\n\n`revalidator` takes json-schema as input to validate objects.\n\n### revalidator.validate (obj, schema, options)\n\nThis will return with a value indicating if the `obj` conforms to the `schema`. If it does not, a descriptive object will be returned containing the errors encountered with validation.\n\n``` js\n{\n  valid: true // or false\n  errors: [/* Array of errors if valid is false */]\n}\n```\n\n#### Available Options\n\n* __validateFormats__: Enforce format constraints (_default true_)\n* __validateFormatsStrict__: When `validateFormats` is _true_ treat unrecognized formats as validation errors (_default false_)\n* __validateFormatExtensions__: When `validateFormats` is _true_ also validate formats defined in `validate.formatExtensions` (_default true_)\n* __additionalProperties__: When `additionalProperties` is _true_ allow additional unvisited properties on the object. (_default true_)\n* __cast__: Enforce casting of some types (for integers/numbers are only supported) when it's possible, e.g. `\"42\" => 42`, but `\"forty2\" => \"forty2\"` for the `integer` type.\n\n### Schema\nFor a property an `value` is that which is given as input for validation where as an `expected value` is the value of the below fields\n\n#### required\nIf true, the value should not be undefined\n\n```js\n{ required: true }\n```\n\n#### allowEmpty\nIf false, the value must not be an empty string\n\n```js\n{ allowEmpty: false }\n```\n\n#### type\nThe `type of value` should be equal to the expected value\n\n```js\n{ type: 'string' }\n{ type: 'number' }\n{ type: 'integer' }\n{ type: 'array' }\n{ type: 'boolean' }\n{ type: 'object' }\n{ type: 'null' }\n{ type: 'any' }\n{ type: ['boolean', 'string'] }\n```\n\n#### pattern\nThe expected value regex needs to be satisfied by the value\n\n```js\n{ pattern: /^[a-z]+$/ }\n```\n\n#### maxLength\nThe length of value must be greater than or equal to expected value\n\n```js\n{ maxLength: 8 }\n```\n\n#### minLength\nThe length of value must be lesser than or equal to expected value\n\n```js\n{ minLength: 8 }\n```\n\n#### minimum\nValue must be greater than or equal to the expected value\n\n```js\n{ minimum: 10 }\n```\n\n#### maximum\nValue must be lesser than or equal to the expected value\n\n```js\n{ maximum: 10 }\n```\n\n#### allowEmpty\nValue may not be empty\n\n```js\n{ allowEmpty: false }\n```\n\n#### exclusiveMinimum\nValue must be greater than expected value\n\n```js\n{ exclusiveMinimum: 9 }\n```\n\n#### exclusiveMaximum\nValue must be lesser than expected value\n\n```js\n{ exclusiveMaximum: 11 }\n```\n\n#### divisibleBy\nValue must be divisible by expected value\n\n```js\n{ divisibleBy: 5 }\n{ divisibleBy: 0.5 }\n```\n\n#### minItems\nValue must contain more than expected number of items\n\n```js\n{ minItems: 2 }\n```\n\n#### maxItems\nValue must contain fewer than expected number of items\n\n```js\n{ maxItems: 5 }\n```\n\n#### uniqueItems\nValue must hold a unique set of values\n\n```js\n{ uniqueItems: true }\n```\n\n#### enum\nValue must be present in the array of expected values\n\n```js\n{ enum: ['month', 'year'] }\n```\n\n#### format\nValue must be a valid format\n\n```js\n{ format: 'url' }\n{ format: 'email' }\n{ format: 'ip-address' }\n{ format: 'ipv6' }\n{ format: 'date-time' }\n{ format: 'date' }\n{ format: 'time' }\n{ format: 'color' }\n{ format: 'host-name' }\n{ format: 'utc-millisec' }\n{ format: 'regex' }\n```\n\n#### conform\nValue must conform to constraint denoted by expected value\n\n```js\n{ conform: function (v) {\n    if (v%3==1) return true;\n    return false;\n  }\n}\n```\n\n#### dependencies\nValue is valid only if the dependent value is valid\n\n```js\n{\n  town: { required: true, dependencies: 'country' },\n  country: { maxLength: 3, required: true }\n}\n```\n\n### Nested Schema\nWe also allow nested schema\n\n```js\n{\n  properties: {\n    title: {\n      type: 'string',\n      maxLength: 140,\n      required: true\n    },\n    author: {\n      type: 'object',\n      required: true,\n      properties: {\n        name: {\n          type: 'string',\n          required: true\n        },\n        email: {\n          type: 'string',\n          format: 'email'\n        }\n      }\n    }\n  }\n}\n```\n\n### Custom Messages\nWe also allow custom messages for different constraints\n\n```js\n{\n  type: 'string',\n  format: 'url'\n  messages: {\n    type: 'Not a string type',\n    format: 'Expected format is a url'\n  }\n```\n\n```js\n{\n  conform: function () { ... },\n  message: 'This can be used as a global message'\n}\n```\n\n## Tests\nAll tests are written with [vows][0] and should be run with [npm][1]:\n\n``` bash\n  $ npm test\n```\n\n#### Author: [Charlie Robbins](https://github.com/indexzero), [Alexis Sellier](http://cloudhead.io)\n#### Contributors: [Fedor Indutny](http://github.com/indutny), [Bradley Meck](http://github.com/bmeck), [Laurie Harper](http://laurie.holoweb.net/), [Martijn Swaagman](http://www.martijnswaagman.nl)\n#### License: Apache 2.0\n\n[0]: http://vowsjs.org\n[1]: http://npmjs.org\n","maintainers":[{"email":"nms@10pearls.com","name":"itteam"},{"email":"asadurrehman@10pearls.com","name":"asadurrehman10p"}],"time":{"modified":"2022-04-04T10:30:23.026Z","created":"2017-06-15T08:27:12.966Z","0.3.1":"2017-06-15T08:27:12.966Z"},"homepage":"https://github.com/10pearls/revalidator#readme","repository":{"type":"git","url":"git+ssh://git@github.com/10pearls/revalidator.git"},"author":{"name":"Charlie Robbins","email":"charlie.robbins@gmail.com"},"bugs":{"url":"https://github.com/10pearls/revalidator/issues"},"license":"Apache-2.0","readmeFilename":"README.md"}