Class: AnyOfNode

AnyOfNode

new AnyOfNode(){AnyOfNode}

The AnyOfNode class represents a validation where the value must be one or more of the validation nodes

Returns:
AnyOfNode instance.

Methods

addValidations(validations){AnyOfNode}

One or more validation nodes must be satisfied for the provided value

Name Type Description
validations array

an array of validation nodes

Example
// Create a AnyOf validator for string validations

assert = require('assert'),
  Compiler = require('vitesse').Compiler,
  StringNode = require('vitesse').StringNode,
  IntegerNode = require('vitesse').IntegerNode,
  AnyOfNode = require('vitesse').AnyOfNode;

var string1 = new StringNode(null, null, {typeCheck:true})
  .addValidation({$gte: 5, $lte: 100});

var integer1 = new IntegerNode(null, null, {typeCheck:true})
  .addValidation({$gte: 100, $lte: 1000});

var schema = new AnyOfNode()
  .addValidations([string1, integer1]);

var compiler = new Compiler({});
// Compile the AST
var func = compiler.compile(schema, {});

// Validate {}
var results = func.validate({});
assert.equal(1, results.length);
assert.equal("value does not match any of the schema's in the anyOf rule", results[0].message);
assert.deepEqual(['object'], results[0].path);
assert.ok(results[0].rule === schema);

// Validate ''
var results = func.validate('4444');
assert.equal(1, results.length);
assert.equal("value does not match any of the schema's in the anyOf rule", results[0].message);
assert.deepEqual(['object'], results[0].path);
assert.ok(results[0].rule === schema);

// Validate string 'xxxxxx'
var results = func.validate(200);
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){AnyOfNode}

Type check value

Name Type Description
typeCheck boolean

type check value

comments powered by Disqus