Miss any of our Open RFC calls?Watch the recordings here! »

terrorify

1.0.0 • Public • Published

TErrorify

Simplify Error Handling in Typescript / Javascript.

One Line implementation for catching error(s) and getting result(s).

styled with prettier CircleCI

Usage

TErrorify aims to simplify the error handling in javascript / typescript without Nested Try / Catch Block for both Promise and Function.

Promise Handling

With TErrorify, we can handle multiple Promise without Nested Structure to simplify the codebase.

import { asyncify } from 'terrorify';
 
// Create a Dummy Promise Function which will throw / return result
const promise = async (willSucceed: boolean): Promise<boolean> => {
  if (willSucceed) return true;
  else throw new Error('foo bar');
};
 
const [err1, result1] = await asyncify(promise(false));
// err1 = Error('foo bar')
// result1 = undefined
 
const [err2, result2] = await asyncify(promise(true));
// err2 = null
// result2 = true

Function Handling

With TErrorify, we can handle multiple Function without Nested Structure to simplify the codebase.

import { syncify } from 'terrorify';
 
// Create a Dummy Function which will throw / return result
const func = (willSucceed: boolean): boolean => {
  if (willSucceed) return true;
  else throw new Error('foo bar');
};
 
const [err1, result1] = syncify(func(false));
// err1 = Error('foo bar')
// result1 = undefined
 
const [err2, result2] = syncify(func(true));
// err2 = null
// result2 = true

Install

npm i terrorify

DownloadsWeekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

22.6 kB

Total Files

10

Last publish

Collaborators

  • avatar