example.js 430 B

123456789101112131415161718
  1. var validator = require('./')
  2. var validate = validator({
  3. type: 'object',
  4. properties: {
  5. hello: {
  6. required: true,
  7. type: 'string'
  8. }
  9. }
  10. })
  11. console.log('should be valid', validate({hello: 'world'}))
  12. console.log('should not be valid', validate({}))
  13. // get the last error message by checking validate.error
  14. // the following will print "data.hello is required"
  15. console.log('the errors were:', validate.errors)