new AllOfNode(){AllOfNode}
The AllOfNode class represents a set of validation nodes that must all be valid for this node to be valid
Returns:
AllOfNode instance.Methods
-
addValidations(validations){AllOfNode}
-
Add validation nodes that must all be satisfied for the provided value
Name Type Description validations
array an array of validation nodes
Example
// Create a AllOf validator for string validations assert = require('assert'), Compiler = require('vitesse').Compiler, StringNode = require('vitesse').StringNode, AllOfNode = require('vitesse').AllOfNode; var string1 = new StringNode(null, null, {typeCheck:true}) .addValidation({$gte: 5, $lte: 100}); var string2 = new StringNode(null, null, {typeCheck:true}) .addValidation({$in: ['roger', 'william', 'christopher']}); var schema = new AllOfNode() .addValidations([string1, string2]); var compiler = new Compiler({}); // Compile the AST var func = compiler.compile(schema, {}); // Validate {} var results = func.validate({}); assert.equal(1, results.length); assert.equal("one or more schema's did not match the allOf rule", results[0].message); assert.deepEqual(['object'], results[0].path); assert.ok(results[0].rule === schema); // Validate '' var results = func.validate('444444'); assert.equal(1, results.length); assert.equal("one or more schema's did not match the allOf rule", results[0].message); assert.deepEqual(['object'], results[0].path); assert.ok(results[0].rule === schema); // Validate string 'xxxxxx' var results = func.validate('william'); assert.equal(0, results.length);
-
generate(context)
-
Generate the code for this node
Name Type Description context
object the generation context for this node
-
path(){array}
-
Return the current object path
Returns:
array containing the path to this node
-
setTypeCheck(typeCheck){AllOfNode}
-
Type check value
Name Type Description typeCheck
boolean type check value