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.5.2 to 0.5.3

24

lib/ajv.js

@@ -12,2 +12,6 @@ 'use strict';

var META_SCHEMA_ID = 'http://json-schema.org/draft-04/schema';
var SCHEMA_URI_FORMAT = /^(?:(?:[a-z][a-z0-9+-.]*:)?\/\/)?[^\s]*$/i;
function SCHEMA_URI_FORMAT_FUNC(str) {
return SCHEMA_URI_FORMAT.test(str);
}

@@ -35,2 +39,3 @@ /**

this.addSchema = addSchema;
this.validateSchema = validateSchema;
this.getSchema = getSchema;

@@ -93,5 +98,16 @@ this.addFormat = addFormat;

/**
* Validate schema
* @param {Object} schema schema to validate
* @return {Boolean}
*/
function validateSchema(schema) {
var $schema = schema.$schema || META_SCHEMA_ID;
return validate($schema, schema);
var currentUriFormat = self._formats.uri;
self._formats.uri = typeof currentUriFormat == 'function'
? SCHEMA_URI_FORMAT_FUNC
: SCHEMA_URI_FORMAT;
var valid = validate($schema, schema);
self._formats.uri = currentUriFormat;
return valid;
}

@@ -133,3 +149,7 @@

|| validateSchema(schema);
if (!ok) console.error('schema is invalid:\n', errorsText());
if (!ok) {
var message = 'schema is invalid:' + errorsText();
if (self.opts.validateSchema == 'log') console.error(message);
else throw new Error(message);
}

@@ -136,0 +156,0 @@ resolve.ids.call(self, schema);

2

lib/compile/formats.js

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

// uri: https://github.com/mafintosh/is-my-json-valid/blob/master/formats.js
uri: /^([a-z][a-z0-9+-.]*:){0,1}\/\/[^\s]*$/i,
uri: /^(?:[a-z][a-z0-9+-.]*:)?\/\/[^\s]*$/i,
// email (sources from jsen validator):

@@ -29,0 +29,0 @@ // http://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address#answer-8829363

{
"name": "ajv",
"version": "0.5.2",
"version": "0.5.3",
"description": "Another JSON schema Validator",

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

@@ -111,3 +111,16 @@ # ajv - Another JSON Schema Validator

By default schema is validated against meta-schema before it is compiled and if the schema does not pass validation the exception is thrown. This behaviour is controlled by `validateSchema` option.
##### .validateSchema(Object schema) -> Boolean
Validates schema.
If schema doesn't have `$schema` property it is validated against draft 4 meta-schema (option `meta` should not be false).
If schema has `$schema` property than the schema with this id (should be previously added) is used to validate passed schema.
Errors are available at `ajv.errors`.
##### .getSchema(String key) -> Function<Object data>

@@ -144,3 +157,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.
- _validateSchema: validate added/compiled schemas 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 exception is thrown. Pass "log" in this option to log error instead of throwing exception.
- _uniqueItems_: validate `uniqueItems` keyword (true by default).

@@ -172,2 +185,9 @@ - _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.2
doT is no longer a run-time dependency
ajv can be used in the browser (with browserify)
##### 0.5.0

@@ -174,0 +194,0 @@

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

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

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

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

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

@@ -38,0 +38,0 @@ var remoteRefs = {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc