A cross-browser / node.js validator used by resourceful and flatiron.
The core of revalidator is simple and succinct: revalidator.validate(obj, schema):
var revalidator = require('revalidator');
console.dir(revalidator.validate(someObject, {
properties: {
url: {
description: 'the url the object should be stored at',
type: 'string',
pattern: '^/[^#%&*{}\\:<>?\/+]+$',
required: true
},
challenge: {
description: 'a means of protecting data (insufficient for production, used as example)',
type: 'string',
minLength: 5
},
body: {
description: 'what to store at the url',
type: 'any',
default: null
}
}
});This 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.
{
valid: true // or false
errors: [/* Array of errors if valid is false */]
}In the browser, the validation function is exposed on window.validate by simply including revalidator.js.
$ curl http://npmjs.org/install.sh | sh $ [sudo] npm install revalidatorAll tests are written with vows and should be run with npm:
$ npm test