Skip to content

Commit 50b0ffd

Browse files
committed
If @@toStringTag is not present, use the old-school Object#toString test.
1 parent ed8047d commit 50b0ffd

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

index.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22

33
var regexExec = RegExp.prototype.exec;
4-
54
var tryRegexExec = function tryRegexExec(value) {
65
try {
76
regexExec.call(value);
@@ -10,8 +9,11 @@ var tryRegexExec = function tryRegexExec(value) {
109
return false;
1110
}
1211
};
12+
var toStr = Object.prototype.toString;
13+
var regexClass = '[object RegExp]';
14+
var hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol';
1315

1416
module.exports = function isRegex(value) {
1517
if (typeof value !== 'object') { return false; }
16-
return tryRegexExec(value);
18+
return hasToStringTag ? tryRegexExec(value) : toStr.call(value) === regexClass;
1719
};

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"license": "MIT",
77
"main": "index.js",
88
"scripts": {
9-
"test": "npm run lint && node test.js && npm run coverage-quiet",
9+
"test": "npm run lint && node test.js",
1010
"coverage": "covert test.js",
1111
"coverage-quiet": "covert test.js --quiet",
1212
"lint": "jscs *.js"

0 commit comments

Comments
 (0)