Schema

Creates a new schema. The schema can be used
to validate any object and deterime if it
matches the rules within the schema.

The each rule within the schema must have a
type. Valid types are:

String

Number

Boolean

Date

Buffer

RexExp

Object

Array

Note that Object can contain any object.
Anything contained within the object will be
ignored by the schema. Array will match any
array, and its contents will also be ignored.
These can be used as mixed types.

Rules can also have match conditions. These
match conditions are optional.

Pattern Match

{ field: { type:String, match:/pattern/ }}

Will match a value matching the pattern
/pattern/.

Exists

{ field: { type:String, match: { exists:true }}}

Will match a value if it exists. By default
values can be undefined. Exists forces then
to be present in order to pass validation.

Custom Validatiors

If you need to do custom validation on a field a
validation function can be passed as the match
contition.

{ field: { type:String, match:function(val) { ... } }}

A validation function with a single argument
will be passed the value of the field and
is expected to return an error if validation
fails. If nothing is returned then the value
will pass validation.

{ field: { type:String, match:function(val, cb) { ... } }}

A validation function with a two arguments
will be passed the value of the field and a
callback. It will be is expected to callback
with an error if validation fails.
If the callback is executed with no arguments
then the value will pass validation.