# errate

> Converts a value into an Error of the specified type.

Latest version **1.3.0** (published 2019-10-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install errate
pnpm add errate
yarn add errate
bun add errate
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.0 |
| Published | 2019-10-12 |
| First published | 2018-04-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6.0.0 |
| Dependencies | 4 |
| Unpacked size | 4.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Fr. John Lamansky |
| Maintainers | lamansky |
| Keywords | convert, error |

## Links

- npm: https://www.npmjs.com/package/errate
- Repository: https://github.com/lamansky/errate
- Homepage: https://github.com/lamansky/errate#readme
- Issues: https://github.com/lamansky/errate/issues
- npm.io page: https://npm.io/package/errate

## Dependencies (4)

- [copy-own](https://npm.io/package/copy-own.md) ^1.2.0
- [trim-call](https://npm.io/package/trim-call.md) ^1.1.0
- [is-class-of](https://npm.io/package/is-class-of.md) ^1.0.1
- [is-instance-of](https://npm.io/package/is-instance-of.md) ^1.0.2

## Alternatives

- [@sentry/react-native](https://npm.io/package/@sentry/react-native.md) — 2.6M weekly downloads
- [@ardatan/aggregate-error](https://npm.io/package/@ardatan/aggregate-error.md) — 708.1K weekly downloads
- [custom-error-generator](https://npm.io/package/custom-error-generator.md) — 2.0K weekly downloads
- [@technik-sde/prosemirror-recreate-transform](https://npm.io/package/@technik-sde/prosemirror-recreate-transform.md) — 1.5K weekly downloads
- [@suchipi/error-utils](https://npm.io/package/@suchipi/error-utils.md) — 78 weekly downloads

## Recent versions

- 1.3.0 (latest) — 2019-10-12
- 1.2.0 — 2018-08-18
- 1.1.0 — 2018-08-17
- 1.0.0 — 2018-04-11

## README

# errate

Converts a value into an Error of the specified type.

## Installation

Requires [Node.js](https://nodejs.org/) 6.0.0 or above.

```bash
npm i errate
```

## API

The module exports a single function.

### Parameters

1. Optional: `e` (string, Error object, boolean, or null): The error message, or an existing Error object. If `null` or a boolean, the returned Error will have no message.
2. Optional: `Cls` (Error class): The desired class of the returned Error (such as `TypeError` or `RangeError`). Defaults to `Error`.
3. Optional: Object argument:
    * `defaultMessage` (string): The first argument that will be provided to the constructor if an Error object is being created (i.e. if `e` is `true` or “falsey”).
    * `forceClass` (boolean): If set to `true`, instances of other `Error` classes will be converted to instances of `Cls`. If set to `false`, `Cls` will only be used to wrap string errors. Defaults to `true`.

### Return Value

An Error of the specified class.

## Examples

### Default Class With Message

```javascript
const errate = require('errate')

const err = errate('Message')
err instanceof Error // true
err.message // 'Message'
```

### Default Class Without Message

```javascript
const errate = require('errate')

const err = errate()
err instanceof Error // true
err.message // ''
```

### Error Subclass With Message

```javascript
const errate = require('errate')

const err = errate('Message', TypeError)
err instanceof TypeError // true
err.message // 'Message'
```

### Error Subclass Without Message

```javascript
const errate = require('errate')

const err = errate(TypeError)
err instanceof TypeError // true
err.message // ''
```

### Error Class Conversion

```javascript
const errate = require('errate')

const err = errate(new TypeError('Message'), RangeError)
err instanceof RangeError // true
err.message // 'Message'
```

---
_Source: https://npm.io/package/errate · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
