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

is-my-json-valid

Package Overview
Dependencies
Maintainers
2
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

is-my-json-valid - npm Package Compare versions

Comparing version 2.9.4 to 2.10.0

8

index.js

@@ -91,2 +91,4 @@ var genobj = require('generate-object-property')

var verbose = opts ? !!opts.verbose : false;
var greedy = opts && opts.greedy !== undefined ?
opts.greedy : false;

@@ -207,4 +209,6 @@ var syms = {}

validate('}');
validate('if (missing === 0) {')
indent++
if (!greedy) {
validate('if (missing === 0) {')
indent++
}
}

@@ -211,0 +215,0 @@

{
"name": "is-my-json-valid",
"version": "2.9.4",
"version": "2.10.0",
"description": "A JSONSchema validator that uses code generation to be extremely fast",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -10,3 +10,3 @@ # is-my-json-valid

It supports passes the entire JSONSchema v4 test suite except for `remoteRefs` and `maxLength`/`minLength` when using unicode surrogate pairs.
It passes the entire JSONSchema v4 test suite except for `remoteRefs` and `maxLength`/`minLength` when using unicode surrogate pairs.

@@ -135,2 +135,25 @@ [![build status](http://img.shields.io/travis/mafintosh/is-my-json-valid.svg?style=flat)](http://travis-ci.org/mafintosh/is-my-json-valid)

## Greedy mode tries to validate as much as possible
By default is-my-json-valid bails on first validation error but when greedy is
set to true it tries to validate as much as possible:
``` js
var validate = validator({
type: 'object',
properties: {
x: {
type: 'number'
}
},
required: ['x', 'y']
}, {
greedy: true
});
validate({x: 'string'});
console.log(validate.errors) // [{field: 'data.y', message: 'is required'},
// {field: 'data.x', message: 'is the wrong type'}]
```
## Performance

@@ -137,0 +160,0 @@

@@ -31,2 +31,61 @@ var tape = require('tape')

tape('greedy/false', function(t) {
var validate = validator({
type: 'object',
properties: {
x: {
type: 'number'
}
},
required: ['x', 'y']
});
t.notOk(validate({}), 'should be invalid')
t.strictEqual(validate.errors.length, 2);
t.strictEqual(validate.errors[0].field, 'data.x')
t.strictEqual(validate.errors[0].message, 'is required')
t.strictEqual(validate.errors[1].field, 'data.y')
t.strictEqual(validate.errors[1].message, 'is required')
t.notOk(validate({x: 'string'}), 'should be invalid')
t.strictEqual(validate.errors.length, 1);
t.strictEqual(validate.errors[0].field, 'data.y')
t.strictEqual(validate.errors[0].message, 'is required')
t.notOk(validate({x: 'string', y: 'value'}), 'should be invalid')
t.strictEqual(validate.errors.length, 1);
t.strictEqual(validate.errors[0].field, 'data.x')
t.strictEqual(validate.errors[0].message, 'is the wrong type')
t.end();
});
tape('greedy/true', function(t) {
var validate = validator({
type: 'object',
properties: {
x: {
type: 'number'
}
},
required: ['x', 'y']
}, {
greedy: true
});
t.notOk(validate({}), 'should be invalid')
t.strictEqual(validate.errors.length, 2);
t.strictEqual(validate.errors[0].field, 'data.x')
t.strictEqual(validate.errors[0].message, 'is required')
t.strictEqual(validate.errors[1].field, 'data.y')
t.strictEqual(validate.errors[1].message, 'is required')
t.notOk(validate({x: 'string'}), 'should be invalid')
t.strictEqual(validate.errors.length, 2);
t.strictEqual(validate.errors[0].field, 'data.y')
t.strictEqual(validate.errors[0].message, 'is required')
t.strictEqual(validate.errors[1].field, 'data.x')
t.strictEqual(validate.errors[1].message, 'is the wrong type')
t.notOk(validate({x: 'string', y: 'value'}), 'should be invalid')
t.strictEqual(validate.errors.length, 1);
t.strictEqual(validate.errors[0].field, 'data.x')
t.strictEqual(validate.errors[0].message, 'is the wrong type')
t.ok(validate({x: 1, y: 'value'}), 'should be invalid')
t.end();
});
tape('additional props', function(t) {

@@ -308,2 +367,2 @@ var validate = validator({

t.end()
})
})
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