Sha256: e12fd03813980bbbe8cf05e85ae8d4ae8d5a954984a61853a0ba657aa1a5fb6e

Contents?: true

Size: 1.19 KB

Versions: 30

Compression:

Stored size: 1.19 KB

Contents

"use strict";

var isToStringTagSupported = require("../lib/is-to-string-tag-supported")
  , isPrototype            = require("../prototype/is");

var regExpTest = RegExp.prototype.test
  , objectToString = Object.prototype.toString
  , objectTaggedString = objectToString.call(/a/);

module.exports = function (value) {
	if (!value) return false;

	// Sanity check (reject objects which do not expose common RegExp interface)
	if (!hasOwnProperty.call(value, "lastIndex")) return false;
	try {
		if (typeof value.lastIndex !== "number") return false;
		if (typeof value.test !== "function") return false;
		if (typeof value.exec !== "function") return false;
	} catch (error) {
		return false;
	}

	// Ensure its native RegExp object (has [[RegExpMatcher]] slot)
	if (isToStringTagSupported && typeof value[Symbol.toStringTag] === "string") {
		// Edge case (possibly a regExp with custom Symbol.toStringTag)
		try {
			var lastIndex = value.lastIndex;
			regExpTest.call(value, "");
			if (value.lastIndex !== lastIndex) value.lastIndex = lastIndex;
			return true;
		} catch (error) {
			return false;
		}
	}
	if (objectToString.call(value) !== objectTaggedString) return false;
	return !isPrototype(value);
};

Version data entries

30 entries across 29 versions & 2 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/ext/node_modules/type/reg-exp/is.js
optimacms-0.1.61 spec/dummy/node_modules/type/reg-exp/is.js
govuk_publishing_components-18.0.0 node_modules/type/reg-exp/is.js
govuk_publishing_components-17.21.0 node_modules/type/reg-exp/is.js
govuk_publishing_components-17.20.0 node_modules/type/reg-exp/is.js
govuk_publishing_components-17.19.1 node_modules/type/reg-exp/is.js
govuk_publishing_components-17.19.0 node_modules/type/reg-exp/is.js
govuk_publishing_components-17.18.0 node_modules/type/reg-exp/is.js
govuk_publishing_components-17.17.0 node_modules/type/reg-exp/is.js
govuk_publishing_components-17.16.0 node_modules/type/reg-exp/is.js
govuk_publishing_components-17.15.0 node_modules/type/reg-exp/is.js
govuk_publishing_components-17.14.0 node_modules/type/reg-exp/is.js
govuk_publishing_components-17.13.0 node_modules/type/reg-exp/is.js
govuk_publishing_components-17.12.2 node_modules/type/reg-exp/is.js
govuk_publishing_components-17.12.1 node_modules/type/reg-exp/is.js
govuk_publishing_components-17.12.0 node_modules/type/reg-exp/is.js
govuk_publishing_components-17.11.0 node_modules/type/reg-exp/is.js
govuk_publishing_components-17.10.0 node_modules/type/reg-exp/is.js
govuk_publishing_components-17.9.0 node_modules/type/reg-exp/is.js
govuk_publishing_components-17.8.0 node_modules/type/reg-exp/is.js