Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jsonvalidator

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsonvalidator - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

.npmignore

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;

17

package.json
{
"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
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc