8000 GitHub - rbmccr/thereforejs: A simple JavaScript library intended to facilitate error handling. Therefore you must use it.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

A simple JavaScript library intended to facilitate error handling. Therefore you must use it.

Notifications You must be signed in to change notification settings

rbmccr/thereforejs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ThereforeJS

A small and easy-to-integrate JavaScript library for managing errors.

  • Write shorter, simpler functions
  • Improve the testability of your code
  • Provide a variety of fallback scenarios if an error occurs

Setup

  • Import the class
  • Instantiate the class
  • Prepare a config object
  • Wrap your function call in an IAm method
import IAm from "therefore";

let iam = new IAm();

let config = {
  // tell me what to do if there's an error, or just give me some defaults
}

function thisMightNotWork () {
  // do something that might throw an error
}

In the flow of your logic in your code:

function thisDoesSomething () {
  let someValue = iam.watching(thisMightNotWork, config)
}

Available Methods

  • watching(): Provides a try/catch/finally block. Accepts a callback function and a config object as arguments.

You can pass a config in as a global config during the IAm class instantiation or just provide a config each time you wrap a callback. All of these properties in the config object below are optional.

let config = {
  try: {
    default: *any*,
    execute: *Function*
  },
  catch: {
    default: *any*,
    execute: *Function*,
    logType: *string*, // a console method that outputs the error to the console (e.g. 'log', 'error', 'warn')
    provideErr: *boolean*
  },
  finally: {
    default: *any*,
    execute: *Function*
  },
  silence: *boolean* // prevent all console logs generated by IAm
}

Here's the order in which a value is returned from a call to watching():

1. value returned from finally: execute
2. finally: default
3. [if no error] value returned from the callback argument provided to watching()
4. [if no error] value returned from try: execute
5. [if no error] try: default
6. value returned from catch: execute
7. catch: provideErr
8. catch: default

About

A simple JavaScript library intended to facilitate error handling. Therefore you must use it.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0