Skip to content
This repository was archived by the owner on Nov 27, 2018. It is now read-only.
This repository was archived by the owner on Nov 27, 2018. It is now read-only.

Move data validation logic to a separate module  #18

Description

@maxmalov

Hi. I've found express-form very useful, but only for express applications. For plain objects I can use https://www.npmjs.org/package/node-validator, but it didn't use validator package, which isn't nice. I think express-form can be easily refactored into 2 packages. First one is about data validation (with chaining and all cool stuff), and the second one is about express middleware specific. Here are some thoughts:

Object validation

// create validator bundle
var v = validator(
  validator.property('name').trim().toString().requred(), // alias for form.field
  // other  routines
);

// perform data validation
v.run(objectToValidate, function (err, data) {
  // err - validation errors (same as in the middleware) or null
  // data - sanitized objectToValidate
});

Express middleware

form factory for middleware will just delegate all validation specific logic to the validation module.

Any thoughts?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions