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

jsonschema

Package Overview
Dependencies
Maintainers
2
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsonschema - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

47

lib/attribute.js

@@ -56,3 +56,3 @@ 'use strict';

function testSchema(instance, options, ctx, schema){
return this.validateSchema(instance, schema, options, ctx).valid;
return this.validateSchema(instance, schema, options, ctx).valid;
}

@@ -77,4 +77,4 @@

if (!schema.anyOf.some(testSchema.bind(this, instance, options, ctx))) {
return "is not any of " + schema.anyOf.map(function (v) {
return v.id && ('<' + v.id + '>') || (v+'');
return "is not any of " + schema.anyOf.map(function (v, i) {
return (v.id && ('<' + v.id + '>')) || (v.title && JSON.stringify(v.title)) || (v['$ref'] && ('<' + v['$ref'] + '>')) || '[subschema '+i+']';
});

@@ -94,2 +94,3 @@ }

validators.allOf = function validateAllOf (instance, schema, options, ctx) {
var result = new ValidatorResult(instance, schema, options, ctx);
// Ignore undefined instances

@@ -102,8 +103,12 @@ if (instance === undefined) {

}
if (!schema.allOf.every(testSchema.bind(this, instance, options, ctx))) {
return "is not all from " + schema.allOf.map(function (v) {
return v.id && ('<' + v.id + '>') || (v+'');
});
}
return null;
var self = this;
schema.allOf.forEach(function(v, i){
var valid = self.validateSchema(instance, v, options, ctx);
if(!valid.valid){
var msg = (v.id && ('<' + v.id + '>')) || (v.title && JSON.stringify(v.title)) || (v['$ref'] && ('<' + v['$ref'] + '>')) || '[subschema '+i+']';
result.addError('does not match allOf schema ' + msg + ' with ' + valid.errors.length + ' error[s]:');
result.importErrors(valid);
}
});
return result;
};

@@ -129,4 +134,4 @@

if (count!==1) {
return "is not exactly one from " + schema.oneOf.map(function (v) {
return v.id && ('<' + v.id + '>') || (v+'');
return "is not exactly one from " + schema.oneOf.map(function (v, i) {
return (v.id && ('<' + v.id + '>')) || (v.title && JSON.stringify(v.title)) || (v['$ref'] && ('<' + v['$ref'] + '>')) || '[subschema '+i+']';
});

@@ -170,3 +175,3 @@ }

if (schema.additionalProperties === false) {
result.addError("Property " + property + " does not exist in the schema");
result.addError("additionalProperty '"+property+"' exists in instance when not allowed");
} else {

@@ -297,3 +302,3 @@ var additionalProperties = schema.additionalProperties || {};

var res = self.validateSchema(value, items, options, ctx.makeChild(items, i));
result.instance[i] = res.instance;
if(res.instance !== result.instance[i]) result.instance[i] = res.instance;
result.importErrors(res);

@@ -322,3 +327,3 @@ return true;

if (!valid) {
return "is not " + schema.minimum;
return "must have a minimum value of " + schema.minimum;
}

@@ -345,3 +350,3 @@ return null;

if (!valid) {
return "is not " + schema.maximum;
return "must have a maximum value of " + schema.maximum;
}

@@ -429,3 +434,3 @@ return null;

if (!instance.match(schema.pattern)) {
return "does not match pattern" + schema.pattern;
return "does not match pattern " + schema.pattern;
}

@@ -618,3 +623,3 @@ return null;

var res = this.validateSchema(instance, dep, options, childContext);
result.instance[property] = res.instance;
if(result.instance !== res.instance) result.instance = res.instance;
if (res && res.errors.length) {

@@ -636,4 +641,4 @@ result.addError("does not meet dependency required by " + childContext.propertyPath);

*/
validators.enum = function validateEnum (instance, schema) {
if (!(schema.enum instanceof Array)) {
validators['enum'] = function validateEnum (instance, schema) {
if (!(schema['enum'] instanceof Array)) {
throw new SchemaError("enum expects an array", schema);

@@ -644,4 +649,4 @@ }

}
if (!schema.enum.some(helpers.deepCompareStrict.bind(null, instance))) {
return "is not one of enum values: " + schema.enum;
if (!schema['enum'].some(helpers.deepCompareStrict.bind(null, instance))) {
return "is not one of enum values: " + schema['enum'];
}

@@ -648,0 +653,0 @@ return null;

@@ -104,3 +104,3 @@ 'use strict';

var FORMAT_REGEXPS = exports.FORMAT_REGEXPS = {
'date-time': /^\d{4}-(?:0[0-9]{1}|1[0-2]{1})-[0-9]{2}T\d{2}:\d{2}:\d{2}(\.\d{3})?Z$/,
'date-time': /^\d{4}-(?:0[0-9]{1}|1[0-2]{1})-[0-9]{2}[tT ]\d{2}:\d{2}:\d{2}(\.\d+)?([zZ]|[+-]\d{2}:\d{2})$/,
'date': /^\d{4}-(?:0[0-9]{1}|1[0-2]{1})-[0-9]{2}$/,

@@ -114,5 +114,7 @@ 'time': /^\d{2}:\d{2}:\d{2}$/,

'color': /(#?([0-9A-Fa-f]{3,6})\b)|(aqua)|(black)|(blue)|(fuchsia)|(gray)|(green)|(lime)|(maroon)|(navy)|(olive)|(orange)|(purple)|(red)|(silver)|(teal)|(white)|(yellow)|(rgb\(\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*,\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*,\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*\))|(rgb\(\s*(\d?\d%|100%)+\s*,\s*(\d?\d%|100%)+\s*,\s*(\d?\d%|100%)+\s*\))/,
'color': /^(#?([0-9A-Fa-f]{3}){1,2}\b|aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow|(rgb\(\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*,\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*,\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*\))|(rgb\(\s*(\d?\d%|100%)+\s*,\s*(\d?\d%|100%)+\s*,\s*(\d?\d%|100%)+\s*\)))$/,
'host-name': /^(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])$/,
// hostname regex from: http://stackoverflow.com/a/1420225/5628
'hostname': /^(?=.{1,255}$)[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?(?:\.[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?)*\.?$/,
'host-name': /^(?=.{1,255}$)[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?(?:\.[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?)*\.?$/,

@@ -119,0 +121,0 @@ 'alpha': /^[a-zA-Z]+$/,

@@ -94,3 +94,3 @@ 'use strict';

}
}
};

@@ -102,3 +102,3 @@ Validator.prototype.addSubSchemaObject = function addSubSchemaArray(baseuri, schemas) {

}
}
};

@@ -192,9 +192,9 @@

if (schema.extends) {
if (schema.extends instanceof Array) {
schema.extends.forEach(function (s) {
if (schema['extends']) {
if (schema['extends'] instanceof Array) {
schema['extends'].forEach(function (s) {
schema = helpers.deepMerge(schema, resolve(s, ctx));
});
} else {
schema = helpers.deepMerge(schema, resolve(schema.extends, ctx));
schema = helpers.deepMerge(schema, resolve(schema['extends'], ctx));
}

@@ -261,3 +261,4 @@ }

return {subschema: subschema, switchSchema: switchSchema};
}
};
/**

@@ -304,3 +305,3 @@ * Tests whether the instance if of a certain type.

};
types.null = function testNull (instance) {
types['null'] = function testNull (instance) {
return instance === null;

@@ -307,0 +308,0 @@ };

{
"author": "Tom de Grunt <tom@degrunt.nl>",
"name": "jsonschema",
"version": "1.0.0",
"version": "1.0.1",
"dependencies": {
},
"contributors": [
{ "name" : "Austin Wright" }
],
"main": "./lib",

@@ -8,0 +11,0 @@ "devDependencies": {

@@ -50,4 +50,5 @@ [![Build Status](https://secure.travis-ci.org/tdegrunt/jsonschema.png)](http://travis-ci.org/tdegrunt/jsonschema)

"city": {"type": "string"},
"country": {"type": "string", "required": true}
}
"country": {"type": "string"}
},
"required": ["country"]
};

@@ -90,3 +91,3 @@

### String Formats
All formats are supported, phone numbers are expected to follow the [http://en.wikipedia.org/wiki/E.123](E.123) standard.
All formats are supported, phone numbers are expected to follow the [E.123](http://en.wikipedia.org/wiki/E.123) standard.

@@ -103,8 +104,8 @@ ### Results

if(typeof schema.contains!='string') throw new jsonschema.SchemaError('"contains" expects a string', schema);
if(instance.indexOf()<0){
return 'does not contain the string '+JSON.stringify(schema.contains);
if(instance.indexOf(schema.contains)<0){
return 'does not contain the string ' + JSON.stringify(schema.contains);
}
}
var result = validator.validate({x:0, y:10}, {type:"object", radius:{x:10, y:10, radius:5}});
var result = validator.validate("i am an instance", { type:"string", contains: "i am" });
// result.valid === true;
```

@@ -145,3 +146,3 @@

## Tests
Uses [https://github.com/json-schema/JSON-Schema-Test-Suite](JSON Schema Test Suite) as well as our own tests.
Uses [JSON Schema Test Suite](https://github.com/json-schema/JSON-Schema-Test-Suite) as well as our own tests.
You'll need to update and init the git submodules:

@@ -152,2 +153,10 @@

## Contributions
This library would not be possible without the valuable contributions by:
- Austin Wright
... and many others!
## License

@@ -157,3 +166,3 @@

Copyright (C) 2012-2014 Tom de Grunt <tom@degrunt.nl>
Copyright (C) 2012-2015 Tom de Grunt <tom@degrunt.nl>

@@ -160,0 +169,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of

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