'use strict'; var has = require('has'); var regexExec = RegExp.prototype.exec; var gOPD = Object.getOwnPropertyDescriptor; var tryRegexExecCall = function tryRegexExec(value) { try { var lastIndex = value.lastIndex; value.lastIndex = 0; regexExec.call(value); return true; } catch (e) { return false; } finally { value.lastIndex = lastIndex; } }; var toStr = Object.prototype.toString; var regexClass = '[object RegExp]'; var hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol'; module.exports = function isRegex(value) { if (!value || typeof value !== 'object') { return false; } if (!hasToStringTag) { return toStr.call(value) === regexClass; } var descriptor = gOPD(value, 'lastIndex'); var hasLastIndexDataProperty = descriptor && has(descriptor, 'value'); if (!hasLastIndexDataProperty) { return false; } return tryRegexExecCall(value); };
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
.jscs.json | File | 4.04 KB | 0644 |
|
.npmignore | File | 97 B | 0644 |
|
.travis.yml | File | 4.66 KB | 0644 |
|
CHANGELOG.md | File | 1.08 KB | 0644 |
|
LICENSE | File | 1.06 KB | 0644 |
|
Makefile | File | 3.74 KB | 0644 |
|
README.md | File | 1.59 KB | 0644 |
|
index.js | File | 918 B | 0644 |
|
package.json | File | 1.79 KB | 0644 |
|
test.js | File | 1.76 KB | 0644 |
|