Skip to content

Instantly share code, notes, and snippets.

@cbaclig
Created September 12, 2013 02:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cbaclig/6532566 to your computer and use it in GitHub Desktop.
Save cbaclig/6532566 to your computer and use it in GitHub Desktop.
Node validation framework idea
input:
* name
* url
* description
* categories
* tags
* pubMonthlyUniqueVisitors
* pubMonthlyPageViews
output:
# property entity
class PropertyValidator extend BaseValidator
PropertyValidator: (@errorFormat = 'nested') ->
schema:
first_name: new NameValidator(required: false)
first_name: NumberValidator.validate(0, 50)
url: new UrlValidator()
middleware: (req, res, next) ->
req.values = if @validate then @validate(req.body) else req.body
next()
validate: (params) ->
for property, validator of @schema
req.body[property] = validator.validate(req.body[property])
if error throw
new Property(data)
{
first_name: {
message: 'human readable'
value: 4
},
buyer: {
name:
},
'buyer.name' : {
}
'buyer[name]' : {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment