try-or-die

Inspired by Scala's `Try` classes (including `Success` and `Failure`).

Usage no npm install needed!

<script type="module">
  import tryOrDie from 'https://cdn.skypack.dev/try-or-die';
</script>

README

pipeline status coverage report

try-or-die

Inspired by Scala's Try classes (including Success and Failure).

Try and succeed

By using try-or-die you can avoid most try-catch blocks in your code. That is because try-or-die wraps around possible exceptions and simply returns the thing you want, or whatever else you want.

Don't get it? Here is an example that will always succeed:

let result = Try<User>(() => userFactory.create('Jack'))
                .map(e => e.name)
                .map(e => e.substr(-1) === 'k')
                .value;

// Result will be true.
console.log(result);