Closed ChALkeR closed 4 years ago
E.g. require('.').validator({items:[{not:{required:['x']}},{}]}).toModule()
:
Before:
(function() {
'use strict'
const hasOwn = Function.prototype.call.bind(Object.prototype.hasOwnProperty);
return (function validate(data) {
if (data === undefined) data = null
let errors = 0
if (Array.isArray(data)) {
if (data[0] !== undefined && hasOwn(data, 0)) {
const prev0 = errors
if (data[0] !== undefined && hasOwn(data, 0)) {
if (typeof data[0] === "object" && data[0] && !Array.isArray(data[0])) {
if (!(data[0]["x"] !== undefined && hasOwn(data[0], "x"))) {
errors++
}
}
}
if (prev0 === errors) {
return false
} else {
errors = prev0
}
}
}
return errors === 0
})})();
After:
(function() {
'use strict'
const hasOwn = Function.prototype.call.bind(Object.prototype.hasOwnProperty);
return (function validate(data) {
if (data === undefined) data = null
let errors = 0
if (Array.isArray(data)) {
if (data[0] !== undefined && hasOwn(data, 0)) {
const prev0 = errors
if (typeof data[0] === "object" && data[0] && !Array.isArray(data[0])) {
if (!(data[0]["x"] !== undefined && hasOwn(data[0], "x"))) {
errors++
}
}
if (prev0 === errors) {
return false
} else {
errors = prev0
}
}
}
return errors === 0
})})();
After #42.
Checking for
present()
twice makes no sense.Also, now
{items:[{allOf:[{default:10}]}
fails withuseDefaults
, because defaults don't make any sense in nested checks.rule
andsubrule
moved belowpresent()
check because they now circumvent it when called on the current node, so we must be sure that those are not used before that check.Only
dependencies/dependentRequired
,not
,if/then/else
,allOf/anyOf/oneOf
can cause such nested checks -- i.e. anything that invokesrule(current,
orsubrule(current,
.