Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

core-error-predicates

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

core-error-predicates - npm Package Compare versions

Comparing version 1.0.3 to 1.1.0

36

index.js

@@ -8,3 +8,3 @@ var errors = [];

name: name,
predicate: function(e) {
class: createClass(name, code, function(e) {
if (!e) return false;

@@ -18,4 +18,30 @@ if ("cause" in e && typeof e.cause.code === "string") {

}
})
});
}
function createClass(name, defaultCode, predicate) {
var CustomError = (new Function('name', 'defaultCode', 'predicate', [
'"use strict";',
'return function ' + name + '(message, code) {',
' if (this === undefined) return message instanceof ' + name + ' ? true : predicate(message);',
' Error.captureStackTrace(this, "' + name + '");',
' Error.call(this);',
' this.name = name;',
' this.message = message;',
' this.code = code === undefined ? defaultCode : code;',
'}'
].join('\n')))(name, defaultCode, predicate);
CustomError.prototype = Object.create(Error.prototype, {
constructor: {
value: CustomError,
enumerable: false,
writable: true,
configurable: true
}
});
Object.setPrototypeOf(CustomError, Error);
return CustomError;
}

@@ -50,3 +76,3 @@

name: "SSLError",
predicate: function(e) {
class: createClass("SSLError", ["SSLERROR"], function(e) {
var re = /^SSL Error:/;

@@ -61,3 +87,3 @@ if (!e) return false;

}
}
})
});

@@ -67,3 +93,3 @@

errors.forEach(function(error) {
module.exports[error.name] = error.predicate;
module.exports[error.name] = error.class;
});

@@ -74,3 +100,3 @@

if (global[error.name] === undefined) {
global[error.name] = error.predicate;
global[error.name] = error.class;
}

@@ -77,0 +103,0 @@ });

2

package.json
{
"name": "core-error-predicates",
"version": "1.0.3",
"version": "1.1.0",
"description": "Error predicate functions for operational errors thrown by node core",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -32,2 +32,13 @@ #Installation

Predicates can be turned into instances of their error types by using the `new` operator:
```js
try {
throw new FileNotFoundError("A file was not found!");
}
catch (e) {
assert(FileNotFoundError(e) === true);
}
```
##Error predicates

@@ -34,0 +45,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