Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Tweaking nothing and anything to be closer to the JSON Schema equival…

…ents.
  • Loading branch information...
commit d96443864e798ffbf43d2c12ca106195be3d3fb8 1 parent f9a9385
@molnarg authored
Showing with 5 additions and 4 deletions.
  1. +2 −1  lib/patterns/anything.js
  2. +3 −3 lib/patterns/nothing.js
View
3  lib/patterns/anything.js
@@ -1,4 +1,5 @@
var schema = require('../schema')
+ , nothing = require('./nothing')
var anything = module.exports = new schema({
compile : function() {
@@ -6,7 +7,7 @@ var anything = module.exports = new schema({
},
generate : function() {
- var type = [Boolean, Number, String, Array, Object][Math.floor(Math.random()*5)]
+ var type = [nothing, Boolean, Number, String, Array, Object][Math.floor(Math.random()*6)]
return type.schema.generate()
},
View
6 lib/patterns/nothing.js
@@ -6,11 +6,11 @@ var nothing = module.exports = new schema({
},
generate : function() {
- return null
+ return Math.random() < 0.5 ? null : undefined
},
toJSON : function() {
- return { disallow : 'any' }
+ return { type : 'null' }
}
})
@@ -19,5 +19,5 @@ schema.fromJS.def(function(sch) {
})
schema.fromJSON.def(function(sch) {
- if (sch.disallow === 'any') return nothing
+ if (sch.type === 'null') return nothing
})
Please sign in to comment.
Something went wrong with that request. Please try again.