Controller - API Usage

Path: /src/index.coffee compiled to /lib/index.js

To make all checks and also I/O specific optimizations available these checks are primarily asynchronous. While there are also synchronous variants available to the outside for simplicity better use the asynchronous ones because the other uses more cpu performance.

describe()

This will directly return the description of how the value has to be.

CoffeeScript Code
validator.describe name: 'test' # name to be displayed in errors (optional) schema: # definition of checks type: 'integer' , (err, text) -> return cb err if err console.log "Configuration:\n" + text

See the possibilities in schema definition.

Usage:describe(spec, cb)

Parameter
  • spec - Object specification for validation
    • name - String descriptive name of the data
    • schema - Object structure to check
    • context - Object additional data structure
  • cb - function(Error, String) callback with descriptive text or an error if something went wrong
See also
-describeSync

describeSync

This will directly return the description of how the value has to be.

CoffeeScript Code
schema = validator.describeSync name: 'test' # name to be displayed in errors (optional) schema: # definition of checks type: 'integer'

See the possibilities in schema definition. @name describeSync() @param {Object} spec specification for validation

  • name - String descriptive name of the data
  • schema - Object structure to check
  • context - Object additional data structure @return {String} descriptive text @throw {Error} if something went wrong @seedescribe()

check()

This will check the given value, sanitize it and return the new value or an Error to the callback.

CoffeeScript Code
validator.check name: 'test' # name to be displayed in errors (optional) value: input # value to check schema: # definition of checks type: 'integer' context: null # additional data (optional) , (err, result) -> # do something

See the possibilities in schema definition.

Usage:check(spec, cb)

Parameter
  • spec - Object specification for validation
    • name - String descriptive name of the data
    • schema - Object structure to check
    • context - Object additional data structure
    • value - original value (not changed)
  • cb - function(Error, Mixed) callback with optimized value or an error if something is wrong with the value as far as possible to sanitize

checkSync()

This will check the given value, sanitize it and return the new value or an Error to the callback.

CoffeeScript Code
input = validator.checkSync name: 'test' # name to be displayed in errors (optional) value: input # value to check schema: # definition of checks type: 'integer' context: null # additional data (optional)

See the possibilities in schema definition.

Usage:checkSync(spec)

Parameter
  • spec - Object specification for validation
    • name - String descriptive name of the data
    • schema - Object structure to check
    • context - Object additional data structure
    • value - original value (not changed)
Return
String optimized value
Throws
  • Error if something went wrong

selfcheck()

The method will check and optimize the schema definition. This is neccessary to evaluate higher class definitions. But it may also be used in tests to check the validator check options if they are valid.

CoffeeScript Code
validator.selfcheck type: 'integer' # definition of checks , (err, schema) -> # do something with optimized schema

See the possibilities in schema definition.

Usage:selfcheck(schema, cb)

Parameter
  • schema - Object structure to check
  • cb - function(Error, Mixed) callback with the checked schema or an error if something is wrong

selfcheckSync()

This may be used in tests to check the validator check options if they are valid.

CoffeeScript Code
try schema = validator.selfcheckSync type: 'integer' # definition of checks catch error # something in schema is not allowed

See the possibilities in schema definition.

Usage:selfcheckSync(schema)

Parameter
  • schema - Object structure to check
Return
String checked schema
Throws
  • Error if something went wrong