@toruslabs/metadata-helpers
Version:
Helper methods for metadata
23 lines (21 loc) • 722 B
JavaScript
/**
* Same as Node.js assert.
* If the value is falsy, throws an error, does nothing otherwise.
*
* @throws {@link AssertionError} If value is falsy.
* @param value - The test that should be truthy to pass.
* @param message - Message to be passed to {@link AssertionError} or an
* {@link Error} instance to throw.
* @param ErrorWrapper - The error class to throw if the assertion fails.
* Defaults to {@link AssertionError}. If a custom error class is provided for
* the `message` argument, this argument is ignored.
*/
function assert(value, message = "Assertion failed.") {
if (!value) {
if (message instanceof Error) {
throw message;
}
throw new Error(message);
}
}
export { assert };