ntn-try-me

Eliminate regular `try-catch-finally`

Usage no npm install needed!

<script type="module">
  import ntnTryMe from 'https://cdn.skypack.dev/ntn-try-me';
</script>

README

ntn-try-me

npm Minified MIT

try-me is a tiny utility.
try-me help Eliminate regular, tangled and heavy try-catch-finally.
With the aim to help you with error handling. You will be able to gain the following:

  • Less code
  • A more intelligent code
  • More flexibility
  • All in Typescript
  • With ESM \ ES Modules

Get ready

npm i ntn-try-me

unpkg.com/ntn-try-me/bundle/bundle

API

tryThat: The function you would like to try
meta: An optional object for configuration
    valid: An event if tryThat is passing
    fail: An event if tryThat failed
    finalize: An event when valid and fail are fulfill
    debugLevel: Might be in the future
    ifFailFireErr: If have an Error, Throw it Back
        fireErrUniqType: If ifFailFireErr true, it will fire only if the Error Type Equal fireErrUniqType
        fireErrData: If ifFailFireErr true, it will be the data Thrown Back

DEFAULT
tryThat: ✔️ Required
meta: ❌ Required, {}

Need an Example ?

import { tryMe } from 'ntn-try-me';

tryMe(() => { });
import { _try } from 'ntn-try-me'; // Lighter

_try(() => { });
import { tryMe } from 'ntn-try-me';

tryMe<MyErr>(() => Number['myFn'](), {
    valid: () => console.log('Great!'),
    fail: (e: MyErr) => console.log('Bummer...'),
    ifFailFireErr: true,
    fireErrUniqType: TypeError,
    finalize: () => console.log('We did it.')
});

In the future

  • Async
  • Fluent API