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

Move data validation logic to a separate module #18

Open
maxmalov opened this issue Sep 13, 2014 · 1 comment
Open

Move data validation logic to a separate module #18

maxmalov opened this issue Sep 13, 2014 · 1 comment

Comments

@maxmalov
Copy link

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?

@maxmalov maxmalov changed the title Extract data validation logic to a separate module Move data validation logic to a separate module Sep 13, 2014
@freewil
Copy link
Owner

freewil commented Sep 13, 2014

I think this makes a lot of sense. If you or someone else wants to work on that, I would accept a pull request to do that. 👍

If you want some feedback, I would also be happy to do that.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants