A package that provides a single function:
function throw_(thing: any): never
If thing
is a function, throw thing()
is executed,
otherwise throw thing
is executed.
That's it.
Run this in a terminal window:
npm run build
Using ES6 modules:
import { throw_ } from "@thepeoplescoder/throw_";
Using CommonJS:
const { throw_ } = require("@thepeoplescoder/throw_");
Afterwards, you can do things along the lines of this:
expression = isErrorCondition
? throw_(anErrorObjectOrAFunctionThatReturnsSomethingThrowable)
: intendedValueOfExpression;