Socket
Socket
Sign inDemoInstall

ajv

Package Overview
Dependencies
Maintainers
1
Versions
355
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ajv - npm Package Compare versions

Comparing version 0.1.11 to 0.1.12

lib/compile/rules/PERFORMANCE.md

8

lib/compile/rules/allOf.dot.js
var valid = true;
{{ var $closingBraces = ''; }}
{{ var $it = it.copy(it); }}
{{
var $it = it.copy(it)
, $closingBraces = ''
, $level = it.level;
$it.level++;
}}

@@ -6,0 +10,0 @@ {{~ it.schema.allOf:$schema:$i }}

@@ -1,5 +0,11 @@

var anyOf_errs = validate.errors.length;
{{
var $it = it.copy(it)
, $closingBraces = ''
, $level = it.level;
$it.level++;
}}
var errs{{= $level}} = validate.errors.length;
var valid = false;
{{ var $closingBraces = ''; }}
{{~ it.schema.anyOf:$schema:$i }}

@@ -12,3 +18,2 @@ {{? $i }}

{{
var $it = it.copy(it);
$it.schema = $schema;

@@ -19,3 +24,2 @@ $it.schemaPath = it.schemaPath + '.anyOf[' + $i + ']';

valid = valid || ({{= it.validate($it) }})(data, dataPath);
{{~}}

@@ -25,2 +29,2 @@

if (valid) validate.errors.length = anyOf_errs;
if (valid) validate.errors.length = errs{{= $level}};

@@ -1,9 +0,9 @@

var errs = validate.errors.length;
var valid;
{{
var $breakOnError = !it.opts.allErrors
var $it = it.copy(it)
, $breakOnError = !it.opts.allErrors
, $closingBraces = ''
, $schemaDeps = {}
, $propertyDeps = {};
, $propertyDeps = {}
, $level = it.level;
$it.level++;

@@ -17,2 +17,6 @@ for ($property in it.schema.dependencies) {

var errs{{= $level}} = validate.errors.length;
var valid;
{{ for ($property in $propertyDeps) { }}

@@ -37,3 +41,2 @@ if (data.hasOwnProperty('{{= $property }}')) {

{{ var $it = it.copy(it); }}

@@ -60,2 +63,4 @@ {{ for ($property in $schemaDeps) { }}

valid = errs == validate.errors.length;
valid = errs{{= $level}} == validate.errors.length;
{{ out = out.replace(/if \(valid\) \{\s*\}/g, ''); }}
{{ var $itemsHash = it.toHash(it.schema.enum, it.stableStringify); }}
var req_itemsHash = {{= JSON.stringify($itemsHash) }};
var valid = req_itemsHash[stableStringify(data)] || false;
var itemsHash{{= it.level }} = {{= JSON.stringify($itemsHash) }};
var valid = itemsHash{{= it.level }}[stableStringify(data)] || false;

@@ -6,0 +6,0 @@ if (!valid) validate.errors.push({

{{? it.opts.format !== false }}
var format = formats['{{= it.schema.format }}'];
var valid = typeof format == 'function'
? format(data)
: !format || format.test(data);
{{ var $format = 'format' + it.level; }}
var {{=$format}} = formats['{{= it.schema.format }}'];
var valid = typeof {{=$format}} == 'function'
? {{=$format}}(data)
: !{{=$format}} || {{=$format}}.test(data);

@@ -7,0 +8,0 @@ if (!valid) validate.errors.push({

{{## def.ifValid:
{{? $breakOnError }}
if (valid) {
{{ $closingBraces += '}'; }}
if (valid) {
{{?}}

@@ -10,7 +10,7 @@ #}}

for (var i = {{= startFrom }}; i < data.length; i++) {
var _data = data[i]
, _dataPath = dataPath + '[' + i + ']';
var data{{=$level}} = data[i]
, dataPath{{=$level}} = dataPath + '[' + i + ']';
{{? $breakOnError }} valid = {{?}}
validateItems(_data, _dataPath);
validateItems(data{{=$level}}, dataPath{{=$level}});

@@ -23,8 +23,10 @@ {{? $breakOnError }} if (!valid) break; {{?}}

var $it = it.copy(it)
, $level = it.level
, $breakOnError = !it.opts.allErrors
, $closingBraces = ''
, $itemsSchema = it.schema.items;
$it.level++;
}}
var items_errs = validate.errors.length;
var errs{{=$level}} = validate.errors.length;
var valid;

@@ -59,7 +61,7 @@

var _data = data[{{= $index }}]
, _dataPath = dataPath + '[{{= $index }}]';
var data{{=$level}} = data[{{= $index }}]
, dataPath{{=$level}} = dataPath + '[{{= $index }}]';
{{? $breakOnError }} valid = {{?}}
({{= it.validate($it) }})(_data, _dataPath);
({{= it.validate($it) }})(data{{=$level}}, dataPath{{=$level}});
}

@@ -98,2 +100,4 @@

valid = items_errs == validate.errors.length;
valid = errs{{=$level}} == validate.errors.length;
{{ out = out.replace(/if \(valid\) \{\s*\}/g, ''); }}

@@ -1,5 +0,5 @@

var not_errs = validate.errors.length;
{{
var $it = it.copy(it);
var $it = it.copy(it)
, $level = it.level;
$it.level++;
$it.schema = it.schema.not;

@@ -9,6 +9,8 @@ $it.schemaPath = it.schemaPath + '.not';

var errs{{= $level }} = validate.errors.length;
var valid = ({{= it.validate($it) }})(data, dataPath);
valid = !valid;
if (valid) validate.errors.length = not_errs;
if (valid) validate.errors.length = errs{{= $level }};
else validate.errors.push({

@@ -15,0 +17,0 @@ keyword: 'not',

@@ -1,7 +0,10 @@

var foundValid = false
, oneOf_errs = validate.errors.length;
{{
var $it = it.copy(it)
, $level = it.level
, $closingBraces = '';
$it.level++;
}}
var validCount = 0;
{{ var $closingBraces = ''; }}
{{ var $it = it.copy(it); }}
var errs{{= $level }} = validate.errors.length;
var validCount{{= $level }} = 0;

@@ -11,3 +14,3 @@ {{~ it.schema.oneOf:$schema:$i }}

{{ $closingBraces += '}'; }}
if (validCount < 2) {
if (validCount{{= $level }} < 2) {
{{?}}

@@ -21,3 +24,3 @@

var valid = ({{= it.validate($it) }})(data, dataPath);
if (valid) validCount++;
if (valid) validCount{{= $level }}++;
{{~}}

@@ -27,3 +30,3 @@

if (validCount == 1) validate.errors.length = oneOf_errs;
if (validCount{{= $level }} == 1) validate.errors.length = errs{{= $level }};
else validate.errors.push({

@@ -36,2 +39,2 @@ keyword: 'oneOf',

var valid = validCount == 1;
var valid = validCount{{= $level }} == 1;

@@ -0,14 +1,19 @@

{{## def.ifValid:
{{? $breakOnError }}
if (valid) {
{{ $closingBraces += '}'; }}
{{?}}
#}}
{{## def.validateProperty:useKey:
var _data = data[{{= useKey }}]
, _dataPath = dataPath + '.' + {{= useKey }};
var data{{=$lvl}} = data[{{= useKey }}]
, dataPath{{=$lvl}} = dataPath + '.' + {{= useKey }};
{{? $breakOnError }} var valid = {{?}}
({{= it.validate($it) }})(_data, _dataPath);
({{= it.validate($it) }})(data{{=$lvl}}, dataPath{{=$lvl}});
#}}
var properties_errs = validate.errors.length;
var valid = true;
{{
var $it = it.copy(it)
, $lvl = it.level
, $breakOnError = !it.opts.allErrors

@@ -23,14 +28,19 @@ , $closingBraces = ''

, $checkAdditional = $noAdditional || $additionalIsSchema;
$it.level++;
}}
var errs{{=$lvl}} = validate.errors.length;
var valid = true;
{{? $checkAdditional }}
var propertiesSchema = validate.schema{{= it.schemaPath + '.properties' }} || {};
var propertiesSchema{{=$lvl}} = validate.schema{{= it.schemaPath + '.properties' }} || {};
{{?}}
{{? $noAdditional }}
var propertiesSchemaKeys = Object.keys(propertiesSchema);
var propertiesSchemaKeys{{=$lvl}} = Object.keys(propertiesSchema{{=$lvl}});
var dataKeys = Object.keys(data);
var dataKeys{{=$lvl}} = Object.keys(data);
var valid = dataKeys.length <= propertiesSchemaKeys.length;
var valid = dataKeys{{=$lvl}}.length <= propertiesSchemaKeys{{=$lvl}}.length;
if (!valid) {

@@ -41,3 +51,3 @@ validate.errors.push({

message: 'additional properties NOT allowed'
{{? it.opts.verbose }}, schema: propertiesSchema, data: data{{?}}
{{? it.opts.verbose }}, schema: propertiesSchema{{=$lvl}}, data: data{{?}}
});

@@ -53,7 +63,7 @@

{{? $pPropertyKeys.length }}
var pPropertiesSchema = validate.schema{{= it.schemaPath + '.patternProperties' }}
, pPropertiesRegexps = {};
var pPropertiesSchema{{=$lvl}} = validate.schema{{= it.schemaPath + '.patternProperties' }}
, pPropertiesRegexps{{=$lvl}} = {};
for (var pProperty in pPropertiesSchema)
pPropertiesRegexps[pProperty] = new RegExp(pProperty);
for (var pProperty{{=$lvl}} in pPropertiesSchema{{=$lvl}})
pPropertiesRegexps{{=$lvl}}[pProperty{{=$lvl}}] = new RegExp(pProperty{{=$lvl}});
{{?}}

@@ -64,8 +74,8 @@

for (var key in data) {
var isAdditional = !propertiesSchema.hasOwnProperty(key);
var isAdditional = !propertiesSchema{{=$lvl}}.hasOwnProperty(key);
{{? $pPropertyKeys.length }}
if (isAdditional) {
for (var pProperty in pPropertiesSchema) {
var keyMatches = pPropertiesRegexps[pProperty].test(key);
for (var pProperty{{=$lvl}} in pPropertiesSchema{{=$lvl}}) {
var keyMatches = pPropertiesRegexps{{=$lvl}}[pProperty{{=$lvl}}].test(key);
if (keyMatches) {

@@ -87,3 +97,3 @@ isAdditional = false;

message: 'property ' + key + ' NOT allowed'
{{? it.opts.verbose }}, schema: propertiesSchema, data: data{{?}}
{{? it.opts.verbose }}, schema: propertiesSchema{{=$lvl}}, data: data{{?}}
});

@@ -105,6 +115,3 @@

{{? $breakOnError }}
{{ $closingBraces += '}'; }}
if (valid) {
{{?}}
{{# def.ifValid }}
{{?}}

@@ -125,11 +132,8 @@

{{ /* TODO cache data types and paths by keys for patternProperties */ }}
{{ var useKey = '"' + $propertyKey + '"'; }}
{{# def.validateProperty:useKey }}
{{ var $useKey = '"' + $propertyKey + '"'; }}
{{# def.validateProperty:$useKey }}
}
{{?}}
{{? $breakOnError }}
{{ $closingBraces += '}'; }}
if (valid) {
{{?}}
{{# def.ifValid }}
{{ } }}

@@ -147,7 +151,8 @@ {{?}}

for (var key in data) {
var keyMatches = pPropertiesRegexps['{{= $propertyKey }}'].test(key);
for (var key{{=$lvl}} in data) {
var keyMatches = pPropertiesRegexps{{=$lvl}}['{{= $propertyKey }}'].test(key{{=$lvl}});
if (keyMatches) {
{{# def.validateProperty:'key' }}
{{ var $useKey = 'key' + $lvl; }}
{{# def.validateProperty:$useKey }}
{{? $breakOnError }} if (!valid) break; {{?}}

@@ -157,6 +162,3 @@ }

{{? $breakOnError }}
{{ $closingBraces += '}'; }}
if (valid) {
{{?}}
{{# def.ifValid }}
{{?}}

@@ -167,2 +169,5 @@ {{~}}

var valid = properties_errs == validate.errors.length;
var valid = errs{{=$lvl}} == validate.errors.length;
{{ out = out.replace(/if \(valid\) \{\s*\}/g, ''); }}

@@ -8,8 +8,9 @@ {{ var $schema = it.schema.required; }}

{{??}}
{{ var $lvl = it.level; }}
var valid = true;
var req_schema = validate.schema{{= it.schemaPath + '.required' }};
var schema{{=$lvl}} = validate.schema{{= it.schemaPath + '.required' }};
for (var i = 0; i < req_schema.length; i++) {
var property = req_schema[i]
, valid = valid && data.hasOwnProperty(req_schema[i]);
for (var i = 0; i < schema{{=$lvl}}.length; i++) {
var property = schema{{=$lvl}}[i]
, valid = valid && data.hasOwnProperty(schema{{=$lvl}}[i]);

@@ -16,0 +17,0 @@ {{? !it.opts.allErrors }} if (!valid) break; {{?}}

var valid = true;
{{ var $lvl = it.level; }}
{{? it.schema.uniqueItems && it.opts.uniqueItems !== false }}
if (data.length > 1) {
var i = data.length, j;
var i{{=$lvl}} = data.length, j{{=$lvl}};
outer:
for (;i--;) {
for (j = i; j--;) {
if (equal(data[i], data[j])) {
for (;i{{=$lvl}}--;) {
for (j{{=$lvl}} = i{{=$lvl}}; j{{=$lvl}}--;) {
if (equal(data[i{{=$lvl}}], data[j{{=$lvl}}])) {
valid = false;

@@ -20,3 +22,3 @@ break outer;

dataPath: dataPath,
message: 'items ## ' + i + ' and ' + j + ' are duplicate'
message: 'items ## ' + i{{=$lvl}} + ' and ' + j{{=$lvl}} + ' are duplicate'
{{? it.opts.verbose }}, schema: {{= it.schema.uniqueItems }}, data: data{{?}}

@@ -23,0 +25,0 @@ });

@@ -15,10 +15,23 @@ {{ /**

{{
var $breakOnErrors = !it.opts.allErrors
, $closingBraces1 = ''
, $closingBraces2 = '';
}}
{{? it.isRoot }}
{{ it.isRoot = false; }}
{{
it.isRoot = false;
var $level = 0;
it.level = 1;
}}
var dataPath = '';
var errs = validate.errors.length = 0;
var errs{{= $level }} = validate.errors.length = 0;
{{??}}
var errs = validate.errors.length;
{{ var $level = it.level++; }}
var errs{{= $level }} = validate.errors.length;
{{?}}
var valid = true;
{{~ it.RULES:$rulesGroup }}

@@ -30,10 +43,24 @@ {{? $shouldUseGroup($rulesGroup) }}

{{= $rule.code(it) }}
{{? !it.opts.allErrors }} if (!valid) return false; {{?}}
{{? $breakOnErrors }}
if (valid) {
{{ $closingBraces1 += '}'; }}
{{?}}
{{?}}
{{~}}
{{? $breakOnErrors }}
{{= $closingBraces1 }}
{{ $closingBraces1 = ''; }}
{{?}}
{{? $rulesGroup.type }} } {{?}}
{{? $breakOnErrors }}
if (valid) {
{{ $closingBraces2 += '}'; }}
{{?}}
{{?}}
{{~}}
return {{? it.opts.allErrors }} errs == validate.errors.length {{??}} true {{?}};
{{? $breakOnErrors }} {{= $closingBraces2 }} {{?}}
return errs{{= $level }} == validate.errors.length;
}

@@ -59,1 +86,4 @@

}}
{{ out = out.replace(/if \(valid\) \{\s*\}/g, ''); }}
{
"name": "ajv",
"version": "0.1.11",
"version": "0.1.12",
"description": "Another JSON schema Validator",

@@ -5,0 +5,0 @@ "main": "lib/ajv.js",

@@ -10,6 +10,6 @@ 'use strict';

// 'type',
// 'not',
'not',
// 'allOf',
// 'anyOf',
'oneOf',
// 'oneOf',
// 'enum',

@@ -62,3 +62,3 @@ // 'maximum', 'minimum', 'multipleOf',

testSets.forEach(function (testSet) {
// if (testSet.description != 'multiple types can be specified in an array') return;
// if (testSet.description != 'not more complex schema') return;
describe(testSet.description, function() {

@@ -70,3 +70,4 @@ // it(testSet.description, function() {

testSet.tests.forEach(function (test) {
// if (test.description != 'mismatch base schema') return;
// if (test.description != 'match') return;
// console.log(testSet.schema, '\n\n***\n\n', validate.toString());
it(test.description, function() {

@@ -73,0 +74,0 @@ var valid = validate(test.data);

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