Skip to content

Commit 5f8b992

Browse files
committed
[Robustness] use safe-regex-test
1 parent 6dfff38 commit 5f8b992

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
var toStr = Object.prototype.toString;
44
var fnToStr = Function.prototype.toString;
5-
var isFnRegex = /^\s*(?:function)?\*/;
5+
var safeRegexTest = require('safe-regex-test');
6+
var isFnRegex = safeRegexTest(/^\s*(?:function)?\*/);
67
var hasToStringTag = require('has-tostringtag/shams')();
78
var getProto = require('get-proto');
9+
810
var getGeneratorFunc = function () { // eslint-disable-line consistent-return
911
if (!hasToStringTag) {
1012
return false;
@@ -20,7 +22,7 @@ module.exports = function isGeneratorFunction(fn) {
2022
if (typeof fn !== 'function') {
2123
return false;
2224
}
23-
if (isFnRegex.test(fnToStr.call(fn))) {
25+
if (isFnRegex(fnToStr.call(fn))) {
2426
return true;
2527
}
2628
if (!hasToStringTag) {

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
},
4444
"dependencies": {
4545
"get-proto": "^1.0.0",
46-
"has-tostringtag": "^1.0.2"
46+
"has-tostringtag": "^1.0.2",
47+
"safe-regex-test": "^1.1.0"
4748
},
4849
"devDependencies": {
4950
"@ljharb/eslint-config": "^21.1.1",

0 commit comments

Comments
 (0)