validateFunction
Description
It resolves if the parameter passed is a function type (lambda or closure).
Parameter List | Returns | Rejection Errors |
---|---|---|
| Promise<Function || Array> | |
Related Functions | Function Signature | |
function supposedFunction(supposedString[, tuple]): Promise<Function || Array> |
Examples
1
2
3
4
5
import { validateFunction } from "puddy-m/lib/validators";
validateFunction(console.log).then((validatedFunction) =>
validatedFunction("I'm a function and I'm being invoked")
); // prints "I'm a function and I'm being invoked"
1
2
3
4
5
import { validateString, validateFunction } from "puddy-m/lib/validators";
validateFunction(console.log, [])
.then((tuple) => validateString("string", tuple))
.then(([logger, str]) => logger(str)); // prints 'string'
1
2
3
4
5
6
7
8
9
10
11
12
13
import { validateFunction } from "puddy-m/lib/validators";
const run = async () => {
try {
const validatedFunction = await validateFunction(() => {});
console.log(validatedFunction); // prints [Function (anonymous)]
} catch (e) {
console.log(e);
}
};
run();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import { validateFunction } from "puddy-m/lib/validators";
const run = async () => {
try {
const validatedFunction = await validateFunction("Not a function");
console.log(emptyArray);
} catch (e) {
// Throws a FunctionValidationError
console.log(e);
}
};
run();