check-error 1.0.1 → 1.0.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.
package/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  </h1>
6
6
 
7
7
  <p align=center>
8
- Error comparison and information related utility for [node](http://nodejs.org) and the browser.
8
+ Error comparison and information related utility for <a href="http://nodejs.org">node</a> and the browser.
9
9
  </p>
10
10
 
11
11
  <p align=center>
@@ -104,13 +104,13 @@ The primary export of `check-error` is an object which has the following methods
104
104
  * `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.
105
105
 
106
106
  ```js
107
- var checkError = require('checkError');
107
+ var checkError = require('check-error');
108
108
  ```
109
109
 
110
110
  #### .compatibleInstance(err, errorLike)
111
111
 
112
112
  ```js
113
- var checkError = require('checkError');
113
+ var checkError = require('check-error');
114
114
 
115
115
  var funcThatThrows = function() { throw new TypeError('I am a TypeError') };
116
116
  var caughtErr;
@@ -130,7 +130,7 @@ checkError.compatibleInstance(caughtErr, new TypeError('Another error')); // fal
130
130
  #### .compatibleConstructor(err, errorLike)
131
131
 
132
132
  ```js
133
- var checkError = require('checkError');
133
+ var checkError = require('check-error');
134
134
 
135
135
  var funcThatThrows = function() { throw new TypeError('I am a TypeError') };
136
136
  var caughtErr;
@@ -149,7 +149,7 @@ checkError.compatibleConstructor(caughtErr, RangeError); // false
149
149
  #### .compatibleMessage(err, errMatcher)
150
150
 
151
151
  ```js
152
- var checkError = require('checkError');
152
+ var checkError = require('check-error');
153
153
 
154
154
  var funcThatThrows = function() { throw new TypeError('I am a TypeError') };
155
155
  var caughtErr;
@@ -171,7 +171,7 @@ checkError.compatibleMessage(caughtErr, 'I do not exist'); // false
171
171
  #### .getConstructorName(errorLike)
172
172
 
173
173
  ```js
174
- var checkError = require('checkError');
174
+ var checkError = require('check-error');
175
175
 
176
176
  var funcThatThrows = function() { throw new TypeError('I am a TypeError') };
177
177
  var caughtErr;
@@ -190,7 +190,7 @@ checkError.getConstructorName(caughtErr) // 'TypeError'
190
190
  #### .getMessage(err)
191
191
 
192
192
  ```js
193
- var checkError = require('checkError');
193
+ var checkError = require('check-error');
194
194
 
195
195
  var funcThatThrows = function() { throw new TypeError('I am a TypeError') };
196
196
  var caughtErr;
package/check-error.js CHANGED
@@ -1,176 +1 @@
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
- });
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})()({},{},[])
package/index.js CHANGED
@@ -6,6 +6,7 @@
6
6
  * MIT Licensed
7
7
  */
8
8
 
9
+ var getFunctionName = require('get-func-name');
9
10
  /**
10
11
  * ### .checkError
11
12
  *
@@ -85,34 +86,6 @@ function compatibleMessage(thrown, errMatcher) {
85
86
  return false;
86
87
  }
87
88
 
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
89
  /**
117
90
  * ### .getConstructorName(errorLike)
118
91
  *
@@ -132,8 +105,11 @@ function getConstructorName(errorLike) {
132
105
  // If `err` is not an instance of Error it is an error constructor itself or another function.
133
106
  // If we've got a common function we get its name, otherwise we may need to create a new instance
134
107
  // of the error just in case it's a poorly-constructed error. Please see chaijs/chai/issues/45 to know more.
135
- constructorName = getFunctionName(errorLike).trim() ||
136
- getFunctionName(new errorLike()); // eslint-disable-line new-cap
108
+ constructorName = getFunctionName(errorLike);
109
+ if (constructorName === '') {
110
+ var newConstructorName = getFunctionName(new errorLike()); // eslint-disable-line new-cap
111
+ constructorName = newConstructorName || constructorName;
112
+ }
137
113
  }
138
114
 
139
115
  return constructorName;
package/package.json CHANGED
@@ -54,7 +54,9 @@
54
54
  "max-statements": 0
55
55
  }
56
56
  },
57
- "dependencies": {},
57
+ "dependencies": {
58
+ "get-func-name": "^2.0.2"
59
+ },
58
60
  "devDependencies": {
59
61
  "browserify": "^13.0.0",
60
62
  "browserify-istanbul": "^1.0.0",
@@ -81,5 +83,5 @@
81
83
  "engines": {
82
84
  "node": "*"
83
85
  },
84
- "version": "1.0.1"
85
- }
86
+ "version": "1.0.3"
87
+ }