credible
Credible is a library for validating objects in node.js or the browser. While it provides several validators out of the box, credible is very unopinionated; mostly, credible simply provides a framework for object validation.
Installation
Credible has two dependencies:
Node.js
$ npm install credible --save
Browser
<script src="/lodash.js"></script>
<script src="/bluebird.js"></script>
<script src="/credible.js"></script>
Example
var person = {
firstName: 'Noah',
lastName: 'Portes Chaikin'
}
var credible = new Credible({
firstName: 'alpha'
lastName: 'alpha'
});
credible.run(person)
.catch(function(err) {
console.log(err);
})
API
var rulesObject = {
username: 'alpha',
email: ['presence', 'email']
}
new Credible(rulesObject);
The most straightforward and "built to order" way to get started is by passing an object to the Credible constructor with the properties you'd like to validate and the rules you'd like to validate the property against.
Rules can either reference a native validator or be a function:
var rulesObject = {
username: 'alpha',
email: function (model, attribute) {
if (!email) throw 'No e-mail provided'
}
}
new Credible(rulesObject);
Credible.validate()
returns a chainable object.
var credible = new Credible()
credible.validate('');
To Do