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 3.2.1 to 3.3.0

4

changelog.md

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

## 3.3.0/2018-01-08
- add `ignoreNodeType`
## 3.2.1/2017-11-14

@@ -2,0 +6,0 @@

8

index.js

@@ -24,3 +24,5 @@ const helpersFuncs = require('./helpers')

}
if (typeof schema !== 'object') throw new TypeError('Schema must be object or array')
if (typeof schema !== 'object') {
throw new TypeError(`Schema must be object or array, but got ${JSON.stringify(schema)}, maybe missing 'type' validator.`)
}

@@ -113,3 +115,5 @@ this._children = _compileSchema(schema, this)

validateType(children, ctx)
if (!opts.ignoreNodeType) {
validateType(children, ctx)
}

@@ -116,0 +120,0 @@ if (ctx._leaf || !isObject) {

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

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

@@ -317,2 +317,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.

@@ -319,0 +320,0 @@

@@ -9,3 +9,3 @@ const AJS = require('..')

} catch (e) {
assert.equal(e.message, 'Schema must be object or array')
assert.ok(e.message.match(/Schema must be object or array/))
}

@@ -12,0 +12,0 @@ })

@@ -56,2 +56,42 @@ const AJS = require('..')

it('ignoreNodeType', function () {
let userSchema = AJS('userSchema', {
posts: [{ type: 'string' }]
})
assert.deepEqual(userSchema.validate({
posts: '1'
}), {
valid: false,
error: {
validator: 'type',
path: '$.posts[]',
actual: '1',
expected: [ { type: 'string' } ],
schema: 'userSchema'
},
result: { posts: '1' }
})
assert.deepEqual(userSchema.validate({
posts: '1'
}, { ignoreNodeType: true }), {
valid: true,
error: null,
result: { posts: '1' }
})
userSchema = AJS('userSchema', {
posts: { type: 'string' }
})
assert.deepEqual(userSchema.validate({
posts: ['1', '2', '3']
}, { ignoreNodeType: true }), {
valid: true,
error: null,
result: { posts: ['1', '2', '3'] }
})
})
it('normal', function () {

@@ -58,0 +98,0 @@ let schema = AJS({ type: 'string' })

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