Socket
Socket
Sign inDemoInstall

error-class

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

error-class - npm Package Compare versions

Comparing version 1.1.1 to 2.0.0

19

index.js

@@ -1,7 +0,9 @@

// Memoize these results, they're basically invariants.
'use strict'
var hasCaptureStackTrace = 'captureStackTrace' in Error
var hasSetPrototypeOf = 'setPrototypeOf' in Object
module.exports = errorClass
module.exports = function errorClass (name, fn) {
function errorClass (name) {
if (!name || typeof name !== 'string')

@@ -12,3 +14,3 @@ throw TypeError('Argument "name" must be a non-empty string.')

// function name.
var ErrorClass = Function('setupError', 'fn',
var ErrorClass = Function('setupError',
'return function ' + name + ' () { ' +

@@ -19,4 +21,3 @@ 'if (!(this instanceof ' + name + ')) ' +

'setupError.apply(this, arguments); ' +
(fn ? 'fn.apply(this, arguments); ' : '') +
'}')(setupError, fn)
'}')(setupError)

@@ -28,6 +29,2 @@ ErrorClass.prototype = Object.create(Error.prototype, {

// The `setPrototypeOf` method is part of ES6.
if (hasSetPrototypeOf) Object.setPrototypeOf(ErrorClass, Error)
else ErrorClass.__proto__ = Error
return ErrorClass

@@ -50,3 +47,3 @@ }

Object.defineProperty(this, 'message',
nonEnumerableProperty(message !== undefined ? '' + message : ''))
nonEnumerableProperty(message !== void 0 ? '' + message : ''))
}

@@ -53,0 +50,0 @@

{
"name": "error-class",
"description": "Typed errors that closely emulate the native Error class.",
"version": "1.1.1",
"version": "2.0.0",
"license": "MIT",

@@ -19,6 +19,6 @@ "author": {

"devDependencies": {
"eslint": "^1.3.1",
"eslint": "^1.9.0",
"eslint-config-0x8890": "^1.0.0",
"tap-dot": "^1.0.0",
"tapdance": "^3.0.6"
"tapdance": "^4.0.1"
},

@@ -33,2 +33,3 @@ "eslintConfig": {

"no-new-func": 0,
"strict": 0,
"vars-on-top": 0

@@ -42,3 +43,3 @@ }

"engines": {
"node": ">=0.10"
"node": ">=4.2.0"
},

@@ -45,0 +46,0 @@ "keywords": [

@@ -16,14 +16,11 @@ # Error Class

The default export is a function that accepts two arguments, the name of the typed error, and an optional function which gets invoked in the context of the error instance with the error arguments after the error setup is completed.
The default export is a function that accepts only one argument, the name of the typed error.
```js
import errorClass from 'error-class'
var errorClass = require('error-class')
const SpecialError = errorClass('SpecialError', function () {
if (arguments.length > 1) this.specialProperty = arguments[1]
})
var SpecialError = errorClass('SpecialError')
const instance = new SpecialError('baz', { foo: 'bar' })
instance.message // 'baz'
instance.specialProperty // { foo: 'bar' }
var instance = new SpecialError('foobar')
instance.message // 'foobar'
```

@@ -30,0 +27,0 @@

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc