validate-params

A small parameter validation library

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
validate-params
711.0.08 years ago8 years agoMinified + gzip package size for validate-params in KB

Readme

validate-params
A small parameter validation library The purpose of this library is to easily check that the contract of your functions are not violated; and if they are, to allow you to gracefully handle the situation (provide useful error messages). !Build Statustravis-imagetravis-url !Coveralls Statuscoveralls-imagecoveralls-url !Code Climatecc-imagecc-url
Basic examples
```js var Validator = require('validate-params'); // validating a single argument function simpleWrapper(callback){
Validator.assert.arg(callback, 'function');
//Then do something with the callback later
//At this point we can be sure that callback is a function
} simpleWrapper(42); //throws Error('Expected type "function" but it was type "number"') // validating an argument object function myCoolFunction(opts){
Validator.assert.arg(opts,
{name: 'string',
//handles optional parameters
phoneNum: {
type: 'string',
optional: true
},
//handles nested objects
location: {
city: 'string',
longitude: 'number',
latitude: 'number'
}
});
//...
} myCoolFunction({name: 'Jenny',
phoneNum: '876-5309',
location: {
city: 'Chicago',
longitude: 87.6847,
latitude: 41.8369
}
});
```
Documentation
To learn more checkout the documentation page (docs/index.md)
License
MIT - view the full license here (LICENSE)