Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Function parameters validation #13

Open
jadok opened this issue Dec 11, 2018 · 2 comments
Open

[Feature] Function parameters validation #13

jadok opened this issue Dec 11, 2018 · 2 comments
Labels
help wanted Extra attention is needed

Comments

@jadok
Copy link

jadok commented Dec 11, 2018

Right now, the library provides the possibility to check :

  • if the tested element is a function
  • get a safeFunction

I am implementing it on a custom project, in my case, I'm using it because I have express middleware functions and some need to be generated before, here some example:

const app = express();

// standard express middleware
const myStandardExpressMiddleware = (req, res, next) => {
   // do something.
  next(); 
};

app.use(myStandardExpressMiddleware);

My issue case:

const app = express();

// standard express middleware
const myLessStandardExpressMiddleware = (data) => (req, res, next) => {
   // do something with my data.
  next(); 
};

app.use(myLessStandardExpressMiddleware(await getAwesomeData());

I want to have the ability to know in which case I'm in because my project allowing custom implementation, I do not know which case I am in.

To solve this issue, I will check the function argument(s) definition: an express middleware is always composed with req, res and next are optionnal.
I am using this stackoverflow post in attempt to do that.
Right now, I will implement it through the custom types (thanks @flexdinesh)

An known issue in this solution is that an user may implement an express middleware with a function with different name parameters. Ex: (request, response, next)

Is this something that could fit in this library ?

@flexdinesh
Copy link
Owner

@jadok This sounds interesting but practical use cases might be limited. Perhaps could you provide an example code on how you'd syntactically like to use this feature? We might then be able to dive into the possibilities.

@jadok
Copy link
Author

jadok commented Dec 16, 2018

I implemented on my project jadok/vemsy@71b8b11.
That one handle anonymous functions as well.

@flexdinesh flexdinesh added the help wanted Extra attention is needed label Jan 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants