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

another-json-schema

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

another-json-schema - npm Package Compare versions

Comparing version 2.0.0 to 2.1.0

.editorconfig

19

index.js

@@ -116,3 +116,5 @@ 'use strict';

validateType(children, ctx);
if (!opts.ignoreNodeType) {
validateType(children, ctx);
}
if (ctx._leaf || isBuffer(children) || !isObject) {

@@ -152,9 +154,10 @@ return validateLeaf(children, opts, ctx);

if (ctx._leaf) {
if (ctx._parent) {
if (isArray && !ctx._array) {
throwError(value, ctx);
} else if (ctx._array && !isArray) {
throwError(value, ctx, null, 'array');
}
if ('function' === typeof ctx._children.type) {
return;
}
if (isArray && !ctx._array) {
throwError(value, ctx);
} else if (ctx._array && !isArray) {
throwError(value, ctx, null, 'array');
}
} else {

@@ -225,3 +228,3 @@ if (ctx._object && !isObject) {

}
error.actual = value;

@@ -228,0 +231,0 @@ error.expected = ctx._children;

{
"name": "another-json-schema",
"version": "2.0.0",
"version": "2.1.0",
"description": "Another JSON Schema, simple & flexible & intuitive.",

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

@@ -223,2 +223,3 @@ ### another-json-schema

- additionalProperties: {Boolean} if true, retain the original field. default `false`
- ignoreNodeType: {Boolean} if true, ignore check node type, like: `[]`. default: `false`
- gt, gte, lt, lte ...: {Boolean} if false, will not execute this validator.

@@ -225,0 +226,0 @@

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

assert.deepEqual(schema.validate(0), { valid: false,
error:
error:
{

@@ -54,3 +54,3 @@ schema: 'adultSchema',

assert.deepEqual(schema.validate('0'), { valid: false,
error:
error:
{

@@ -73,7 +73,6 @@ validator: 'type',

var schema = AJS('typeSchema', { type: checkIsObject });
assert.deepEqual(schema.validate([]), { valid: true, error: null, result: [] });
assert.deepEqual(schema.validate({}), { valid: true, error: null, result: {} });
assert.deepEqual(schema.validate(0), { valid: false,
error:
error:
{

@@ -102,3 +101,3 @@ validator: 'type',

valid: false,
error:
error:
{

@@ -113,2 +112,28 @@ validator: 'type',

});
var schema = AJS('typeSchema', [{ type: 'string' }]);
assert.deepEqual(schema.validate('a'), {
valid: false,
error: {
validator: 'type',
actual: 'a',
expected: { type: 'string' },
path: '$[]',
schema: 'typeSchema'
},
result: 'a'
});
var schema = AJS('typeSchema', { type: 'string' });
assert.deepEqual(schema.validate(['a']), {
valid: false,
error: {
validator: 'type',
actual: [ 'a' ],
expected: { type: 'string' },
path: '$',
schema: 'typeSchema'
},
result: [ 'a' ]
});
});

@@ -120,3 +145,3 @@

assert.deepEqual(schema.validate(0), { valid: false,
error:
error:
{

@@ -136,3 +161,3 @@ schema: 'numberSchema',

assert.deepEqual(schema.validate(-1), { valid: false,
error:
error:
{

@@ -152,3 +177,3 @@ schema: 'numberSchema',

assert.deepEqual(schema.validate(0), { valid: false,
error:
error:
{

@@ -168,3 +193,3 @@ schema: 'numberSchema',

assert.deepEqual(schema.validate(1), { valid: false,
error:
error:
{

@@ -185,3 +210,3 @@ schema: 'numberSchema',

assert.deepEqual(schema.validate(-1), { valid: false,
error:
error:
{

@@ -201,3 +226,3 @@ schema: 'numberSchema',

assert.deepEqual(schema.validate('ccc'), { valid: false,
error:
error:
{

@@ -220,3 +245,3 @@ validator: 'enum',

assert.deepEqual(schema.validate(''), { valid: false,
error:
error:
{

@@ -240,3 +265,3 @@ validator: 'required',

assert.deepEqual(schema.validate('bbb'), { valid: false,
error:
error:
{

@@ -259,3 +284,3 @@ validator: 'pattern',

assert.deepEqual(schema.validate('bbb'), { valid: false,
error:
error:
{

@@ -262,0 +287,0 @@ validator: 'validate',

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

});
assert.deepEqual(userSchema.validate({

@@ -31,3 +31,3 @@ _id: '111111111111111111111111',

pet: 'cat'
}), { valid: true, error: null, result:
}), { valid: true, error: null, result:
{ _id: '111111111111111111111111',

@@ -45,3 +45,3 @@ name: 'nswbmw',

pet: 'cat'
}, { additionalProperties: true }), { valid: true, error: null, result:
}, { additionalProperties: true }), { valid: true, error: null, result:
{ _id: '111111111111111111111111',

@@ -59,3 +59,3 @@ name: 'nswbmw',

assert.deepEqual(schema.validate(1), { valid: false,
error:
error:
{

@@ -67,9 +67,10 @@ validator: 'type',

schema: undefined },
result: 1
result: 1
});
var schema = AJS([{ type: 'string' }]);
assert.deepEqual(schema.validate('1', { ignoreNodeType: true }), { valid: true, error: null, result: '1' });
assert.deepEqual(schema.validate(['1']), { valid: true, error: null, result: ['1'] });
assert.deepEqual(schema.validate([2, '1']), { valid: false,
error:
error:
{

@@ -87,3 +88,3 @@ validator: 'type',

assert.deepEqual(schema.validate(['1', 2]), { valid: false,
error:
error:
{

@@ -117,5 +118,5 @@ validator: 'type',

error: null,
result:
result:
{ _id: '111111111111111111111111',
nicknames: [ 'nswbmw', 'xiaoxingxing' ] }
nicknames: [ 'nswbmw', 'xiaoxingxing' ] }
});

@@ -136,3 +137,3 @@

}), { valid: false,
error:
error:
{

@@ -162,3 +163,3 @@ validator: 'type',

}), { valid: false,
error:
error:
{

@@ -165,0 +166,0 @@ validator: 'type',

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