nitroglycerindeprecated

Makes JavaScript functions throw exceptions on errors

Usage no npm install needed!

<script type="module">
  import nitroglycerin from 'https://cdn.skypack.dev/nitroglycerin';
</script>

README

Nitroglycerin

Circle CI Dependency Status Coverage Status

Makes JavaScript functions so volatile and explosive that they immediately throw on errors.

This is mostly useful for testing and simple command-line scripts. In production you most likely don't want to throw exceptions.

How it works

Let's say you have a small piece of test code that needs to set something up:

resetDatabase (err) ->
  if err then throw new Error(err)
  createUser name: 'Alfred Nobel', (err, alfred) ->
    if err then throw new Error(err)
    # run your tests using alfred here

Checking that these calls didn't error out requires a bit of ceremony in Node.js, either in the form of manual error checking as described above, promises, or async.waterfall. Nitroglycerin removes most of this ceremony:

N = require 'nitroglycerin'

resetDatabase N ->
  createUser name: 'Alfred Nobel', N (alfred) ->
    # run your tests using alfred here

The functions wrapped in Nitroglycerin will immediately throw an exception when they receive an error or execute the callback with the error argument stripped.

Development

See the developer documentation