Files: 02a191f8e7ff6bee2149956d58dce0c939e7b1c8 / lib / build-validator.js
498 bytesRaw
1 | const Validator = require('is-my-json-valid') |
2 | const getContent = require('ssb-msg-content') |
3 | |
4 | module.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