check-error 2.0.0 → 2.1.1
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 +3 -63
- package/index.js +15 -5
- package/package.json +9 -22
package/README.md
CHANGED
|
@@ -1,75 +1,15 @@
|
|
|
1
1
|
<h1 align=center>
|
|
2
2
|
<a href="http://chaijs.com" title="Chai Documentation">
|
|
3
|
-
<img alt="ChaiJS" src="http://chaijs.com/img/chai-logo.png"
|
|
3
|
+
<img alt="ChaiJS" src="http://chaijs.com/img/chai-logo.png">
|
|
4
4
|
</a>
|
|
5
|
+
<br>
|
|
6
|
+
check-error
|
|
5
7
|
</h1>
|
|
6
8
|
|
|
7
9
|
<p align=center>
|
|
8
10
|
Error comparison and information related utility for <a href="http://nodejs.org">node</a> and the browser.
|
|
9
11
|
</p>
|
|
10
12
|
|
|
11
|
-
<p align=center>
|
|
12
|
-
<a href="./LICENSE">
|
|
13
|
-
<img
|
|
14
|
-
alt="license:mit"
|
|
15
|
-
src="https://img.shields.io/badge/license-mit-green.svg?style=flat-square"
|
|
16
|
-
/>
|
|
17
|
-
</a>
|
|
18
|
-
<a href="https://github.com/chaijs/check-error/releases">
|
|
19
|
-
<img
|
|
20
|
-
alt="tag:?"
|
|
21
|
-
src="https://img.shields.io/github/tag/chaijs/check-error.svg?style=flat-square"
|
|
22
|
-
/>
|
|
23
|
-
</a>
|
|
24
|
-
|
|
25
|
-

|
|
26
|
-
|
|
27
|
-
<a href="https://coveralls.io/r/chaijs/check-error">
|
|
28
|
-
<img
|
|
29
|
-
alt="coverage:?"
|
|
30
|
-
src="https://img.shields.io/coveralls/chaijs/check-error/master.svg?style=flat-square"
|
|
31
|
-
/>
|
|
32
|
-
</a>
|
|
33
|
-
<a href="https://www.npmjs.com/packages/check-error">
|
|
34
|
-
<img
|
|
35
|
-
alt="npm:?"
|
|
36
|
-
src="https://img.shields.io/npm/v/check-error.svg?style=flat-square"
|
|
37
|
-
/>
|
|
38
|
-
</a>
|
|
39
|
-
<a href="https://www.npmjs.com/packages/check-error">
|
|
40
|
-
<img
|
|
41
|
-
alt="dependencies:?"
|
|
42
|
-
src="https://img.shields.io/npm/dm/check-error.svg?style=flat-square"
|
|
43
|
-
/>
|
|
44
|
-
</a>
|
|
45
|
-
<a href="">
|
|
46
|
-
<img
|
|
47
|
-
alt="devDependencies:?"
|
|
48
|
-
src="https://img.shields.io/david/chaijs/check-error.svg?style=flat-square"
|
|
49
|
-
/>
|
|
50
|
-
</a>
|
|
51
|
-
<br/>
|
|
52
|
-
<a href="https://saucelabs.com/u/chaijs-check-error">
|
|
53
|
-
<img
|
|
54
|
-
alt="Selenium Test Status"
|
|
55
|
-
src="https://saucelabs.com/browser-matrix/chaijs-check-error.svg"
|
|
56
|
-
/>
|
|
57
|
-
</a>
|
|
58
|
-
<br>
|
|
59
|
-
<a href="https://chai-slack.herokuapp.com/">
|
|
60
|
-
<img
|
|
61
|
-
alt="Join the Slack chat"
|
|
62
|
-
src="https://img.shields.io/badge/slack-join%20chat-E2206F.svg?style=flat-square"
|
|
63
|
-
/>
|
|
64
|
-
</a>
|
|
65
|
-
<a href="https://gitter.im/chaijs/chai">
|
|
66
|
-
<img
|
|
67
|
-
alt="Join the Gitter chat"
|
|
68
|
-
src="https://img.shields.io/badge/gitter-join%20chat-D0104D.svg?style=flat-square"
|
|
69
|
-
/>
|
|
70
|
-
</a>
|
|
71
|
-
</p>
|
|
72
|
-
|
|
73
13
|
## What is Check-Error?
|
|
74
14
|
|
|
75
15
|
Check-Error is a module which you can use to retrieve an Error's information such as its `message` or `constructor` name and also to check whether two Errors are compatible based on their messages, constructors or even instances.
|
package/index.js
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
function isErrorInstance(obj) {
|
|
2
|
+
// eslint-disable-next-line prefer-reflect
|
|
3
|
+
return obj instanceof Error || Object.prototype.toString.call(obj) === '[object Error]';
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
function isRegExp(obj) {
|
|
7
|
+
// eslint-disable-next-line prefer-reflect
|
|
8
|
+
return Object.prototype.toString.call(obj) === '[object RegExp]';
|
|
9
|
+
}
|
|
10
|
+
|
|
1
11
|
/**
|
|
2
12
|
* ### .compatibleInstance(thrown, errorLike)
|
|
3
13
|
*
|
|
@@ -13,7 +23,7 @@
|
|
|
13
23
|
*/
|
|
14
24
|
|
|
15
25
|
function compatibleInstance(thrown, errorLike) {
|
|
16
|
-
return errorLike
|
|
26
|
+
return isErrorInstance(errorLike) && thrown === errorLike;
|
|
17
27
|
}
|
|
18
28
|
|
|
19
29
|
/**
|
|
@@ -33,10 +43,10 @@ function compatibleInstance(thrown, errorLike) {
|
|
|
33
43
|
*/
|
|
34
44
|
|
|
35
45
|
function compatibleConstructor(thrown, errorLike) {
|
|
36
|
-
if (errorLike
|
|
46
|
+
if (isErrorInstance(errorLike)) {
|
|
37
47
|
// If `errorLike` is an instance of any error we compare their constructors
|
|
38
48
|
return thrown.constructor === errorLike.constructor || thrown instanceof errorLike.constructor;
|
|
39
|
-
} else if (errorLike
|
|
49
|
+
} else if ((typeof errorLike === 'object' || typeof errorLike === 'function') && errorLike.prototype) {
|
|
40
50
|
// If `errorLike` is a constructor that inherits from Error, we compare `thrown` to `errorLike` directly
|
|
41
51
|
return thrown.constructor === errorLike || thrown instanceof errorLike;
|
|
42
52
|
}
|
|
@@ -60,7 +70,7 @@ function compatibleConstructor(thrown, errorLike) {
|
|
|
60
70
|
|
|
61
71
|
function compatibleMessage(thrown, errMatcher) {
|
|
62
72
|
const comparisonString = typeof thrown === 'string' ? thrown : thrown.message;
|
|
63
|
-
if (errMatcher
|
|
73
|
+
if (isRegExp(errMatcher)) {
|
|
64
74
|
return errMatcher.test(comparisonString);
|
|
65
75
|
} else if (typeof errMatcher === 'string') {
|
|
66
76
|
return comparisonString.indexOf(errMatcher) !== -1; // eslint-disable-line no-magic-numbers
|
|
@@ -82,7 +92,7 @@ function compatibleMessage(thrown, errMatcher) {
|
|
|
82
92
|
|
|
83
93
|
function getConstructorName(errorLike) {
|
|
84
94
|
let constructorName = errorLike;
|
|
85
|
-
if (errorLike
|
|
95
|
+
if (isErrorInstance(errorLike)) {
|
|
86
96
|
constructorName = errorLike.constructor.name;
|
|
87
97
|
} else if (typeof errorLike === 'function') {
|
|
88
98
|
// If `err` is not an instance of Error it is an error constructor itself or another function.
|
package/package.json
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
{
|
|
2
|
+
"version": "2.1.1",
|
|
2
3
|
"name": "check-error",
|
|
3
4
|
"description": "Error comparison and information related utility for node and the browser",
|
|
4
|
-
"keywords": [
|
|
5
|
-
"check-error",
|
|
6
|
-
"error",
|
|
7
|
-
"chai util"
|
|
8
|
-
],
|
|
5
|
+
"keywords": ["check-error", "error", "chai util"],
|
|
9
6
|
"license": "MIT",
|
|
10
7
|
"author": "Jake Luer <jake@alogicalparadox.com> (http://alogicalparadox.com)",
|
|
11
8
|
"contributors": [
|
|
@@ -14,10 +11,7 @@
|
|
|
14
11
|
"Miroslav Bajtoš (https://github.com/bajtos)",
|
|
15
12
|
"Lucas Fernandes da Costa (https://github.com/lucasfcosta)"
|
|
16
13
|
],
|
|
17
|
-
"files": [
|
|
18
|
-
"index.js",
|
|
19
|
-
"check-error.js"
|
|
20
|
-
],
|
|
14
|
+
"files": ["index.js", "check-error.js"],
|
|
21
15
|
"type": "module",
|
|
22
16
|
"main": "./index.js",
|
|
23
17
|
"module": "./index.js",
|
|
@@ -26,13 +20,11 @@
|
|
|
26
20
|
"url": "git+ssh://git@github.com/chaijs/check-error.git"
|
|
27
21
|
},
|
|
28
22
|
"scripts": {
|
|
29
|
-
"build": "rollup -c rollup.config.js",
|
|
30
23
|
"lint": "eslint --ignore-path .gitignore index.js test/",
|
|
31
|
-
"prepublish": "npm run build",
|
|
32
24
|
"semantic-release": "semantic-release pre && npm publish && semantic-release post",
|
|
33
|
-
"pretest": "npm run lint
|
|
25
|
+
"pretest": "npm run lint",
|
|
34
26
|
"test": "npm run test:node && npm run test:browser",
|
|
35
|
-
"test:browser": "web-test-runner
|
|
27
|
+
"test:browser": "web-test-runner",
|
|
36
28
|
"test:node": "mocha"
|
|
37
29
|
},
|
|
38
30
|
"config": {
|
|
@@ -41,9 +33,7 @@
|
|
|
41
33
|
}
|
|
42
34
|
},
|
|
43
35
|
"eslintConfig": {
|
|
44
|
-
"extends": [
|
|
45
|
-
"strict/es6"
|
|
46
|
-
],
|
|
36
|
+
"extends": ["strict/es6"],
|
|
47
37
|
"env": {
|
|
48
38
|
"es6": true
|
|
49
39
|
},
|
|
@@ -53,12 +43,11 @@
|
|
|
53
43
|
"rules": {
|
|
54
44
|
"complexity": "off",
|
|
55
45
|
"max-statements": "off",
|
|
56
|
-
"prefer-arrow-callback": "off"
|
|
46
|
+
"prefer-arrow-callback": "off",
|
|
47
|
+
"prefer-reflect": "off"
|
|
57
48
|
}
|
|
58
49
|
},
|
|
59
50
|
"devDependencies": {
|
|
60
|
-
"@rollup/plugin-commonjs": "^21.0.0",
|
|
61
|
-
"@rollup/plugin-node-resolve": "^13.0.5",
|
|
62
51
|
"@web/test-runner": "^0.17.0",
|
|
63
52
|
"browserify": "^13.0.0",
|
|
64
53
|
"browserify-istanbul": "^1.0.0",
|
|
@@ -67,13 +56,11 @@
|
|
|
67
56
|
"eslint-plugin-filenames": "^0.2.0",
|
|
68
57
|
"ghooks": "^1.0.1",
|
|
69
58
|
"mocha": "^9.1.2",
|
|
70
|
-
"rollup": "^2.58.0",
|
|
71
59
|
"semantic-release": "^4.3.5",
|
|
72
60
|
"simple-assert": "^2.0.0",
|
|
73
61
|
"validate-commit-msg": "^2.3.1"
|
|
74
62
|
},
|
|
75
63
|
"engines": {
|
|
76
64
|
"node": ">= 16"
|
|
77
|
-
}
|
|
78
|
-
"version": "2.0.0"
|
|
65
|
+
}
|
|
79
66
|
}
|