Socket
Socket
Sign inDemoInstall

tryor

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    tryor

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


Version published
Weekly downloads
184K
increased by7.48%
Maintainers
1
Install size
3.38 kB
Created
Weekly downloads
 

Readme

Source

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

    // 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
var tryor = require("tryor");

Browser

Clone the repo and include it in a script tag

git clone https://github.com/olov/tryor.git
<script src="tryor/tryor.js"></script>

Keywords

FAQs

Last updated on 22 Apr 2013

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc