Skip to content

Commit 5ab7632

Browse files
committed
Improve optimization by separating the try/catch, and bailing out early when not typeof "object".
1 parent c278e21 commit 5ab7632

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

index.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
var regexExec = RegExp.prototype.exec;
44

5-
module.exports = function isRegex(value) {
5+
var tryRegexExec = function tryRegexExec(value) {
66
try {
77
regexExec.call(value);
88
return true;
@@ -11,3 +11,7 @@ module.exports = function isRegex(value) {
1111
}
1212
};
1313

14+
module.exports = function isRegex(value) {
15+
if (typeof value !== 'object') { return false; }
16+
return tryRegexExec(value);
17+
};

0 commit comments

Comments
 (0)