https://github.com/lamansky/otherwise
[Node.js] Executes fallback behavior if a function was unsuccessful.
https://github.com/lamansky/otherwise
Last synced: 2 months ago
JSON representation
[Node.js] Executes fallback behavior if a function was unsuccessful.
- Host: GitHub
- URL: https://github.com/lamansky/otherwise
- Owner: lamansky
- License: mit
- Created: 2018-05-22T15:50:15.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2020-11-12T05:18:23.000Z (over 5 years ago)
- Last Synced: 2025-10-17T16:27:42.400Z (8 months ago)
- Language: JavaScript
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license.txt
Awesome Lists containing this project
README
# otherwise
Executes fallback behavior if a function was unsuccessful. Intended for use in modules that use option object arguments.
## Installation
Requires [Node.js](https://nodejs.org/) 6.0.0 or above.
```bash
npm i otherwise
```
## API
The module exports a single function.
### Parameters
1. 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. (If `args` are specified, they will be provided as subsequent arguments.) If the function argument is not called, then `elseThrow` and `elseReturn` will not be taken into consideration, and the return value of the `elseCall` function will be forwarded.
* `elseThrow` (Error or string): An error to be thrown. A string will be wrapped in an `Error` object automatically.
* `elseReturn` (any): A value to return if `elseThrow` is omitted.
2. Optional: Object argument:
* `defaultErrorClass` (Class): An Error class in which to wrap `elseThrow` if it is a string.
* `args` (array): An array of arguments that should be passed on to `elseCall` if provided.
### Return Value
Returns the return value of `elseCall` (if provided) or returns `elseReturn`.