Bemu Validator
Bemu Validator is a simple, easy customizable JavaScript object validator. It contains many ways of validating predefined and also custom defined objects in a configurable manner. The package has no dependencies making it small and portable. Every method has multiple tests, with 100% code coverage making it somewhat well tested.
Setting up
To install the package simply do
npm i --save bemu-validator
After installaton you can require or import it to your project as
const bemuValidator = ;
or
;
Or you can require any individual validator via the destructuring assignment syntax
// Require only the methods you needconst isString isNumber isBoolean isUrl isEmail isArray objectValidator stringValidator numberValidator booleanValidator urlValidator emailValidator arrayValidator customValidator } = ; // Example with import ;
Example usage
In this advanced example we are creating a composite object validator and checking if an object is valid. In this case we are testing if a if objects are valid Books.
// Lets create a object validator to check if an object is a Bookconst isBook = ; // This is a object which we want to test if it is really a valid bookconst potentialBook = title: 'A song of ice and fire' rating: 495 numberOfPages: 387 // To check if the object we recieved is a valid book we simply doif! console; else console; // This will be logged
For additional examples and docs please refer to this page.