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.4.1 to 2.5.0

33

index.js

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

var visit = function(name, node, reporter) {
var visit = function(name, node, reporter, filter) {
var properties = node.properties

@@ -171,3 +171,3 @@ var type = node.type

validate('for (var %s = %d; %s < %s.length; %s++) {', i, node.items.length, i, name, i)
visit(name+'['+i+']', node.additionalItems, reporter)
visit(name+'['+i+']', node.additionalItems, reporter, filter)
validate('}')

@@ -242,3 +242,3 @@ }

validate('if (%s !== undefined) {', genobj(name, key))
visit(name, deps, reporter)
visit(name, deps, reporter, filter)
validate('}')

@@ -274,5 +274,6 @@ }

if (node.additionalProperties === false) {
if (filter) validate('delete %s', name+'['+keys+'['+i+']]')
error('has additional properties')
} else {
visit(name+'['+keys+'['+i+']]', node.additionalProperties, reporter)
visit(name+'['+keys+'['+i+']]', node.additionalProperties, reporter, filter)
}

@@ -308,3 +309,3 @@

validate('var %s = errors', prev)
visit(name, node.not, false)
visit(name, node.not, false, filter)
validate('if (%s === errors) {', prev)

@@ -322,3 +323,3 @@ error('negative schema matches')

validate('for (var %s = 0; %s < %s.length; %s++) {', i, i, name, i)
visit(name+'['+i+']', node.items, reporter)
visit(name+'['+i+']', node.items, reporter, filter)
validate('}')

@@ -340,3 +341,3 @@

validate('if (%s.test(%s)) {', p, keys+'['+i+']')
visit(name+'['+keys+'['+i+']]', node.patternProperties[key], reporter)
visit(name+'['+keys+'['+i+']]', node.patternProperties[key], reporter, filter)
validate('}')

@@ -360,3 +361,3 @@ })

node.allOf.forEach(function(sch) {
visit(name, sch, reporter)
visit(name, sch, reporter, filter)
})

@@ -375,3 +376,3 @@ }

}
visit(name, sch, false)
visit(name, sch, false, false)
})

@@ -395,3 +396,3 @@ node.anyOf.forEach(function(sch, i) {

node.oneOf.forEach(function(sch, i) {
visit(name, sch, false)
visit(name, sch, false, false)
validate('if (%s === errors) {', prev)

@@ -508,3 +509,3 @@ ('%s++', passes)

visit('data', schema, reporter)
visit('data', schema, reporter, opts && opts.filter)

@@ -537,2 +538,10 @@ validate

return compile(schema, {}, schema, true, opts)
}
}
module.exports.filter = function(schema, opts) {
var validate = module.exports(schema, xtend(opts, {filter: true}))
return function(sch) {
validate(sch)
return sch
}
}
{
"name": "is-my-json-valid",
"version": "2.4.1",
"version": "2.5.0",
"description": "A JSONSchema validator that uses code generation to be extremely fast",

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

@@ -94,2 +94,20 @@ # is-my-json-valid

## Filtering away additional properties
is-my-json-valid supports filtering away properties not in the schema
``` js
var filter = validator.filter({
required: true,
type: 'object',
properties: {
hello: {type: 'string', required: true}
},
additionalProperties: false
})
var doc = {hello: 'world', notInSchema: true}
console.log(doc) // {hello: 'world'}
```
## Performance

@@ -96,0 +114,0 @@

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