spumko/joi — pull request #242 by petreboy14 (2014-04-11 03:08:59+00:00)
Title: Adds support for any().type(type)

This is a first stab at allowing for checking that a property is an instance of a desired type which may be a custom or environment specific one (Buffer, Stream, etc).
For example:
```
var schema = { buffer: Joi.any().type(Buffer) };
Joi.validate( { buffer: new Buffer('test') }, schema }); // returns no errors
Joi.validate({ buffer: 2, schema }); // Will return an error
```
If the 'class' does not exist, Joi will throw an error when attempting to define the type()
```
var schema = { buffer: Joi.any().type(FooBar) } // throws error
```
One caveat is that primitives aren't instances of their corresponding classes so something like the following will return an error.
```
var schema = { string: Joi.any().type(String) };
Joi.validate( { string: 'test', schema } ) // Returns an error since 'test' is not an instance of String
```
I didn't know if you wanted me to try and handle these situations nicely. So, if someone passes in a primitives class return the corresponding Joi type. Like in the previous example, if they pass in String as the type then turn the validation object into Joi.string(). Let me know what you think.