check-error 1.0.2 → 2.0.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 +3 -6
- package/index.js +10 -57
- package/package.json +21 -27
- package/check-error.js +0 -176
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
src="https://img.shields.io/travis/chaijs/check-error/master.svg?style=flat-square"
|
|
28
|
-
/>
|
|
29
|
-
</a>
|
|
24
|
+
|
|
25
|
+

|
|
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,3 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/* !
|
|
4
|
-
* Chai - checkError utility
|
|
5
|
-
* Copyright(c) 2012-2016 Jake Luer <jake@alogicalparadox.com>
|
|
6
|
-
* MIT Licensed
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* ### .checkError
|
|
11
|
-
*
|
|
12
|
-
* Checks that an error conforms to a given set of criteria and/or retrieves information about it.
|
|
13
|
-
*
|
|
14
|
-
* @api public
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
1
|
/**
|
|
18
2
|
* ### .compatibleInstance(thrown, errorLike)
|
|
19
3
|
*
|
|
@@ -75,7 +59,7 @@ function compatibleConstructor(thrown, errorLike) {
|
|
|
75
59
|
*/
|
|
76
60
|
|
|
77
61
|
function compatibleMessage(thrown, errMatcher) {
|
|
78
|
-
|
|
62
|
+
const comparisonString = typeof thrown === 'string' ? thrown : thrown.message;
|
|
79
63
|
if (errMatcher instanceof RegExp) {
|
|
80
64
|
return errMatcher.test(comparisonString);
|
|
81
65
|
} else if (typeof errMatcher === 'string') {
|
|
@@ -85,34 +69,6 @@ function compatibleMessage(thrown, errMatcher) {
|
|
|
85
69
|
return false;
|
|
86
70
|
}
|
|
87
71
|
|
|
88
|
-
/**
|
|
89
|
-
* ### .getFunctionName(constructorFn)
|
|
90
|
-
*
|
|
91
|
-
* Returns the name of a function.
|
|
92
|
-
* This also includes a polyfill function if `constructorFn.name` is not defined.
|
|
93
|
-
*
|
|
94
|
-
* @name getFunctionName
|
|
95
|
-
* @param {Function} constructorFn
|
|
96
|
-
* @namespace Utils
|
|
97
|
-
* @api private
|
|
98
|
-
*/
|
|
99
|
-
|
|
100
|
-
var functionNameMatch = /\s*function(?:\s|\s*\/\*[^(?:*\/)]+\*\/\s*)*([^\(\/]+)/;
|
|
101
|
-
function getFunctionName(constructorFn) {
|
|
102
|
-
var name = '';
|
|
103
|
-
if (typeof constructorFn.name === 'undefined') {
|
|
104
|
-
// Here we run a polyfill if constructorFn.name is not defined
|
|
105
|
-
var match = String(constructorFn).match(functionNameMatch);
|
|
106
|
-
if (match) {
|
|
107
|
-
name = match[1];
|
|
108
|
-
}
|
|
109
|
-
} else {
|
|
110
|
-
name = constructorFn.name;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return name;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
72
|
/**
|
|
117
73
|
* ### .getConstructorName(errorLike)
|
|
118
74
|
*
|
|
@@ -125,15 +81,18 @@ function getFunctionName(constructorFn) {
|
|
|
125
81
|
*/
|
|
126
82
|
|
|
127
83
|
function getConstructorName(errorLike) {
|
|
128
|
-
|
|
84
|
+
let constructorName = errorLike;
|
|
129
85
|
if (errorLike instanceof Error) {
|
|
130
|
-
constructorName =
|
|
86
|
+
constructorName = errorLike.constructor.name;
|
|
131
87
|
} else if (typeof errorLike === 'function') {
|
|
132
88
|
// If `err` is not an instance of Error it is an error constructor itself or another function.
|
|
133
89
|
// If we've got a common function we get its name, otherwise we may need to create a new instance
|
|
134
90
|
// of the error just in case it's a poorly-constructed error. Please see chaijs/chai/issues/45 to know more.
|
|
135
|
-
constructorName =
|
|
136
|
-
|
|
91
|
+
constructorName = errorLike.name;
|
|
92
|
+
if (constructorName === '') {
|
|
93
|
+
const newConstructorName = (new errorLike().name); // eslint-disable-line new-cap
|
|
94
|
+
constructorName = newConstructorName || constructorName;
|
|
95
|
+
}
|
|
137
96
|
}
|
|
138
97
|
|
|
139
98
|
return constructorName;
|
|
@@ -153,7 +112,7 @@ function getConstructorName(errorLike) {
|
|
|
153
112
|
*/
|
|
154
113
|
|
|
155
114
|
function getMessage(errorLike) {
|
|
156
|
-
|
|
115
|
+
let msg = '';
|
|
157
116
|
if (errorLike && errorLike.message) {
|
|
158
117
|
msg = errorLike.message;
|
|
159
118
|
} else if (typeof errorLike === 'string') {
|
|
@@ -163,10 +122,4 @@ function getMessage(errorLike) {
|
|
|
163
122
|
return msg;
|
|
164
123
|
}
|
|
165
124
|
|
|
166
|
-
|
|
167
|
-
compatibleInstance: compatibleInstance,
|
|
168
|
-
compatibleConstructor: compatibleConstructor,
|
|
169
|
-
compatibleMessage: compatibleMessage,
|
|
170
|
-
getMessage: getMessage,
|
|
171
|
-
getConstructorName: getConstructorName,
|
|
172
|
-
};
|
|
125
|
+
export { compatibleInstance, compatibleConstructor, compatibleMessage, getMessage, getConstructorName };
|
package/package.json
CHANGED
|
@@ -18,21 +18,22 @@
|
|
|
18
18
|
"index.js",
|
|
19
19
|
"check-error.js"
|
|
20
20
|
],
|
|
21
|
+
"type": "module",
|
|
21
22
|
"main": "./index.js",
|
|
23
|
+
"module": "./index.js",
|
|
22
24
|
"repository": {
|
|
23
25
|
"type": "git",
|
|
24
26
|
"url": "git+ssh://git@github.com/chaijs/check-error.git"
|
|
25
27
|
},
|
|
26
28
|
"scripts": {
|
|
27
|
-
"build": "
|
|
28
|
-
"lint": "eslint --ignore-path .gitignore .",
|
|
29
|
+
"build": "rollup -c rollup.config.js",
|
|
30
|
+
"lint": "eslint --ignore-path .gitignore index.js test/",
|
|
29
31
|
"prepublish": "npm run build",
|
|
30
32
|
"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
|
|
33
|
-
"test:browser": "
|
|
34
|
-
"test:node": "
|
|
35
|
-
"upload-coverage": "lcov-result-merger 'coverage/**/lcov.info' | coveralls; exit 0"
|
|
33
|
+
"pretest": "npm run lint && npm run build",
|
|
34
|
+
"test": "npm run test:node && npm run test:browser",
|
|
35
|
+
"test:browser": "web-test-runner --node-resolve test/",
|
|
36
|
+
"test:node": "mocha"
|
|
36
37
|
},
|
|
37
38
|
"config": {
|
|
38
39
|
"ghooks": {
|
|
@@ -41,7 +42,7 @@
|
|
|
41
42
|
},
|
|
42
43
|
"eslintConfig": {
|
|
43
44
|
"extends": [
|
|
44
|
-
"strict/
|
|
45
|
+
"strict/es6"
|
|
45
46
|
],
|
|
46
47
|
"env": {
|
|
47
48
|
"es6": true
|
|
@@ -50,36 +51,29 @@
|
|
|
50
51
|
"HTMLElement": false
|
|
51
52
|
},
|
|
52
53
|
"rules": {
|
|
53
|
-
"complexity":
|
|
54
|
-
"max-statements":
|
|
54
|
+
"complexity": "off",
|
|
55
|
+
"max-statements": "off",
|
|
56
|
+
"prefer-arrow-callback": "off"
|
|
55
57
|
}
|
|
56
58
|
},
|
|
57
|
-
"dependencies": {},
|
|
58
59
|
"devDependencies": {
|
|
60
|
+
"@rollup/plugin-commonjs": "^21.0.0",
|
|
61
|
+
"@rollup/plugin-node-resolve": "^13.0.5",
|
|
62
|
+
"@web/test-runner": "^0.17.0",
|
|
59
63
|
"browserify": "^13.0.0",
|
|
60
64
|
"browserify-istanbul": "^1.0.0",
|
|
61
|
-
"coveralls": "2.11.9",
|
|
62
65
|
"eslint": "^2.4.0",
|
|
63
66
|
"eslint-config-strict": "^8.5.0",
|
|
64
67
|
"eslint-plugin-filenames": "^0.2.0",
|
|
65
68
|
"ghooks": "^1.0.1",
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"karma-browserify": "^5.0.2",
|
|
69
|
-
"karma-coverage": "^0.5.5",
|
|
70
|
-
"karma-mocha": "^0.2.2",
|
|
71
|
-
"karma-phantomjs-launcher": "^1.0.0",
|
|
72
|
-
"karma-sauce-launcher": "^0.3.1",
|
|
73
|
-
"lcov-result-merger": "^1.0.2",
|
|
74
|
-
"mocha": "^2.4.5",
|
|
75
|
-
"phantomjs-prebuilt": "^2.1.5",
|
|
69
|
+
"mocha": "^9.1.2",
|
|
70
|
+
"rollup": "^2.58.0",
|
|
76
71
|
"semantic-release": "^4.3.5",
|
|
77
|
-
"simple-assert": "^
|
|
78
|
-
"travis-after-all": "^1.4.4",
|
|
72
|
+
"simple-assert": "^2.0.0",
|
|
79
73
|
"validate-commit-msg": "^2.3.1"
|
|
80
74
|
},
|
|
81
75
|
"engines": {
|
|
82
|
-
"node": "
|
|
76
|
+
"node": ">= 16"
|
|
83
77
|
},
|
|
84
|
-
"version": "
|
|
85
|
-
}
|
|
78
|
+
"version": "2.0.0"
|
|
79
|
+
}
|
package/check-error.js
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.checkError = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
/* !
|
|
5
|
-
* Chai - checkError utility
|
|
6
|
-
* Copyright(c) 2012-2016 Jake Luer <jake@alogicalparadox.com>
|
|
7
|
-
* MIT Licensed
|
|
8
|
-
*/
|
|
9
|
-
|
|
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
|
-
*/
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* ### .compatibleInstance(thrown, errorLike)
|
|
20
|
-
*
|
|
21
|
-
* Checks if two instances are compatible (strict equal).
|
|
22
|
-
* Returns false if errorLike is not an instance of Error, because instances
|
|
23
|
-
* can only be compatible if they're both error instances.
|
|
24
|
-
*
|
|
25
|
-
* @name compatibleInstance
|
|
26
|
-
* @param {Error} thrown error
|
|
27
|
-
* @param {Error|ErrorConstructor} errorLike object to compare against
|
|
28
|
-
* @namespace Utils
|
|
29
|
-
* @api public
|
|
30
|
-
*/
|
|
31
|
-
|
|
32
|
-
function compatibleInstance(thrown, errorLike) {
|
|
33
|
-
return errorLike instanceof Error && thrown === errorLike;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* ### .compatibleConstructor(thrown, errorLike)
|
|
38
|
-
*
|
|
39
|
-
* Checks if two constructors are compatible.
|
|
40
|
-
* This function can receive either an error constructor or
|
|
41
|
-
* an error instance as the `errorLike` argument.
|
|
42
|
-
* Constructors are compatible if they're the same or if one is
|
|
43
|
-
* an instance of another.
|
|
44
|
-
*
|
|
45
|
-
* @name compatibleConstructor
|
|
46
|
-
* @param {Error} thrown error
|
|
47
|
-
* @param {Error|ErrorConstructor} errorLike object to compare against
|
|
48
|
-
* @namespace Utils
|
|
49
|
-
* @api public
|
|
50
|
-
*/
|
|
51
|
-
|
|
52
|
-
function compatibleConstructor(thrown, errorLike) {
|
|
53
|
-
if (errorLike instanceof Error) {
|
|
54
|
-
// If `errorLike` is an instance of any error we compare their constructors
|
|
55
|
-
return thrown.constructor === errorLike.constructor || thrown instanceof errorLike.constructor;
|
|
56
|
-
} else if (errorLike.prototype instanceof Error || errorLike === Error) {
|
|
57
|
-
// If `errorLike` is a constructor that inherits from Error, we compare `thrown` to `errorLike` directly
|
|
58
|
-
return thrown.constructor === errorLike || thrown instanceof errorLike;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* ### .compatibleMessage(thrown, errMatcher)
|
|
66
|
-
*
|
|
67
|
-
* Checks if an error's message is compatible with a matcher (String or RegExp).
|
|
68
|
-
* If the message contains the String or passes the RegExp test,
|
|
69
|
-
* it is considered compatible.
|
|
70
|
-
*
|
|
71
|
-
* @name compatibleMessage
|
|
72
|
-
* @param {Error} thrown error
|
|
73
|
-
* @param {String|RegExp} errMatcher to look for into the message
|
|
74
|
-
* @namespace Utils
|
|
75
|
-
* @api public
|
|
76
|
-
*/
|
|
77
|
-
|
|
78
|
-
function compatibleMessage(thrown, errMatcher) {
|
|
79
|
-
var comparisonString = typeof thrown === 'string' ? thrown : thrown.message;
|
|
80
|
-
if (errMatcher instanceof RegExp) {
|
|
81
|
-
return errMatcher.test(comparisonString);
|
|
82
|
-
} else if (typeof errMatcher === 'string') {
|
|
83
|
-
return comparisonString.indexOf(errMatcher) !== -1; // eslint-disable-line no-magic-numbers
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return false;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* ### .getFunctionName(constructorFn)
|
|
91
|
-
*
|
|
92
|
-
* Returns the name of a function.
|
|
93
|
-
* This also includes a polyfill function if `constructorFn.name` is not defined.
|
|
94
|
-
*
|
|
95
|
-
* @name getFunctionName
|
|
96
|
-
* @param {Function} constructorFn
|
|
97
|
-
* @namespace Utils
|
|
98
|
-
* @api private
|
|
99
|
-
*/
|
|
100
|
-
|
|
101
|
-
var functionNameMatch = /\s*function(?:\s|\s*\/\*[^(?:*\/)]+\*\/\s*)*([^\(\/]+)/;
|
|
102
|
-
function getFunctionName(constructorFn) {
|
|
103
|
-
var name = '';
|
|
104
|
-
if (typeof constructorFn.name === 'undefined') {
|
|
105
|
-
// Here we run a polyfill if constructorFn.name is not defined
|
|
106
|
-
var match = String(constructorFn).match(functionNameMatch);
|
|
107
|
-
if (match) {
|
|
108
|
-
name = match[1];
|
|
109
|
-
}
|
|
110
|
-
} else {
|
|
111
|
-
name = constructorFn.name;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return name;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* ### .getConstructorName(errorLike)
|
|
119
|
-
*
|
|
120
|
-
* Gets the constructor name for an Error instance or constructor itself.
|
|
121
|
-
*
|
|
122
|
-
* @name getConstructorName
|
|
123
|
-
* @param {Error|ErrorConstructor} errorLike
|
|
124
|
-
* @namespace Utils
|
|
125
|
-
* @api public
|
|
126
|
-
*/
|
|
127
|
-
|
|
128
|
-
function getConstructorName(errorLike) {
|
|
129
|
-
var constructorName = errorLike;
|
|
130
|
-
if (errorLike instanceof Error) {
|
|
131
|
-
constructorName = getFunctionName(errorLike.constructor);
|
|
132
|
-
} else if (typeof errorLike === 'function') {
|
|
133
|
-
// If `err` is not an instance of Error it is an error constructor itself or another function.
|
|
134
|
-
// If we've got a common function we get its name, otherwise we may need to create a new instance
|
|
135
|
-
// of the error just in case it's a poorly-constructed error. Please see chaijs/chai/issues/45 to know more.
|
|
136
|
-
constructorName = getFunctionName(errorLike).trim() ||
|
|
137
|
-
getFunctionName(new errorLike()); // eslint-disable-line new-cap
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
return constructorName;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* ### .getMessage(errorLike)
|
|
145
|
-
*
|
|
146
|
-
* Gets the error message from an error.
|
|
147
|
-
* If `err` is a String itself, we return it.
|
|
148
|
-
* If the error has no message, we return an empty string.
|
|
149
|
-
*
|
|
150
|
-
* @name getMessage
|
|
151
|
-
* @param {Error|String} errorLike
|
|
152
|
-
* @namespace Utils
|
|
153
|
-
* @api public
|
|
154
|
-
*/
|
|
155
|
-
|
|
156
|
-
function getMessage(errorLike) {
|
|
157
|
-
var msg = '';
|
|
158
|
-
if (errorLike && errorLike.message) {
|
|
159
|
-
msg = errorLike.message;
|
|
160
|
-
} else if (typeof errorLike === 'string') {
|
|
161
|
-
msg = errorLike;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
return msg;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
module.exports = {
|
|
168
|
-
compatibleInstance: compatibleInstance,
|
|
169
|
-
compatibleConstructor: compatibleConstructor,
|
|
170
|
-
compatibleMessage: compatibleMessage,
|
|
171
|
-
getMessage: getMessage,
|
|
172
|
-
getConstructorName: getConstructorName,
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
},{}]},{},[1])(1)
|
|
176
|
-
});
|