check-error 2.1.1 → 2.1.3

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.
Files changed (3) hide show
  1. package/README.md +20 -20
  2. package/index.js +5 -4
  3. package/package.json +17 -37
package/README.md CHANGED
@@ -41,16 +41,16 @@ The primary export of `check-error` is an object which has the following methods
41
41
  * `getMessage(err)` - Retrieves the message of an error or `err` itself if it's a String. If `err` or `err.message` is undefined we return an empty String.
42
42
 
43
43
  ```js
44
- var checkError = require('check-error');
44
+ import * as checkError 'check-error';
45
45
  ```
46
46
 
47
47
  #### .compatibleInstance(err, errorLike)
48
48
 
49
49
  ```js
50
- var checkError = require('check-error');
50
+ import * as checkError 'check-error';
51
51
 
52
- var funcThatThrows = function() { throw new TypeError('I am a TypeError') };
53
- var caughtErr;
52
+ const funcThatThrows = function() { throw new TypeError('I am a TypeError') };
53
+ let caughtErr;
54
54
 
55
55
  try {
56
56
  funcThatThrows();
@@ -58,7 +58,7 @@ try {
58
58
  caughtErr = e;
59
59
  }
60
60
 
61
- var sameInstance = caughtErr;
61
+ const sameInstance = caughtErr;
62
62
 
63
63
  checkError.compatibleInstance(caughtErr, sameInstance); // true
64
64
  checkError.compatibleInstance(caughtErr, new TypeError('Another error')); // false
@@ -67,10 +67,10 @@ checkError.compatibleInstance(caughtErr, new TypeError('Another error')); // fal
67
67
  #### .compatibleConstructor(err, errorLike)
68
68
 
69
69
  ```js
70
- var checkError = require('check-error');
70
+ import * as checkError 'check-error';
71
71
 
72
- var funcThatThrows = function() { throw new TypeError('I am a TypeError') };
73
- var caughtErr;
72
+ const funcThatThrows = function() { throw new TypeError('I am a TypeError') };
73
+ let caughtErr;
74
74
 
75
75
  try {
76
76
  funcThatThrows();
@@ -86,10 +86,10 @@ checkError.compatibleConstructor(caughtErr, RangeError); // false
86
86
  #### .compatibleMessage(err, errMatcher)
87
87
 
88
88
  ```js
89
- var checkError = require('check-error');
89
+ import * as checkError 'check-error';
90
90
 
91
- var funcThatThrows = function() { throw new TypeError('I am a TypeError') };
92
- var caughtErr;
91
+ const funcThatThrows = function() { throw new TypeError('I am a TypeError') };
92
+ let caughtErr;
93
93
 
94
94
  try {
95
95
  funcThatThrows();
@@ -97,7 +97,7 @@ try {
97
97
  caughtErr = e;
98
98
  }
99
99
 
100
- var sameInstance = caughtErr;
100
+ const sameInstance = caughtErr;
101
101
 
102
102
  checkError.compatibleMessage(caughtErr, /TypeError$/); // true
103
103
  checkError.compatibleMessage(caughtErr, 'I am a'); // true
@@ -108,10 +108,10 @@ checkError.compatibleMessage(caughtErr, 'I do not exist'); // false
108
108
  #### .getConstructorName(errorLike)
109
109
 
110
110
  ```js
111
- var checkError = require('check-error');
111
+ import * as checkError 'check-error';
112
112
 
113
- var funcThatThrows = function() { throw new TypeError('I am a TypeError') };
114
- var caughtErr;
113
+ const funcThatThrows = function() { throw new TypeError('I am a TypeError') };
114
+ let caughtErr;
115
115
 
116
116
  try {
117
117
  funcThatThrows();
@@ -119,7 +119,7 @@ try {
119
119
  caughtErr = e;
120
120
  }
121
121
 
122
- var sameInstance = caughtErr;
122
+ const sameInstance = caughtErr;
123
123
 
124
124
  checkError.getConstructorName(caughtErr) // 'TypeError'
125
125
  ```
@@ -127,10 +127,10 @@ checkError.getConstructorName(caughtErr) // 'TypeError'
127
127
  #### .getMessage(err)
128
128
 
129
129
  ```js
130
- var checkError = require('check-error');
130
+ import * as checkError 'check-error';
131
131
 
132
- var funcThatThrows = function() { throw new TypeError('I am a TypeError') };
133
- var caughtErr;
132
+ const funcThatThrows = function() { throw new TypeError('I am a TypeError') };
133
+ let caughtErr;
134
134
 
135
135
  try {
136
136
  funcThatThrows();
@@ -138,7 +138,7 @@ try {
138
138
  caughtErr = e;
139
139
  }
140
140
 
141
- var sameInstance = caughtErr;
141
+ const sameInstance = caughtErr;
142
142
 
143
143
  checkError.getMessage(caughtErr) // 'I am a TypeError'
144
144
  ```
package/index.js CHANGED
@@ -1,10 +1,8 @@
1
1
  function isErrorInstance(obj) {
2
- // eslint-disable-next-line prefer-reflect
3
2
  return obj instanceof Error || Object.prototype.toString.call(obj) === '[object Error]';
4
3
  }
5
4
 
6
5
  function isRegExp(obj) {
7
- // eslint-disable-next-line prefer-reflect
8
6
  return Object.prototype.toString.call(obj) === '[object RegExp]';
9
7
  }
10
8
 
@@ -70,10 +68,13 @@ function compatibleConstructor(thrown, errorLike) {
70
68
 
71
69
  function compatibleMessage(thrown, errMatcher) {
72
70
  const comparisonString = typeof thrown === 'string' ? thrown : thrown.message;
71
+ if (comparisonString === undefined) {
72
+ return false;
73
+ }
73
74
  if (isRegExp(errMatcher)) {
74
75
  return errMatcher.test(comparisonString);
75
76
  } else if (typeof errMatcher === 'string') {
76
- return comparisonString.indexOf(errMatcher) !== -1; // eslint-disable-line no-magic-numbers
77
+ return comparisonString.indexOf(errMatcher) !== -1;
77
78
  }
78
79
 
79
80
  return false;
@@ -100,7 +101,7 @@ function getConstructorName(errorLike) {
100
101
  // of the error just in case it's a poorly-constructed error. Please see chaijs/chai/issues/45 to know more.
101
102
  constructorName = errorLike.name;
102
103
  if (constructorName === '') {
103
- const newConstructorName = (new errorLike().name); // eslint-disable-line new-cap
104
+ const newConstructorName = (new errorLike().name);
104
105
  constructorName = newConstructorName || constructorName;
105
106
  }
106
107
  }
package/package.json CHANGED
@@ -1,8 +1,11 @@
1
1
  {
2
- "version": "2.1.1",
3
2
  "name": "check-error",
4
3
  "description": "Error comparison and information related utility for node and the browser",
5
- "keywords": ["check-error", "error", "chai util"],
4
+ "keywords": [
5
+ "check-error",
6
+ "error",
7
+ "chai util"
8
+ ],
6
9
  "license": "MIT",
7
10
  "author": "Jake Luer <jake@alogicalparadox.com> (http://alogicalparadox.com)",
8
11
  "contributors": [
@@ -11,7 +14,10 @@
11
14
  "Miroslav Bajtoš (https://github.com/bajtos)",
12
15
  "Lucas Fernandes da Costa (https://github.com/lucasfcosta)"
13
16
  ],
14
- "files": ["index.js", "check-error.js"],
17
+ "files": [
18
+ "index.js",
19
+ "check-error.js"
20
+ ],
15
21
  "type": "module",
16
22
  "main": "./index.js",
17
23
  "module": "./index.js",
@@ -20,47 +26,21 @@
20
26
  "url": "git+ssh://git@github.com/chaijs/check-error.git"
21
27
  },
22
28
  "scripts": {
23
- "lint": "eslint --ignore-path .gitignore index.js test/",
24
- "semantic-release": "semantic-release pre && npm publish && semantic-release post",
29
+ "lint": "eslint index.js test/",
25
30
  "pretest": "npm run lint",
26
31
  "test": "npm run test:node && npm run test:browser",
27
32
  "test:browser": "web-test-runner",
28
33
  "test:node": "mocha"
29
34
  },
30
- "config": {
31
- "ghooks": {
32
- "commit-msg": "validate-commit-msg"
33
- }
34
- },
35
- "eslintConfig": {
36
- "extends": ["strict/es6"],
37
- "env": {
38
- "es6": true
39
- },
40
- "globals": {
41
- "HTMLElement": false
42
- },
43
- "rules": {
44
- "complexity": "off",
45
- "max-statements": "off",
46
- "prefer-arrow-callback": "off",
47
- "prefer-reflect": "off"
48
- }
49
- },
50
35
  "devDependencies": {
51
- "@web/test-runner": "^0.17.0",
52
- "browserify": "^13.0.0",
53
- "browserify-istanbul": "^1.0.0",
54
- "eslint": "^2.4.0",
55
- "eslint-config-strict": "^8.5.0",
56
- "eslint-plugin-filenames": "^0.2.0",
57
- "ghooks": "^1.0.1",
58
- "mocha": "^9.1.2",
59
- "semantic-release": "^4.3.5",
60
- "simple-assert": "^2.0.0",
61
- "validate-commit-msg": "^2.3.1"
36
+ "@eslint/js": "^9.31.0",
37
+ "@web/test-runner": "^0.20.2",
38
+ "eslint": "^9.31.0",
39
+ "mocha": "^11.7.1",
40
+ "simple-assert": "^2.0.0"
62
41
  },
63
42
  "engines": {
64
43
  "node": ">= 16"
65
- }
44
+ },
45
+ "version": "2.1.3"
66
46
  }