1.0.3 • Published 6 years ago

@shanedaugherty/try-or v1.0.3

Weekly downloads
1
License
ISC
Repository
github
Last release
6 years ago

TryOr

How to install

npm install @shanedaugherty/try-or --save

What is it

TryOr is a simple utility function that can be used to use execute code within a supercharged, one-line try catch block.

How does it work

TryOr is just a function that has two parameters: 1) a function to execute 2) (optional) either a fallback value, or a fallback function. Default is null.

const result = tryOr(() => mightThrowAnError(), 'hello')

// result is 'hello';
const result = tryOr(
    () => mightThrowAnError(),
    (error) => {
        logError(error);
        return 'hi';
    }
)

// result is 'hi';

See more examples here: https://shanedaugherty.com/posts/a-shortcut-to-the-try-catch-block