2.0.1 • Published 5 years ago
otherwise v2.0.1
otherwise
Executes fallback behavior if a function was unsuccessful. Intended for use in modules that use option object arguments.
Installation
Requires Node.js 6.0.0 or above.
npm i otherwiseAPI
The module exports a single function.
Parameters
- Optional: Object argument:
elseCall(function): If provided, this function will be called with at least one argument: a function that will invoke the other fallbacks. (Ifargsare specified, they will be provided as subsequent arguments.) If the function argument is not called, thenelseThrowandelseReturnwill not be taken into consideration, and the return value of theelseCallfunction will be forwarded.elseThrow(Error or string): An error to be thrown. A string will be wrapped in anErrorobject automatically.elseReturn(any): A value to return ifelseThrowis omitted.
- Optional: Object argument:
defaultErrorClass(Class): An Error class in which to wrapelseThrowif it is a string.args(array): An array of arguments that should be passed on toelseCallif provided.
Return Value
Returns the return value of elseCall (if provided) or returns elseReturn.