Class: NullNode

NullNode

new NullNode(){NullNode}

The NullNode class represents a value that must be null

Returns:
NullNode instance.

Methods

addCustomValidator(node){NullNode}

Add a custom object validator

Name Type Description
node CustomNode

custom validation node to be used for this field validation

Example
// Create a Custom validator

assert = require('assert'),
  Compiler = require('vitesse').Compiler,
  NullNode = require('vitesse').NullNode,
  CustomNode = require('../lib/custom');

var customValidator = new CustomNode()
  .setContext({divisibleBy: 10})
  .setValidator(function(object, context) {
    if((object % context.divisibleBy) != 0) {
      return new Error('number not divisible by ' + context.divisibleBy);
    }
  });

var schema = new NullNode(null, null, {typeCheck:true})
var compiler = new Compiler({});
// Compile the AST
var func = compiler.compile(schema, {});

// Validate {}
var results = func.validate({});
assert.equal(1, results.length);
assert.equal('field is not a null', results[0].message);
assert.deepEqual(['object'], results[0].path);
assert.ok(results[0].rule === schema);

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

Type check value

Name Type Description
typeCheck boolean

type check value

comments powered by Disqus