throw-error

Throws something if it’s an Error; otherwise returns it.

Usage no npm install needed!

<script type="module">
  import throwError from 'https://cdn.skypack.dev/throw-error';
</script>

README

throw-error

Throws something if it’s an Error; otherwise returns it.

Installation

Requires Node.js 6.0.0 or above.

npm i throw-error

API

The module exports a single function.

Parameter

x (any): A value which may or may not be an Error object.

Return Value

Returns x only if it isn’t an Error.

Example

const throwError = require('throw-error')

throwError('not an error') // 'not an error'
throwError(new Error()) // Uncaught Error