# create-error

> Simple helper for sub-classing the Error object

Latest version **0.3.1** (published 2013-12-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install create-error
pnpm add create-error
yarn add create-error
bun add create-error
```

## Health

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

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.1 |
| Published | 2013-12-19 |
| First published | 2013-12-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/create-error) |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 102 |
| Author | Tim Griesser |
| Maintainers | tgriesser |
| Keywords | errors |

## Links

- npm: https://www.npmjs.com/package/create-error
- Repository: https://github.com/tgriesser/create-error
- Issues: https://github.com/tgriesser/create-error/issues
- npm.io page: https://npm.io/package/create-error

## 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

- 0.3.1 (latest) — 2013-12-19
- 0.3.0 — 2013-12-17
- 0.2.1 — 2013-12-11
- 0.1.0 — 2013-12-03

## README

create-error.js
===============

A simple helper for creating subclassed errors in Javascript.

[![Build Status](https://travis-ci.org/tgriesser/create-error.png)](https://travis-ci.org/tgriesser/create-error)

## Use:

```bash
$ npm   install create-error
$ bower install create-error
```

```js
var createError    = require('create-error');

var MyCustomError  = createError('MyCustomError');
var SubCustomError = createError(MyCustomError, 'CoolSubError', {messages: []});

var sub = new SubCustomError('My Message', {someVal: 'value'});

sub instanceof SubCustomError // true
sub instanceof MyCustomError  // true
sub instanceof Error          // true

assert.deepEqual(sub.messages, []) // true
assert.equal(sub.someVal, 'value') // true
```

### createError(name, [properties])

Creates a new error by specifying the name of the error to be created,
taking an optional hash of properties to be attached to the error class
upon creation.

### createError(Target, [name, [properties]])

Create a new error by specifying the `Target` error class we wish to inherit from,
along with an optional name and properties for the error. If the `name` is omitted,
it will have the same name as the parent error.

### Additional Notes:

In the browser, the function will be assigned to `window.createError`,
and `createError.noConflict()` will restore the original `window.createError`
if overwritten.

### License

MIT

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