Sha256: 10c5e8398a189adf8c781858c54637a9e4dc4d659163647569e69cff90d82fd6

Contents?: true

Size: 1.37 KB

Versions: 41

Compression:

Stored size: 1.37 KB

Contents

'use strict';

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 = {};

	var throwRegexMarker = function () {
		throw isRegexMarker;
	};
	badStringifier = {
		toString: throwRegexMarker,
		valueOf: throwRegexMarker
	};

	if (typeof Symbol.toPrimitive === 'symbol') {
		badStringifier[Symbol.toPrimitive] = throwRegexMarker;
	}
}

var $toString = callBound('Object.prototype.toString');
var gOPD = Object.getOwnPropertyDescriptor;
var regexClass = '[object RegExp]';

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;
		}

		try {
			$exec(value, badStringifier);
		} catch (e) {
			return e === isRegexMarker;
		}
	}
	: function isRegex(value) {
		// In older browsers, typeof regex incorrectly returns 'function'
		if (!value || (typeof value !== 'object' && typeof value !== 'function')) {
			return false;
		}

		return $toString(value) === regexClass;
	};

Version data entries

41 entries across 41 versions & 2 rubygems

Version Path
immosquare-cleaner-0.1.51 node_modules/is-regex/index.js
immosquare-cleaner-0.1.50 node_modules/is-regex/index.js
immosquare-cleaner-0.1.49 node_modules/is-regex/index.js
immosquare-cleaner-0.1.48 node_modules/is-regex/index.js
immosquare-cleaner-0.1.47 node_modules/is-regex/index.js
immosquare-cleaner-0.1.46 node_modules/is-regex/index.js
immosquare-cleaner-0.1.45 node_modules/is-regex/index.js
immosquare-cleaner-0.1.44 node_modules/is-regex/index.js
immosquare-cleaner-0.1.43 node_modules/is-regex/index.js
immosquare-cleaner-0.1.42 node_modules/is-regex/index.js
immosquare-cleaner-0.1.41 node_modules/is-regex/index.js
immosquare-cleaner-0.1.40 node_modules/is-regex/index.js
immosquare-cleaner-0.1.39 node_modules/is-regex/index.js
immosquare-cleaner-0.1.38 node_modules/is-regex/index.js
immosquare-cleaner-0.1.32 node_modules/is-regex/index.js
immosquare-cleaner-0.1.31 node_modules/is-regex/index.js
immosquare-cleaner-0.1.30 node_modules/is-regex/index.js
immosquare-cleaner-0.1.29 node_modules/is-regex/index.js
immosquare-cleaner-0.1.28 node_modules/is-regex/index.js
immosquare-cleaner-0.1.27 node_modules/is-regex/index.js