"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/har-validator/lib/index.js" (7 Feb 2017, 776 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 'use strict'
    2 
    3 var schemas = require('./schemas')
    4 var ValidationError = require('./error')
    5 var validator = require('is-my-json-valid')
    6 
    7 var runner = function (schema, data, cb) {
    8   var validate = validator(schema, {
    9     greedy: true,
   10     verbose: true,
   11     schemas: schemas
   12   })
   13 
   14   var valid = false
   15 
   16   if (data !== undefined) {
   17     // execute is-my-json-valid
   18     valid = validate(data)
   19   }
   20 
   21   // callback?
   22   if (!cb) {
   23     return valid
   24   } else {
   25     return cb(validate.errors ? new ValidationError(validate.errors) : null, valid)
   26   }
   27 
   28   return valid
   29 }
   30 
   31 module.exports = function (data, cb) {
   32   return runner(schemas.har, data, cb)
   33 }
   34 
   35 Object.keys(schemas).map(function (name) {
   36   module.exports[name] = function (data, cb) {
   37     return runner(schemas[name], data, cb)
   38   }
   39 })