Function: createFunctionPrecondition()
createFunctionPrecondition(
precondition
:FunctionPrecondition
,fallback
:FunctionFallback
):MethodDecorator
Utility to make function preconditions.
// No fallback (returns undefined)
function requireGuild(value: number) {
return createFunctionPrecondition((message: Message) =>
message.guild !== null
);
}
// With fallback
function requireGuild(
value: number,
fallback: () => unknown = () => undefined
) {
return createFunctionPrecondition(
(message: Message) => message.guild !== null,
fallback
);
}
Parameters
Parameter | Type | Description |
---|---|---|
precondition | FunctionPrecondition | The function that defines whether or not the function should be run, returning the returned value from fallback |
fallback | FunctionFallback | The fallback value that defines what the method should return in case the precondition fails |
Returns
MethodDecorator
Since
1.0.0