management/front/dkha-web-sz-main/node_modules/is-regex/index.js

59 lines
1.4 KiB
JavaScript
Raw Normal View History

2023-12-18 13:12:25 +08:00
'use strict';
2023-12-28 23:41:32 +08:00
var callBound = require('call-bind/callBound');
var hasToStringTag = require('has-tostringtag/shams')();
var has;
var $exec;
var isRegexMarker;
var badStringifier;
if (hasToStringTag) {
has = callBound('Object.prototype.hasOwnProperty');
$exec = callBound('RegExp.prototype.exec');
isRegexMarker = {};
2023-12-18 13:12:25 +08:00
2023-12-28 23:41:32 +08:00
var throwRegexMarker = function () {
throw isRegexMarker;
};
badStringifier = {
toString: throwRegexMarker,
valueOf: throwRegexMarker
};
if (typeof Symbol.toPrimitive === 'symbol') {
badStringifier[Symbol.toPrimitive] = throwRegexMarker;
2023-12-18 13:12:25 +08:00
}
2023-12-28 23:41:32 +08:00
}
var $toString = callBound('Object.prototype.toString');
var gOPD = Object.getOwnPropertyDescriptor;
2023-12-18 13:12:25 +08:00
var regexClass = '[object RegExp]';
2023-12-28 23:41:32 +08:00
module.exports = hasToStringTag
// eslint-disable-next-line consistent-return
? function isRegex(value) {
if (!value || typeof value !== 'object') {
return false;
}
var descriptor = gOPD(value, 'lastIndex');
var hasLastIndexDataProperty = descriptor && has(descriptor, 'value');
if (!hasLastIndexDataProperty) {
return false;
}
2023-12-18 13:12:25 +08:00
2023-12-28 23:41:32 +08:00
try {
$exec(value, badStringifier);
} catch (e) {
return e === isRegexMarker;
}
2023-12-18 13:12:25 +08:00
}
2023-12-28 23:41:32 +08:00
: function isRegex(value) {
// In older browsers, typeof regex incorrectly returns 'function'
if (!value || (typeof value !== 'object' && typeof value !== 'function')) {
return false;
}
2023-12-18 13:12:25 +08:00
2023-12-28 23:41:32 +08:00
return $toString(value) === regexClass;
};