jsonvalidator
Advanced tools
Comparing version 0.1.0 to 0.1.1
89
index.js
@@ -1,1 +0,88 @@ | ||
console.log('Comming soon'); | ||
'use strict'; | ||
var Ajv = require('ajv'); | ||
var jsonschema = require('jsonschema'); | ||
var debug = require('./debug')('jsonvalidator'); | ||
var Service = function(params) { | ||
debug && debug(' + constructor begin ...'); | ||
params = params || {}; | ||
var validatorName = params.validatorName; | ||
if (['ajv', 'jsonschema'].indexOf(validatorName) < 0) { | ||
validatorName = 'ajv'; | ||
} | ||
var ajvValidator = new Ajv({ | ||
allErrors: true | ||
}); | ||
false && ajvValidator.addMetaSchema(require('ajv/lib/refs/json-schema-draft-04.json')); | ||
var jsonschemaValidator = new jsonschema.Validator(); | ||
jsonschemaValidator.addSchema(require('jsonschema/schema/draft-04/schema.json')); | ||
this.validate = validateWith[validatorName].bind({ | ||
skipErrors: params.skipErrors, | ||
ajv: ajvValidator, | ||
jsonschema: jsonschemaValidator | ||
}); | ||
debug && debug(' - constructor end!'); | ||
}; | ||
var validateWith = {}; | ||
validateWith.ajv = function(data, schema, opts) { | ||
var self = this; | ||
opts = opts || {}; | ||
debug && debug(' - [ajv] is invoked'); | ||
var output = { failed: false, validatorName: 'ajv' }; | ||
var valid = self.ajv.validate(schema, data); | ||
if (!valid) { | ||
debug && debug(' - [ajv] invalid data. error: %s', JSON.stringify(self.ajv.errors)); | ||
output.failed = true; | ||
if (self.skipErrors !== true && opts.skipErrors !== true) { | ||
output.errors = transformErrorWith.ajv(self.ajv.errors); | ||
} | ||
} else { | ||
debug && debug(' - [ajv] data validated successful'); | ||
} | ||
return output; | ||
} | ||
validateWith.jsonschema = function(data, schema, opts) { | ||
var self = this; | ||
opts = opts || {}; | ||
debug && debug(' - [jsonschema] is invoked'); | ||
var output = { failed: false, validatorName: 'jsonschema' }; | ||
var result = self.jsonschema.validate(data, schema); | ||
debug && debug(' - [jsonschema] validation result: %s', JSON.stringify(result)); | ||
if (result.errors.length > 0) { | ||
debug && debug(' - [jsonschema] invalid data. error: %s', JSON.stringify(result.errors)); | ||
output.failed = true; | ||
if (self.skipErrors !== true && opts.skipErrors !== true) { | ||
output.errors = transformErrorWith.jsonschema(result.errors); | ||
} | ||
} else { | ||
debug && debug(' - [jsonschema] data validated successful'); | ||
} | ||
return output; | ||
} | ||
var transformErrorWith = {}; | ||
transformErrorWith.ajv = function(errors) { | ||
return errors; | ||
} | ||
transformErrorWith.jsonschema = function(errors) { | ||
return errors; | ||
} | ||
module.exports = Service; |
{ | ||
"name": "jsonvalidator", | ||
"version": "0.1.0", | ||
"description": "JSON validators wrapper", | ||
"version": "0.1.1", | ||
"description": "JSON validator wrapper", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "node_modules/.bin/mocha test/tdd/*-test.js" | ||
}, | ||
"author": "devebot", | ||
"license": "MIT" | ||
"license": "MIT", | ||
"dependencies": { | ||
"ajv": "^4.11.3", | ||
"debug": "^2.6.1", | ||
"jsonschema": "^1.1.1" | ||
}, | ||
"devDependencies": { | ||
"chai": "^3.5.0", | ||
"mocha": "^3.2.0" | ||
} | ||
} |
# jsonvalidator | ||
> JSON validators wrapper | ||
> JSON validator wrapper |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Empty package
Supply chain riskPackage does not contain any code. It may be removed, is name squatting, or the result of a faulty package publish.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
3315
5
81
2
0
3
2
4
+ Addedajv@^4.11.3
+ Addeddebug@^2.6.1
+ Addedjsonschema@^1.1.1
+ Addedajv@4.11.8(transitive)
+ Addedcall-bind@1.0.8(transitive)
+ Addedcall-bind-apply-helpers@1.0.1(transitive)
+ Addedcall-bound@1.0.3(transitive)
+ Addedco@4.6.0(transitive)
+ Addeddebug@2.6.9(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addeddunder-proto@1.0.1(transitive)
+ Addedes-define-property@1.0.1(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedes-object-atoms@1.0.0(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-intrinsic@1.2.6(transitive)
+ Addedgopd@1.2.0(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedhas-symbols@1.1.0(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedisarray@2.0.5(transitive)
+ Addedjson-stable-stringify@1.2.1(transitive)
+ Addedjsonify@0.0.1(transitive)
+ Addedjsonschema@1.4.1(transitive)
+ Addedmath-intrinsics@1.1.0(transitive)
+ Addedms@2.0.0(transitive)
+ Addedobject-keys@1.1.1(transitive)
+ Addedset-function-length@1.2.2(transitive)