File tree 2 files changed +5
-3
lines changed
2 files changed +5
-3
lines changed Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
3
3
var regexExec = RegExp . prototype . exec ;
4
-
5
4
var tryRegexExec = function tryRegexExec ( value ) {
6
5
try {
7
6
regexExec . call ( value ) ;
@@ -10,8 +9,11 @@ var tryRegexExec = function tryRegexExec(value) {
10
9
return false ;
11
10
}
12
11
} ;
12
+ var toStr = Object . prototype . toString ;
13
+ var regexClass = '[object RegExp]' ;
14
+ var hasToStringTag = typeof Symbol === 'function' && typeof Symbol . toStringTag === 'symbol' ;
13
15
14
16
module . exports = function isRegex ( value ) {
15
17
if ( typeof value !== 'object' ) { return false ; }
16
- return tryRegexExec ( value ) ;
18
+ return hasToStringTag ? tryRegexExec ( value ) : toStr . call ( value ) === regexClass ;
17
19
} ;
Original file line number Diff line number Diff line change 6
6
"license" : " MIT" ,
7
7
"main" : " index.js" ,
8
8
"scripts" : {
9
- "test" : " npm run lint && node test.js && npm run coverage-quiet " ,
9
+ "test" : " npm run lint && node test.js" ,
10
10
"coverage" : " covert test.js" ,
11
11
"coverage-quiet" : " covert test.js --quiet" ,
12
12
"lint" : " jscs *.js"
You can’t perform that action at this time.
0 commit comments