@exivar/funtry
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

FunTry

Super lightweight Async/Sync function handler that provides a one liner replacement to traditional try...catch block.

Installation

npm install @exivar/funtry
#or
yarn add @exivar/funtry

Usage

Common Js

const asyncTry = require('@exivar/funtry').asyncTry

// returns array [result, error]
var response = await asyncTry(<promise>);

if(response[1]) { //if error
  throw Error('this is error');
}

var result = response[0];

ES Module

import {asyncTry, syncTry} from '@exivar/funtry';

const [result, error] = await asyncTry(<promise>);
if(error){
  // validate returned error and return a custom error;
  throw Error('custom error');
}
// or do something with result

Package Sidebar

Install

npm i @exivar/funtry

Weekly Downloads

1

Version

1.0.2

License

ISC

Unpacked Size

8.5 kB

Total Files

14

Last publish

Collaborators

  • exivar