0.0.3 • Published 2 years ago

error-fns v0.0.3

Weekly downloads
-
License
LGPL-3.0
Repository
-
Last release
2 years ago

A simplified general-purpose permissions system for node apps.

Table of Contents

Installation

Using npm:

npm install error-fns

or if you prefer to use the yarn package manager:

yarn add error-fns

or if you prefer to use the pnpm package manager:

pnpm add error-fns

couldThrow

Assuming there is some weird function like so:

const subTract = (a: number, b: number, c: string) => {
    console.log(c);

    return a - b;
};

couldThrow allows your to do

const { error, result } = couldThrow(subTract, 0, 0, '');

if (error) throw error; // handle error accordingly

console.log(result);

as opposed to

let result2: number;

try {
    result2 = subTract(0, 0, '');
} catch (error) {
    throw error; // handle error accordingly
}

console.log(result2);

toCouldThrow

If you would like to pre-convert the couldThrow function in a promisify way you can do the following

// Somewhere in the beginning
const couldThrowifiedSubTract = toCouldThrow(subTract);

// And then elsewhere in the code
const { error, result } = couldThrowifiedSubTract(0, 0, '');

if (error) throw error; // handle error accordingly

console.log(result);

Contributors

npm.io

LICENSE

This package is licensed under the GNU Lesser General Public License.

0.0.3

2 years ago

0.0.2

2 years ago

0.0.2-alpha.3

2 years ago

0.0.2-alpha.2

2 years ago

0.0.2-alpha.1

2 years ago

0.0.1-alpha.3

2 years ago

0.0.1-alpha.2

2 years ago