filterResolutionParam
Description
This function is used by all other functions in puddy-m library. It ensures whether the value to be resolved should be the tuple parameter (an array) or the single valued (usually the first parameter of the client function).
For example, if the tuple parameter is passed when invoking the validateString function, it will get the string and put inside the tuple array and resolve the array. This will allow you to accumulate valid parameters in a chained function invocation to use them later on. You are only using this function if you are creating your own function that behaves like the the functions from this lib by accumulating previous chained parameters from puddy-m functions. The promise always resolves
Parameter List | Returns | Rejection Errors |
---|---|---|
| Promise<Array<*> || *> | This function doesn't depend on any other from the library. |
Related Functions | Function Signature | |
This function doesn't depend on any other from the library. | function filterResolutionParam(tuple, singleValue): Promise<Array<*> || *> |
Examples
1
2
3
4
5
6
7
8
9
10
11
12
import { filterResolutionParam } from "puddy-m/lib/validators"
;const myFunction = async (param, tuple) => new Promise((resolve, reject) => {
if (param) {
resolve(filterResolutionParam(tuple, param));
} else {
reject(new Error("Parameter is required."));
}
});
nmyFunction(1, [])
.then((tuple) => myFunction(2, tuple))
.then(([_1, _2]) => _1 + _2);
1
2
3
4
5
6
7
8
9
10
11
// The use of this function can be demonstrated by using three other functions as example.// This is not meant to be used by users the puddy-m lib.
import { filterResolutionParam } from "puddy-m/lib/validators";
validateString("hello", [])
.then((tuple) => validateNumber(5, tuple))
.then((tuple) => validateBoolean(true, tuple))
.then(([validatedString, validatedNumber, validatedBoolean]) => {
/*Do logic using the three validated parameter here*/
});
// The validatedString, validatedNumber and validatedBoolean can be accessed in the last promise thanks to the filterResolutionParam.