check-error 1.0.3 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -21,12 +21,9 @@
21
21
  src="https://img.shields.io/github/tag/chaijs/check-error.svg?style=flat-square"
22
22
  />
23
23
  </a>
24
- <a href="https://travis-ci.org/chaijs/check-error">
25
- <img
26
- alt="build:?"
27
- src="https://img.shields.io/travis/chaijs/check-error/master.svg?style=flat-square"
28
- />
29
- </a>
24
+
25
+ ![example workflow](https://github.com/chaijs/check-error/actions/workflows/nodejs.yml/badge.svg)
26
+
30
27
  <a href="https://coveralls.io/r/chaijs/check-error">
31
28
  <img
32
29
  alt="coverage:?"
package/index.js CHANGED
@@ -1,19 +1,16 @@
1
- 'use strict';
1
+ function isErrorInstance(obj) {
2
+ // eslint-disable-next-line prefer-reflect
3
+ return obj instanceof Error || Object.prototype.toString.call(obj) === '[object Error]';
4
+ }
2
5
 
3
- /* !
4
- * Chai - checkError utility
5
- * Copyright(c) 2012-2016 Jake Luer <jake@alogicalparadox.com>
6
- * MIT Licensed
7
- */
6
+ function isErrorClass(obj) {
7
+ return obj === Error || (typeof obj === 'function' && obj.name === 'Error');
8
+ }
8
9
 
9
- var getFunctionName = require('get-func-name');
10
- /**
11
- * ### .checkError
12
- *
13
- * Checks that an error conforms to a given set of criteria and/or retrieves information about it.
14
- *
15
- * @api public
16
- */
10
+ function isRegExp(obj) {
11
+ // eslint-disable-next-line prefer-reflect
12
+ return Object.prototype.toString.call(obj) === '[object RegExp]';
13
+ }
17
14
 
18
15
  /**
19
16
  * ### .compatibleInstance(thrown, errorLike)
@@ -30,7 +27,7 @@ var getFunctionName = require('get-func-name');
30
27
  */
31
28
 
32
29
  function compatibleInstance(thrown, errorLike) {
33
- return errorLike instanceof Error && thrown === errorLike;
30
+ return isErrorInstance(errorLike) && thrown === errorLike;
34
31
  }
35
32
 
36
33
  /**
@@ -50,10 +47,10 @@ function compatibleInstance(thrown, errorLike) {
50
47
  */
51
48
 
52
49
  function compatibleConstructor(thrown, errorLike) {
53
- if (errorLike instanceof Error) {
50
+ if (isErrorInstance(errorLike)) {
54
51
  // If `errorLike` is an instance of any error we compare their constructors
55
52
  return thrown.constructor === errorLike.constructor || thrown instanceof errorLike.constructor;
56
- } else if (errorLike.prototype instanceof Error || errorLike === Error) {
53
+ } else if (isErrorClass(Object.getPrototypeOf(errorLike)) || isErrorClass(errorLike)) {
57
54
  // If `errorLike` is a constructor that inherits from Error, we compare `thrown` to `errorLike` directly
58
55
  return thrown.constructor === errorLike || thrown instanceof errorLike;
59
56
  }
@@ -76,8 +73,8 @@ function compatibleConstructor(thrown, errorLike) {
76
73
  */
77
74
 
78
75
  function compatibleMessage(thrown, errMatcher) {
79
- var comparisonString = typeof thrown === 'string' ? thrown : thrown.message;
80
- if (errMatcher instanceof RegExp) {
76
+ const comparisonString = typeof thrown === 'string' ? thrown : thrown.message;
77
+ if (isRegExp(errMatcher)) {
81
78
  return errMatcher.test(comparisonString);
82
79
  } else if (typeof errMatcher === 'string') {
83
80
  return comparisonString.indexOf(errMatcher) !== -1; // eslint-disable-line no-magic-numbers
@@ -98,16 +95,16 @@ function compatibleMessage(thrown, errMatcher) {
98
95
  */
99
96
 
100
97
  function getConstructorName(errorLike) {
101
- var constructorName = errorLike;
102
- if (errorLike instanceof Error) {
103
- constructorName = getFunctionName(errorLike.constructor);
98
+ let constructorName = errorLike;
99
+ if (isErrorInstance(errorLike)) {
100
+ constructorName = errorLike.constructor.name;
104
101
  } else if (typeof errorLike === 'function') {
105
102
  // If `err` is not an instance of Error it is an error constructor itself or another function.
106
103
  // If we've got a common function we get its name, otherwise we may need to create a new instance
107
104
  // of the error just in case it's a poorly-constructed error. Please see chaijs/chai/issues/45 to know more.
108
- constructorName = getFunctionName(errorLike);
105
+ constructorName = errorLike.name;
109
106
  if (constructorName === '') {
110
- var newConstructorName = getFunctionName(new errorLike()); // eslint-disable-line new-cap
107
+ const newConstructorName = (new errorLike().name); // eslint-disable-line new-cap
111
108
  constructorName = newConstructorName || constructorName;
112
109
  }
113
110
  }
@@ -129,7 +126,7 @@ function getConstructorName(errorLike) {
129
126
  */
130
127
 
131
128
  function getMessage(errorLike) {
132
- var msg = '';
129
+ let msg = '';
133
130
  if (errorLike && errorLike.message) {
134
131
  msg = errorLike.message;
135
132
  } else if (typeof errorLike === 'string') {
@@ -139,10 +136,4 @@ function getMessage(errorLike) {
139
136
  return msg;
140
137
  }
141
138
 
142
- module.exports = {
143
- compatibleInstance: compatibleInstance,
144
- compatibleConstructor: compatibleConstructor,
145
- compatibleMessage: compatibleMessage,
146
- getMessage: getMessage,
147
- getConstructorName: getConstructorName,
148
- };
139
+ export { compatibleInstance, compatibleConstructor, compatibleMessage, getMessage, getConstructorName };
package/package.json CHANGED
@@ -1,4 +1,5 @@
1
1
  {
2
+ "version": "2.1.0",
2
3
  "name": "check-error",
3
4
  "description": "Error comparison and information related utility for node and the browser",
4
5
  "keywords": [
@@ -18,21 +19,22 @@
18
19
  "index.js",
19
20
  "check-error.js"
20
21
  ],
22
+ "type": "module",
21
23
  "main": "./index.js",
24
+ "module": "./index.js",
22
25
  "repository": {
23
26
  "type": "git",
24
27
  "url": "git+ssh://git@github.com/chaijs/check-error.git"
25
28
  },
26
29
  "scripts": {
27
- "build": "browserify --bare $npm_package_main --standalone checkError -o check-error.js",
28
- "lint": "eslint --ignore-path .gitignore .",
30
+ "build": "rollup -c rollup.config.js",
31
+ "lint": "eslint --ignore-path .gitignore index.js test/",
29
32
  "prepublish": "npm run build",
30
33
  "semantic-release": "semantic-release pre && npm publish && semantic-release post",
31
- "pretest": "npm run lint",
32
- "test": "npm run test:node && npm run test:browser && npm run upload-coverage",
33
- "test:browser": "karma start --singleRun=true",
34
- "test:node": "istanbul cover _mocha",
35
- "upload-coverage": "lcov-result-merger 'coverage/**/lcov.info' | coveralls; exit 0"
34
+ "pretest": "npm run lint && npm run build",
35
+ "test": "npm run test:node && npm run test:browser",
36
+ "test:browser": "web-test-runner",
37
+ "test:node": "mocha"
36
38
  },
37
39
  "config": {
38
40
  "ghooks": {
@@ -41,7 +43,7 @@
41
43
  },
42
44
  "eslintConfig": {
43
45
  "extends": [
44
- "strict/es5"
46
+ "strict/es6"
45
47
  ],
46
48
  "env": {
47
49
  "es6": true
@@ -50,38 +52,29 @@
50
52
  "HTMLElement": false
51
53
  },
52
54
  "rules": {
53
- "complexity": 0,
54
- "max-statements": 0
55
+ "complexity": "off",
56
+ "max-statements": "off",
57
+ "prefer-arrow-callback": "off",
58
+ "prefer-reflect": "off"
55
59
  }
56
60
  },
57
- "dependencies": {
58
- "get-func-name": "^2.0.2"
59
- },
60
61
  "devDependencies": {
62
+ "@rollup/plugin-commonjs": "^21.0.0",
63
+ "@rollup/plugin-node-resolve": "^13.0.5",
64
+ "@web/test-runner": "^0.17.0",
61
65
  "browserify": "^13.0.0",
62
66
  "browserify-istanbul": "^1.0.0",
63
- "coveralls": "2.11.9",
64
67
  "eslint": "^2.4.0",
65
68
  "eslint-config-strict": "^8.5.0",
66
69
  "eslint-plugin-filenames": "^0.2.0",
67
70
  "ghooks": "^1.0.1",
68
- "istanbul": "^0.4.2",
69
- "karma": "^0.13.22",
70
- "karma-browserify": "^5.0.2",
71
- "karma-coverage": "^0.5.5",
72
- "karma-mocha": "^0.2.2",
73
- "karma-phantomjs-launcher": "^1.0.0",
74
- "karma-sauce-launcher": "^0.3.1",
75
- "lcov-result-merger": "^1.0.2",
76
- "mocha": "^2.4.5",
77
- "phantomjs-prebuilt": "^2.1.5",
71
+ "mocha": "^9.1.2",
72
+ "rollup": "^2.58.0",
78
73
  "semantic-release": "^4.3.5",
79
- "simple-assert": "^1.0.0",
80
- "travis-after-all": "^1.4.4",
74
+ "simple-assert": "^2.0.0",
81
75
  "validate-commit-msg": "^2.3.1"
82
76
  },
83
77
  "engines": {
84
- "node": "*"
85
- },
86
- "version": "1.0.3"
78
+ "node": ">= 16"
79
+ }
87
80
  }
package/check-error.js DELETED
@@ -1 +0,0 @@
1
- (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({},{},[])