bloody-attempt

smart try {} catch(){}

Usage no npm install needed!

<script type="module">
  import bloodyAttempt from 'https://cdn.skypack.dev/bloody-attempt';
</script>

README

attempt

browser support

Build Status

install

$ npm install bloody-attempt

require

var attempt = require("bloody-attempt")

api

attempt(fn) > boolean

returns whether or not fn execution has been without error.

attempt.withValue(fn) > value

returns the result of fn() or the error it threw.

attempt.all(object) > key || null

tries to execute functions in object until one does not error. returns the key matching the error free function. if none executed properly, null is returned.

attempt.all({
  EVENT_OBJECT: function(){
    document.createEventObject()
  },
  CUSTOM_EVENT: function(){
    new CustomEvent(
      "attempt",
      {
        bubbles: false,
        cancelable: false
      }, {
        detail: {}
      }
    )
  }
})
// => "CUSTOM_EVENT"