error-fns
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

error-fns


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

LICENSE

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

Readme

Keywords

none

Package Sidebar

Install

npm i error-fns

Weekly Downloads

4

Version

0.0.3

License

LGPL-3.0

Unpacked Size

9.68 kB

Total Files

5

Last publish

Collaborators

  • lucemans