validate.js 528 B

123456789101112131415161718192021222324
  1. const { exit } = require('./exit')
  2. // proxy to joi for option validation
  3. exports.createSchema = fn => fn(require('@hapi/joi'))
  4. exports.validate = (obj, schema, cb) => {
  5. require('@hapi/joi').validate(obj, schema, {}, err => {
  6. if (err) {
  7. cb(err.message)
  8. if (process.env.VUE_CLI_TEST) {
  9. throw err
  10. } else {
  11. exit(1)
  12. }
  13. }
  14. })
  15. }
  16. exports.validateSync = (obj, schema) => {
  17. const result = require('@hapi/joi').validate(obj, schema)
  18. if (result.error) {
  19. throw result.error
  20. }
  21. }