# @shanedaugherty/try-or

> A shortcut to the try catch block.

Latest version **1.0.3** (published 2018-02-26) · ISC license · 0 weekly downloads

## Install

```sh
npm install @shanedaugherty/try-or
pnpm add @shanedaugherty/try-or
yarn add @shanedaugherty/try-or
bun add @shanedaugherty/try-or
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2018-02-26 |
| First published | 2017-12-06 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 15 |
| Unpacked size | 10.4 KB |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| Maintainers | shanedaugherty |

## Links

- npm: https://www.npmjs.com/package/@shanedaugherty/try-or
- Repository: https://github.com/shanedaugherty/TryOr
- Homepage: https://github.com/shanedaugherty/TryOr#readme
- Issues: https://github.com/shanedaugherty/TryOr/issues
- npm.io page: https://npm.io/package/@shanedaugherty/try-or

## Dependencies (15)

- [mocha](https://npm.io/package/mocha.md) ^3.2.0
- [eslint](https://npm.io/package/eslint.md) ^4.1.1
- [rollup](https://npm.io/package/rollup.md) ^0.43.0
- [istanbul](https://npm.io/package/istanbul.md) ^0.4.5
- [babel-eslint](https://npm.io/package/babel-eslint.md) ^7.2.3
- [rollup-watch](https://npm.io/package/rollup-watch.md) ^4.0.0
- [babel-register](https://npm.io/package/babel-register.md) ^6.18.0
- [babelrc-rollup](https://npm.io/package/babelrc-rollup.md) ^3.0.0
- [babel-preset-es2015](https://npm.io/package/babel-preset-es2015.md) ^6.18.0
- [rollup-plugin-babel](https://npm.io/package/rollup-plugin-babel.md) ^2.7.1
- [rollup-plugin-istanbul](https://npm.io/package/rollup-plugin-istanbul.md) ^1.1.0
- [babel-plugin-external-helpers](https://npm.io/package/babel-plugin-external-helpers.md) ^6.18.0
- [babel-plugin-transform-class-properties](https://npm.io/package/babel-plugin-transform-class-properties.md) ^6.24.1
- [babel-plugin-transform-decorators-legacy](https://npm.io/package/babel-plugin-transform-decorators-legacy.md) ^1.3.4
- [babel-plugin-transform-object-rest-spread](https://npm.io/package/babel-plugin-transform-object-rest-spread.md) ^6.26.0

## Recent versions

- 1.0.3 (latest) — 2018-02-26
- 1.0.2 — 2018-02-24
- 1.0.1 — 2017-12-06
- 1.0.0 — 2017-12-06

## README

# 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

---
_Source: https://npm.io/package/@shanedaugherty/try-or · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
