is-my-json-valid
Advanced tools
Comparing version 2.13.1 to 2.14.0
10
index.js
@@ -517,11 +517,19 @@ var genobj = require('generate-object-property') | ||
if (node.minimum !== undefined) { | ||
if (type !== 'number' && type !== 'integer') validate('if (%s) {', types.number(name)) | ||
validate('if (%s %s %d) {', name, node.exclusiveMinimum ? '<=' : '<', node.minimum) | ||
error('is less than minimum') | ||
validate('}') | ||
if (type !== 'number' && type !== 'integer') validate('}') | ||
} | ||
if (node.maximum !== undefined) { | ||
if (type !== 'number' && type !== 'integer') validate('if (%s) {', types.number(name)) | ||
validate('if (%s %s %d) {', name, node.exclusiveMaximum ? '>=' : '>', node.maximum) | ||
error('is more than maximum') | ||
validate('}') | ||
if (type !== 'number' && type !== 'integer') validate('}') | ||
} | ||
@@ -544,2 +552,4 @@ | ||
('function validate(data) {') | ||
// Since undefined is not a valid JSON value, we coerce to null and other checks will catch this | ||
('if (data === undefined) data = null') | ||
('validate.errors = null') | ||
@@ -546,0 +556,0 @@ ('var errors = 0') |
{ | ||
"name": "is-my-json-valid", | ||
"version": "2.13.1", | ||
"version": "2.14.0", | ||
"description": "A JSONSchema validator that uses code generation to be extremely fast", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -23,2 +23,10 @@ var tape = require('tape') | ||
tape('data is undefined', function (t) { | ||
var validate = validator({type: 'string'}) | ||
t.notOk(validate(null)) | ||
t.notOk(validate(undefined)) | ||
t.end() | ||
}) | ||
tape('advanced', function(t) { | ||
@@ -198,2 +206,18 @@ var validate = validator(cosmic.schema) | ||
tape('minimum/maximum number type', function(t) { | ||
var validate = validator({ | ||
type: ['integer', 'null'], | ||
minimum: 1, | ||
maximum: 100 | ||
}) | ||
t.notOk(validate(-1)) | ||
t.notOk(validate(0)) | ||
t.ok(validate(null)) | ||
t.ok(validate(1)) | ||
t.ok(validate(100)) | ||
t.notOk(validate(101)) | ||
t.end() | ||
}) | ||
tape('custom format', function(t) { | ||
@@ -200,0 +224,0 @@ var validate = validator({ |
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
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
105765
3379