@trenskow/fail-silently

0.2.14 • Public • Published

@trenskow/fail-silently

A simple function wrapper for ignoring errors thrown.

Usage

You wrap the function you want to ignore errors thrown from as the example below.

const
	failSilently = require('@trenskow/fail-silently');

function myThrowingFunction(shouldThrow) {
    if (shouldThrow) throw new Error("This is my error.");
    return 'Hello, World!';
}

failSilently(myThrowingFunction)(false); // -> 'Hello, World!'
failSilently(myThrowingFunction)(true); // -> undefined

It also works with async functions.

LICENSE

See license in LICENSE

Readme

Keywords

Package Sidebar

Install

npm i @trenskow/fail-silently

Weekly Downloads

13

Version

0.2.14

License

BSD-2-Clause

Unpacked Size

5.16 kB

Total Files

7

Last publish

Collaborators

  • trenskow