# tryor

> return fn() or default value (in case of exception)

Latest version **0.1.2** (published 2013-04-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install tryor
pnpm add tryor
yarn add tryor
bun add tryor
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.2 |
| Published | 2013-04-22 |
| First published | 2013-04-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Olov Lassus |
| Maintainers | olov |
| Keywords | try, catch, default |

## Links

- npm: https://www.npmjs.com/package/tryor
- Repository: https://github.com/olov/tryor
- npm.io page: https://npm.io/package/tryor

## Alternatives

- [@sentry/react-native](https://npm.io/package/@sentry/react-native.md) — 2.6M weekly downloads
- [@ardatan/aggregate-error](https://npm.io/package/@ardatan/aggregate-error.md) — 708.1K weekly downloads
- [custom-error-generator](https://npm.io/package/custom-error-generator.md) — 2.0K weekly downloads
- [@technik-sde/prosemirror-recreate-transform](https://npm.io/package/@technik-sde/prosemirror-recreate-transform.md) — 1.5K weekly downloads
- [@suchipi/error-utils](https://npm.io/package/@suchipi/error-utils.md) — 78 weekly downloads

## Recent versions

- 0.1.2 (latest) — 2013-04-22
- 0.1.1 — 2013-04-22
- 0.1.0 — 2013-04-22

## README

# tryor.js
Give it a function and a default value. `tryor` will give you back the return value of
the function or, in case the function threw an exception, the default value.
Works in node and browsers.



## Usage
```javascript
    // do this
    var config = tryor(function() {
        return JSON.parse(userProvidedConfigString);
    }, {});

    // instead of
    var config; // or var config = {}; and empty catch
    try {
        config = JSON.parse(userProvidedConfigString);
    } catch (e) {
        config = {};
    }
```

Works extra well with ES6-style `const` variables.



## Installation

### Node
Install using npm

    npm install tryor

```javascript
var tryor = require("tryor");
```

### Browser
Clone the repo and include it in a script tag

    git clone https://github.com/olov/tryor.git

```html
<script src="tryor/tryor.js"></script>
```

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