###
Bongo.js
Unfancy models for MongoDB

@description: inbuilt validators and filters
@convention: if it's a function, it's a filter, if it's an array,
  or an instance of Validator, it's a (you guessed it) validator.
@author: Christopher Thorn
###
{check, sanitize} = require 'validator'

module.exports =
  
  email: [
    'not an email address.'
    (value)-> check(value).isEmail()
  ]

  enum: [
    'nonenumerated value.'
    (set, value)-> value in set
  ]

  pattern: [
    "doesn't match."
    (pattern, value)-> pattern.test value
  ]

  required: [
    'missed a required field.'
    (value)-> !!value
  ]

  validate: [
    "doesn't validate."
    (userFn, value)->
      userFn value, check
  ]

  xss:(string)-> sanitize(string).xss()