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.2.0 to 2.2.1

test/json-schema.js

80

index.js

@@ -110,9 +110,13 @@ var genobj = require('generate-object-property')

var visit = function(name, node, reporter) {
var properties = node.properties
var type = node.type
var tuple = false
if (Array.isArray(node.items)) { // tuple type
node.properties = {}
properties = {}
node.items.forEach(function(item, i) {
node.properties[i] = item
properties[i] = item
})
node.type = 'array'
node.tuple = true
type = 'array'
tuple = true
}

@@ -155,3 +159,3 @@

var valid = [].concat(node.type)
var valid = [].concat(type)
.map(function(t) {

@@ -169,3 +173,3 @@ return types[t || 'any'](name)

if (node.tuple) {
if (tuple) {
if (node.additionalItems === false) {

@@ -194,7 +198,7 @@ validate('if (%s.length > %d) {', name, node.items.length)

if (node.uniqueItems) {
if (node.type !== 'array') validate('if (%s) {', types.array(name))
if (type !== 'array') validate('if (%s) {', types.array(name))
validate('if (!(unique(%s))) {', name)
error('must be unique')
validate('}')
if (node.type !== 'array') validate('}')
if (type !== 'array') validate('}')
}

@@ -221,3 +225,3 @@

if (node.dependencies) {
if (node.type !== 'object') validate('if (%s) {', types.object(name))
if (type !== 'object') validate('if (%s) {', types.object(name))

@@ -244,7 +248,7 @@ Object.keys(node.dependencies).forEach(function(key) {

if (node.type !== 'object') validate('}')
if (type !== 'object') validate('}')
}
if (node.additionalProperties || node.additionalProperties === false) {
if (node.type !== 'object') validate('if (%s) {', types.object(name))
if (type !== 'object') validate('if (%s) {', types.object(name))

@@ -262,3 +266,3 @@ var i = genloop()

var additionalProp = Object.keys(node.properties || {}).map(toCompare)
var additionalProp = Object.keys(properties || {}).map(toCompare)
.concat(Object.keys(node.patternProperties || {}).map(toTest))

@@ -281,3 +285,3 @@ .join(' && ') || 'true'

if (node.type !== 'object') validate('}')
if (type !== 'object') validate('}')
}

@@ -314,4 +318,4 @@

if (node.items && !node.tuple) {
if (node.type !== 'array') validate('if (%s) {', types.array(name))
if (node.items && !tuple) {
if (type !== 'array') validate('if (%s) {', types.array(name))

@@ -323,7 +327,7 @@ var i = genloop()

if (node.type !== 'array') validate('}')
if (type !== 'array') validate('}')
}
if (node.patternProperties) {
if (node.type !== 'object') validate('if (%s) {', types.object(name))
if (type !== 'object') validate('if (%s) {', types.object(name))
var keys = gensym('keys')

@@ -343,3 +347,3 @@ var i = genloop()

validate('}')
if (node.type !== 'object') validate('}')
if (type !== 'object') validate('}')
}

@@ -349,7 +353,7 @@

var p = patterns(node.pattern)
if (node.type !== 'string') validate('if (%s) {', types.string(name))
if (type !== 'string') validate('if (%s) {', types.string(name))
validate('if (!(%s.test(%s))) {', p, name)
error('pattern mismatch')
validate('}')
if (node.type !== 'string') validate('}')
if (type !== 'string') validate('}')
}

@@ -406,3 +410,3 @@

if (node.multipleOf !== undefined) {
if (node.type !== 'number' && node.type !== 'integer') validate('if (%s) {', types.number(name))
if (type !== 'number' && type !== 'integer') validate('if (%s) {', types.number(name))

@@ -416,7 +420,7 @@ var factor = ((node.multipleOf | 0) !== node.multipleOf) ? Math.pow(10, node.multipleOf.toString().split('.').pop().length) : 1

if (node.type !== 'number' && node.type !== 'integer') validate('}')
if (type !== 'number' && type !== 'integer') validate('}')
}
if (node.maxProperties !== undefined) {
if (node.type !== 'object') validate('if (%s) {', types.object(name))
if (type !== 'object') validate('if (%s) {', types.object(name))

@@ -427,7 +431,7 @@ validate('if (Object.keys(%s).length > %d) {', name, node.maxProperties)

if (node.type !== 'object') validate('}')
if (type !== 'object') validate('}')
}
if (node.minProperties !== undefined) {
if (node.type !== 'object') validate('if (%s) {', types.object(name))
if (type !== 'object') validate('if (%s) {', types.object(name))

@@ -438,7 +442,7 @@ validate('if (Object.keys(%s).length < %d) {', name, node.minProperties)

if (node.type !== 'object') validate('}')
if (type !== 'object') validate('}')
}
if (node.maxItems !== undefined) {
if (node.type !== 'array') validate('if (%s) {', types.array(name))
if (type !== 'array') validate('if (%s) {', types.array(name))

@@ -449,7 +453,7 @@ validate('if (%s.length > %d) {', name, node.maxItems)

if (node.type !== 'array') validate('}')
if (type !== 'array') validate('}')
}
if (node.minItems !== undefined) {
if (node.type !== 'array') validate('if (%s) {', types.array(name))
if (type !== 'array') validate('if (%s) {', types.array(name))

@@ -460,7 +464,7 @@ validate('if (%s.length < %d) {', name, node.minItems)

if (node.type !== 'array') validate('}')
if (type !== 'array') validate('}')
}
if (node.maxLength !== undefined) {
if (node.type !== 'string') validate('if (%s) {', types.string(name))
if (type !== 'string') validate('if (%s) {', types.string(name))

@@ -471,7 +475,7 @@ validate('if (%s.length > %d) {', name, node.maxLength)

if (node.type !== 'string') validate('}')
if (type !== 'string') validate('}')
}
if (node.minLength !== undefined) {
if (node.type !== 'string') validate('if (%s) {', types.string(name))
if (type !== 'string') validate('if (%s) {', types.string(name))

@@ -482,3 +486,3 @@ validate('if (%s.length < %d) {', name, node.minLength)

if (node.type !== 'string') validate('}')
if (type !== 'string') validate('}')
}

@@ -498,6 +502,6 @@

if (node.properties) {
Object.keys(node.properties).forEach(function(p) {
visit(genobj(name, p), node.properties[p], reporter)
var def = node.properties[p].default
if (properties) {
Object.keys(properties).forEach(function(p) {
visit(genobj(name, p), properties[p], reporter)
var def = properties[p].default
if (def !== undefined) validate('if (%s === undefined) %s = %s', genobj(name, p), genobj(name, p), JSON.stringify(def))

@@ -504,0 +508,0 @@ })

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

@@ -16,3 +16,3 @@ "main": "index.js",

"scripts": {
"test": "tape test/validate.js"
"test": "tape test/*.js"
},

@@ -19,0 +19,0 @@ "repository": {

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