Socket
Socket
Sign inDemoInstall

makeerror

Package Overview
Dependencies
1
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.7 to 1.0.8

2

package.json
{
"name": "makeerror",
"description": "A library to make errors.",
"version": "1.0.7",
"version": "1.0.8",
"author": "Naitik Shah <n@daaku.org>",

@@ -6,0 +6,0 @@ "main": "lib/makeerror",

makeerror
=========
A library to make errors. Makes an Error constructor function with the
signature:
A library to make errors.
Basics
------
Makes an Error constructor function with the signature below. All arguments are
optional, and if the first argument is not a `String`, it will be assumed to be
`data`:
```javascript

@@ -25,7 +32,47 @@ function(message, data)

```javascript
er instanceof UnknownFileTypeError
er instanceof Error
er instanceof UnknownFileTypeError
```
You can also do `var er = new UnknownFileTypeError()` if you really like the
`new` keyword.
Templatized Error Messages
--------------------------
There is support for simple string substitutions like:
```javascript
var makeError = require('makeerror')
var UnknownFileTypeError = makeError(
'UnknownFileTypeError',
'The specified type "{type}" is not known.'
)
var er = UnknownFileTypeError({ type: 'bmp' })
```
Now `er.message` or `er.toString()` will return `'The specified type "bmp" is
not known.'`.
Prototype Hierarchies
---------------------
You can create simple hierarchies as well using the `prototype` chain:
```javascript
var makeError = require('makeerror')
var ParentError = makeError('ParentError')
var ChildError = makeError(
'ChildError',
'The child error.',
{ proto: ParentError() }
)
var er = ChildError()
```
`er` will have a prototype chain that ensures:
```javascript
er instanceof ChildError
er instanceof ParentError
er instanceof Error
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc