IsRegExp.js 545 B

123456789101112131415161718192021222324
  1. 'use strict';
  2. var GetIntrinsic = require('get-intrinsic');
  3. var $match = GetIntrinsic('%Symbol.match%', true);
  4. var hasRegExpMatcher = require('is-regex');
  5. var ToBoolean = require('./ToBoolean');
  6. // https://ecma-international.org/ecma-262/6.0/#sec-isregexp
  7. module.exports = function IsRegExp(argument) {
  8. if (!argument || typeof argument !== 'object') {
  9. return false;
  10. }
  11. if ($match) {
  12. var isRegExp = argument[$match];
  13. if (typeof isRegExp !== 'undefined') {
  14. return ToBoolean(isRegExp);
  15. }
  16. }
  17. return hasRegExpMatcher(argument);
  18. };