Skip to content

Commit ab38c4c

Browse files
committed
chore: use external get-func-name module
1 parent f609b7b commit ab38c4c

File tree

2 files changed

+5
-32
lines changed

2 files changed

+5
-32
lines changed

index.js

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* MIT Licensed
77
*/
88

9+
var getFunctionName = require('get-func-name');
910
/**
1011
* ### .checkError
1112
*
@@ -85,36 +86,6 @@ function compatibleMessage(thrown, errMatcher) {
8586
return false;
8687
}
8788

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 toString = Function.prototype.toString;
101-
var functionNameMatch = /\s*function(?:\s|\s*\/\*[^(?:*\/)]+\*\/\s*)*([^\s\(\/]+)/;
102-
function getFunctionName(constructorFn) {
103-
var name = '';
104-
if (typeof Function.prototype.name === 'undefined' && typeof constructorFn.name === 'undefined') {
105-
// Here we run a polyfill if Function does not support the `name` property and if constructorFn.name is not defined
106-
var match = toString.call(constructorFn).match(functionNameMatch);
107-
if (match) {
108-
name = match[1];
109-
}
110-
} else {
111-
// If we've got a `name` property we just use it
112-
name = constructorFn.name;
113-
}
114-
115-
return name;
116-
}
117-
11889
/**
11990
* ### .getConstructorName(errorLike)
12091
*
@@ -137,7 +108,7 @@ function getConstructorName(errorLike) {
137108
constructorName = getFunctionName(errorLike);
138109
if (constructorName === '') {
139110
var newConstructorName = getFunctionName(new errorLike()); // eslint-disable-line new-cap
140-
constructorName = newConstructorName ? newConstructorName : constructorName;
111+
constructorName = newConstructorName || constructorName;
141112
}
142113
}
143114

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@
5454
"max-statements": 0
5555
}
5656
},
57-
"dependencies": {},
57+
"dependencies": {
58+
"get-func-name": "^1.0.0"
59+
},
5860
"devDependencies": {
5961
"browserify": "^13.0.0",
6062
"browserify-istanbul": "^1.0.0",

0 commit comments

Comments
 (0)