git ssb

0+

mixmix / ssb-gathering-schema



Tree: ae90623c733a90b422e30a1d0c3068048e89f291

Files: ae90623c733a90b422e30a1d0c3068048e89f291 / lib / build-validator.js

498 bytesRaw
1const Validator = require('is-my-json-valid')
2const getContent = require('ssb-msg-content')
3
4module.exports = function buildValidator (schema) {
5 const validator = Validator(schema, { verbose: true })
6
7 return function validatorWithErrors (obj, opts = {}) {
8 const result = validator(getContent(obj))
9
10 // exposes error messages provided by is-my-json-valid
11 validatorWithErrors.errors = validator.errors
12 if (opts.attachErrors) obj.errors = validator.errors
13
14 return result
15 }
16}
17

Built with git-ssb-web