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
govuk_publishing_components-17.7.0 node_modules/type/reg-exp/is.js
govuk_publishing_components-17.6.1 node_modules/type/reg-exp/is.js
govuk_publishing_components-17.6.0 node_modules/type/reg-exp/is.js
govuk_publishing_components-17.5.0 node_modules/type/reg-exp/is.js
govuk_publishing_components-17.4.0 node_modules/type/reg-exp/is.js
govuk_publishing_components-17.3.0 node_modules/type/reg-exp/is.js
govuk_publishing_components-17.2.0 node_modules/type/reg-exp/is.js
govuk_publishing_components-17.1.1 node_modules/type/reg-exp/is.js
govuk_publishing_components-17.1.0 node_modules/type/reg-exp/is.js
govuk_publishing_components-17.0.0 node_modules/type/reg-exp/is.js