1 line
1.0 KiB
JSON
1 line
1.0 KiB
JSON
{"ast":null,"code":"'use strict';\n\nvar has = require('has');\n\nvar regexExec = RegExp.prototype.exec;\nvar gOPD = Object.getOwnPropertyDescriptor;\n\nvar tryRegexExecCall = function tryRegexExec(value) {\n try {\n var lastIndex = value.lastIndex;\n value.lastIndex = 0;\n regexExec.call(value);\n return true;\n } catch (e) {\n return false;\n } finally {\n value.lastIndex = lastIndex;\n }\n};\n\nvar toStr = Object.prototype.toString;\nvar regexClass = '[object RegExp]';\nvar hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol';\n\nmodule.exports = function isRegex(value) {\n if (!value || typeof value !== 'object') {\n return false;\n }\n\n if (!hasToStringTag) {\n return toStr.call(value) === regexClass;\n }\n\n var descriptor = gOPD(value, 'lastIndex');\n var hasLastIndexDataProperty = descriptor && has(descriptor, 'value');\n\n if (!hasLastIndexDataProperty) {\n return false;\n }\n\n return tryRegexExecCall(value);\n};","map":null,"metadata":{},"sourceType":"script"} |