Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F102835122
README.md
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Feb 24, 16:31
Size
864 B
Mime Type
text/html
Expires
Wed, Feb 26, 16:31 (2 d)
Engine
blob
Format
Raw Data
Handle
24434202
Attached To
R8244 Eawag_Swing_Weight_Elicitation
README.md
View Options
# 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>
```
Event Timeline
Log In to Comment