conforma
Filter, validate and conform your data from POST request data in Express or other environment.
Install
npm install conforma --save
Usage
More examples you can find in example path or in test.
var conforma = ; formData ;
If your data is invalid, then you get error:
Error: Conforma Validation Error errors: name: 'ConformaError' message: 'email.invalid.format %s' field: 'nested.value1' value: 'email(at)localhost' name: 'ConformaError' message: 'only.alpha.allowed' field: 'nested.value2' value: 'HÄNSEL UND GRETEL'
If your data is valid, then you get the filtered and validated data:
value1: 123 value2: true nested: value1: 'email(at)localhost' value2: 'HÄNSEL UND GRETEL' value3: '<html>Hello World!</html>'
Use with Promise (bluebird)
var conforma = ; var formData = ; formData ;
Use with your local filter/validator
var conforma = ; var formData = ; formData ;
Use without new
var conforma = ; conforma ;
Use in ES6 Style
; ;
API
- setData(object)
- getData(filtered)
- filter(path, filter, options)
- validate(path, validator)
- move(srcPath, destPath)
- remove(path)
- exec(callback) return Promise
- reset
- mount()
Filter
With Filter you can transform your data to your valid format
- int
- float
- bool
- digit
- string
- stringLength
- trim whitespaces
- lowerCase
- upperCase
- escapeHtml (<>"'& to entities)
- addSlashes (like php)
- stripHtml (sanitize all html content)
- stripHtmlTags
- url [node url object keys]
- date [moment format]
- object
- array
- null
- uniqueList
Validator
- required
- empty allow empty fields
- emailMx
- alpha (UTF8 and whitespaces)
- alnum (UTF8 and whitespaces)
- number (allowed decimal place ,.)
- notEmpty
- equals
- compare (with other fields)
- contains
- isDate (format please use moment)
- inList
- length (min, max)
- objectId (Mongo ObjectID)
TODO
- extend all tests
- create some examples
- extend validator/filter
- extend README
- your suggestion
- i18n error messages
- bug fixing