1.0.0 • Published 5 years ago

reror v1.0.0

Weekly downloads
4
License
MIT
Repository
github
Last release
5 years ago

reror Build Status

The functional, and proper, way to throw errors.

Install

Use npm:

npm i reror

Usage

var reror = require('reror');
reror(new Error('abc')); // → throws an Error: abc
reror('abc'); // ↑ same
reror.lateThrow(new Error('abc'))(); // ↑ same
reror.lateThrow('abc'); // ↑ same

Why is this useful?

Well, you could just do this:

const func = (requiredArg = throw new Error('Argument not provided')) => {};

Oh, wait... that's a syntax error! Try this instead:

// E is short, and it goes against the naming scheme, so there shouldn't be any naming conflicts.
const E = require('reror');
const func = (requiredArg = E('Argument not provided')) => {};

Or even better:

const missingArgError = reror.lateThrow('Argument not provided');
const func = (requiredArg = missingArgError()) => {};

API

reror(error)

Throws the Error.

error

Type: Error | string

The error to be thrown.

reror.lateThrow(error)

Returns a function that throws the error.

error

Type: Error | string

The error to be thrown.

What does the name mean?

It's an anagram of "error". The obvious names were taken up with placeholders, so this was the obvious choice :).

License

This project is licensed under the MIT license. A copy of this license can be found in the license file.

MIT @ Will Hoskings (resynth1943)