Socket
Socket
Sign inDemoInstall

check-error

Package Overview
Dependencies
0
Maintainers
2
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.0 to 2.1.0

24

index.js

@@ -0,1 +1,15 @@

function isErrorInstance(obj) {
// eslint-disable-next-line prefer-reflect
return obj instanceof Error || Object.prototype.toString.call(obj) === '[object Error]';
}
function isErrorClass(obj) {
return obj === Error || (typeof obj === 'function' && obj.name === 'Error');
}
function isRegExp(obj) {
// eslint-disable-next-line prefer-reflect
return Object.prototype.toString.call(obj) === '[object RegExp]';
}
/**

@@ -16,3 +30,3 @@ * ### .compatibleInstance(thrown, errorLike)

function compatibleInstance(thrown, errorLike) {
return errorLike instanceof Error && thrown === errorLike;
return isErrorInstance(errorLike) && thrown === errorLike;
}

@@ -37,6 +51,6 @@

function compatibleConstructor(thrown, errorLike) {
if (errorLike instanceof Error) {
if (isErrorInstance(errorLike)) {
// If `errorLike` is an instance of any error we compare their constructors
return thrown.constructor === errorLike.constructor || thrown instanceof errorLike.constructor;
} else if (errorLike.prototype instanceof Error || errorLike === Error) {
} else if (isErrorClass(Object.getPrototypeOf(errorLike)) || isErrorClass(errorLike)) {
// If `errorLike` is a constructor that inherits from Error, we compare `thrown` to `errorLike` directly

@@ -65,3 +79,3 @@ return thrown.constructor === errorLike || thrown instanceof errorLike;

const comparisonString = typeof thrown === 'string' ? thrown : thrown.message;
if (errMatcher instanceof RegExp) {
if (isRegExp(errMatcher)) {
return errMatcher.test(comparisonString);

@@ -88,3 +102,3 @@ } else if (typeof errMatcher === 'string') {

let constructorName = errorLike;
if (errorLike instanceof Error) {
if (isErrorInstance(errorLike)) {
constructorName = errorLike.constructor.name;

@@ -91,0 +105,0 @@ } else if (typeof errorLike === 'function') {

{
"version": "2.1.0",
"name": "check-error",

@@ -35,3 +36,3 @@ "description": "Error comparison and information related utility for node and the browser",

"test": "npm run test:node && npm run test:browser",
"test:browser": "web-test-runner --node-resolve test/",
"test:browser": "web-test-runner",
"test:node": "mocha"

@@ -57,3 +58,4 @@ },

"max-statements": "off",
"prefer-arrow-callback": "off"
"prefer-arrow-callback": "off",
"prefer-reflect": "off"
}

@@ -79,4 +81,3 @@ },

"node": ">= 16"
},
"version": "2.0.0"
}
}
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