1.0.0 • Published 5 years ago

terrorify v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

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
1.0.0

5 years ago