flexdinesh / flexdinesh/typy

[Feature] Function parameters validation

Open
#13 2 comments 0 reactions 0 assignees View on GitHub
help wanted
Dominant language
JavaScript
Stars
225
Forks
21
PR merge metrics
No merged PRs in 30d

Description

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](https://github.com/jadok/vemsy), 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](https://stackoverflow.com/questions/1007981/how-to-get-function-parameter-names-values-dynamically) 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 ?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reviewing the library's existing function checks, safeFunction support, and custom types. Determine whether parameter validation can distinguish standard Express middleware from middleware factories without relying on parameter names. Done should include a defined behavior for the requested validation and coverage for the examples described in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
express, javascript
Domain
backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.