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

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.4.15 to 0.5.0

21

lib/ajv.js

@@ -36,2 +36,3 @@ 'use strict';

this.addFormat = addFormat;
this.errorsText = errorsText;

@@ -128,5 +129,5 @@ addInitialSchemas();

// var ok = skipValidation || self.opts.validateSchema === false
// || validateSchema(schema);
// if (!ok) throw new Error('schema is invalid');
var ok = skipValidation || self.opts.validateSchema === false
|| validateSchema(schema);
if (!ok) console.error('schema is invalid:\n', errorsText());

@@ -141,2 +142,16 @@ resolve.ids.call(self, schema);

function errorsText(errors, opts) {
errors = errors || self.errors;
if (!errors) return 'No errors';
opts = opts || {};
var separator = opts.separator || ', ';
var dataVar = opts.dataVar || 'data';
var text = errors.reduce(function(txt, e) {
return e ? txt + e.keyword + ' ' + dataVar + e.dataPath + ': ' + e.message + separator : txt;
}, '');
return text.slice(0, -separator.length);
}
function addFormat(name, format) {

@@ -143,0 +158,0 @@ if (typeof format == 'string') format = new RegExp(format);

2

package.json
{
"name": "ajv",
"version": "0.4.15",
"version": "0.5.0",
"description": "Another JSON schema Validator",

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

@@ -61,3 +61,3 @@ # ajv - Another JSON Schema Validator

var valid = ajv.validate('mySchema', data);
if (!valid) console.log(ajv.errors);
if (!valid) console.log(ajv.errorsText());
// ...

@@ -84,3 +84,5 @@ ```

Unless options `validateSchema` is false, the schema will be validated against meta-schema and if schema is invalid the errors will be logged. See [options](#options).
##### .validate(Object schema|String key|String ref, data) -> Boolean

@@ -125,2 +127,10 @@

##### .errorsText([Array<Object> errors [, Object options]]) -&gt; String
Returns the text with all errors in a String. Options can have these properties:
- separator: string used to separate errors, ", " is used by default.
- dataVar: the variable name that dataPaths are prefixed with, "data" by default.
## Options

@@ -133,2 +143,3 @@

- _meta_: add [meta-schema](http://json-schema.org/documentation.html) so it can be used by other schemas (true by default).
- _validateSchema: validate schema against meta-schema (true by default). `$schema` property in the schema can either be absent (draft-4 meta-schema will be used) or can be a reference to any previously added schema. If the validation fails, the errors will be logged.
- _uniqueItems_: validate `uniqueItems` keyword (true by default).

@@ -148,2 +159,7 @@ - _unicode_: calculate correct length of strings with unicode pairs (true by default). Pass `false` to use `.length` of strings that is faster, but gives "incorrect" lengths of strings with unicode pairs - each unicode pair is counted as two characters.

##### 0.5.0
Schemas are validated against meta-schema before compilation
##### 0.4.1

@@ -150,0 +166,0 @@

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

it.skip('should throw if schema is invalid', function() {
should.throw(function() {
ajv.compile({ type: null });
});
it('should validate schema when it is compiled', function() {
ajv.errors = null;
ajv.compile({ type: null });
ajv.errors.length .should.be.greaterThan(0);
});

@@ -48,0 +48,0 @@ });

@@ -58,2 +58,9 @@ 'use strict';

shouldBeError(fullValidate.errors[1], 'additionalProperties', "['quux']");
fullValidate.errors
.filter(function(err) { return err.keyword == 'additionalProperties'; })
.map(function(err) { return err.dataPath.slice(2,-2); })
.forEach(function(p) { delete invalidData[p]; });
invalidData .should.eql({ foo: 1, bar: 2 });
});

@@ -60,0 +67,0 @@

@@ -34,4 +34,4 @@ 'use strict';

var Ajv = require('../lib/ajv')
, ajv = Ajv({ beautify: true, _debug: DEBUG })
, fullAjv = Ajv({ allErrors: true, verbose: true, format: 'full', beautify: true, _debug: DEBUG });
, ajv = Ajv({ beautify: DEBUG, _debug: DEBUG })
, fullAjv = Ajv({ allErrors: true, verbose: true, format: 'full', beautify: DEBUG, _debug: DEBUG });

@@ -51,3 +51,3 @@ var remoteRefs = {

describe('Schema validation tests', function() {
addTests('JSON-Schema tests draft4', './json-schema-test-suite/tests/draft4/{**/,}*.json');
addTests('JSON-Schema tests draft4', './JSON-Schema-Test-Suite/tests/draft4/{**/,}*.json');
addTests('Advanced schema tests', './tests/{**/,}*.json');

@@ -69,3 +69,3 @@ });

testSets.forEach(function (testSet) {
// if (testSet.description != 'restoring root after ref resolution (#12)') return;
// if (testSet.description != 'change resolution scope') return;
(testSet.skip ? describe.skip : describe)(testSet.description, function() {

@@ -72,0 +72,0 @@ var validate, fullValidate;

Sorry, the diff of this file is not supported yet

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