Giter VIP home page Giter VIP logo

Comments (6)

syco avatar syco commented on May 23, 2024 3

from express-validator.

fedeci avatar fedeci commented on May 23, 2024 1

do we want to make a shift allowing validations to run on express requests and on plain json objects too?

Yeah, I think this can be done.

I'm marking this issue as an enhancement then, but please note it might take a few weeks/months before I'm able to get around to working on it @syco

I may do that this week. It shouldn't take me more than a couple hours to get it working.

from express-validator.

gustavohenke avatar gustavohenke commented on May 23, 2024

Hey,
In theory you can, it's how most of the tests are written, but all of express-validator assumes a request-like structure.

it('can be used on custom chains', async () => {
const req = { query: { foo: 1 } };
const { check, matchedData } = createInstance();
await check('foo').isAllowedDomain().run(req);
const data = matchedData(req);

...but this might be weird when you're not near the HTTP layer of your application (e.g. "why does this object have a body/cookie/query/header/param property")

You might like using pure validator.js instead: https://github.com/validatorjs/validator.js/
You'd need to validate each property you care about. And at of the time of writing, it'll throw if the input is not a string, which might or might not be annoying for you.

Then there are plenty other libraries for object validation out there.

from express-validator.

fedeci avatar fedeci commented on May 23, 2024

@gustavohenke do we want to make a shift allowing validations to run on express requests and on plain json objects too? It shouldn't be too tricky to implement and would provide a nice wrapper over validator.js.

from express-validator.

gustavohenke avatar gustavohenke commented on May 23, 2024

do we want to make a shift allowing validations to run on express requests and on plain json objects too?

Yeah, I think this can be done.

I'm marking this issue as an enhancement then, but please note it might take a few weeks/months before I'm able to get around to working on it @syco

from express-validator.

syco avatar syco commented on May 23, 2024

That's great news, thanks

from express-validator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.