f0ed484e155561ba7a363aec0e9b847577d93b9a
[yaffs-website] / node_modules / uncss / node_modules / har-validator / lib / runner.js
1 'use strict'
2
3 var schemas = require('./schemas')
4 var ValidationError = require('./error')
5 var validator = require('is-my-json-valid')
6
7 module.exports = function (schema, data, cb) {
8   // default value
9   var valid = false
10
11   // validator config
12   var validate = validator(schema, {
13     greedy: true,
14     verbose: true,
15     schemas: schemas
16   })
17
18   // execute is-my-json-valid
19   if (data !== undefined) {
20     valid = validate(data)
21   }
22
23   // callback?
24   if (typeof cb === 'function') {
25     return cb(validate.errors ? new ValidationError(validate.errors) : null, valid)
26   }
27
28   return valid
29 }