@shanedaugherty/try-or
A shortcut to the try catch block.
Last updated a year ago by shanedaugherty .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @shanedaugherty/try-or 
SYNC missed versions from official npm registry.

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

Current Tags

  • 1.0.3                                ...           latest (a year ago)

4 Versions

  • 1.0.3                                ...           a year ago
  • 1.0.2                                ...           a year ago
  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 13
Last Day 1
Last Week 13
Last Month 2
Dev Dependencies (0)
None

Copyright 2014 - 2017 © taobao.org |