Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

is-regex

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

is-regex - npm Package Compare versions

Comparing version 1.0.5 to 1.1.0

.editorconfig

10

CHANGELOG.md

@@ -10,2 +10,12 @@ # Changelog

## [v1.1.0](https://github.com/inspect-js/is-regex/compare/v1.0.5...v1.1.0) - 2020-06-04
### Commits
- [New] use `badStringifier`‑based RegExp detection [`31eff67`](https://github.com/inspect-js/is-regex/commit/31eff673243d65c3d6c05848c0eb52f5380f1be3)
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `aud`, `tape` [`fc91458`](https://github.com/inspect-js/is-regex/commit/fc914588187b8bb00d8d792c84f06a6e15d883c1)
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `tape`; add `safe-publish-latest` [`d43ed83`](https://github.com/inspect-js/is-regex/commit/d43ed83db54ea727bb0b1b77a50af79d1edb8a6d)
- [Dev Deps] update `auto-changelog`, `tape`; add `aud` [`56647d1`](https://github.com/inspect-js/is-regex/commit/56647d196be34ef3c118ad67726e75169fbcb875)
- [meta] only run `aud` on prod deps [`e0865b8`](https://github.com/inspect-js/is-regex/commit/e0865b8360b0ac1b9d17b7b81ae5f339e5c9036b)
## [v1.0.5](https://github.com/inspect-js/is-regex/compare/v1.0.4...v1.0.5) - 2019-12-15

@@ -12,0 +22,0 @@

66

index.js
'use strict';
var has = require('has');
var regexExec = RegExp.prototype.exec;
var gOPD = Object.getOwnPropertyDescriptor;
var hasSymbols = require('has-symbols')();
var hasToStringTag = hasSymbols && typeof Symbol.toStringTag === 'symbol';
var regexExec;
var isRegexMarker;
var badStringifier;
var tryRegexExecCall = function tryRegexExec(value) {
try {
var lastIndex = value.lastIndex;
value.lastIndex = 0; // eslint-disable-line no-param-reassign
if (hasToStringTag) {
regexExec = Function.call.bind(RegExp.prototype.exec);
isRegexMarker = {};
regexExec.call(value);
return true;
} catch (e) {
return false;
} finally {
value.lastIndex = lastIndex; // eslint-disable-line no-param-reassign
var throwRegexMarker = function () {
throw isRegexMarker;
};
badStringifier = {
toString: throwRegexMarker,
valueOf: throwRegexMarker
};
if (typeof Symbol.toPrimitive === 'symbol') {
badStringifier[Symbol.toPrimitive] = throwRegexMarker;
}
};
}
var toStr = Object.prototype.toString;
var regexClass = '[object RegExp]';
var hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol';
module.exports = function isRegex(value) {
if (!value || typeof value !== 'object') {
return false;
}
if (!hasToStringTag) {
return toStr.call(value) === regexClass;
}
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 {
regexExec(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 tryRegexExecCall(value);
};
return toStr.call(value) === regexClass;
};
{
"name": "is-regex",
"version": "1.0.5",
"version": "1.1.0",
"description": "Is this value a JS regex? Works cross-realm/iframe, and despite ES6 @@toStringTag",

@@ -12,6 +12,7 @@ "author": "Jordan Harband <ljharb@gmail.com>",

"scripts": {
"prepublish": "safe-publish-latest",
"pretest": "npm run lint",
"test": "npm run tests-only",
"tests-only": "node --harmony --es-staging test",
"posttest": "npx aud",
"posttest": "npx aud --production",
"coverage": "covert test/index.js",

@@ -40,11 +41,14 @@ "lint": "eslint .",

"dependencies": {
"has": "^1.0.3"
"has-symbols": "^1.0.1"
},
"devDependencies": {
"@ljharb/eslint-config": "^15.0.2",
"auto-changelog": "^1.16.2",
"@ljharb/eslint-config": "^17.1.0",
"aud": "^1.1.2",
"auto-changelog": "^2.0.0",
"covert": "^1.1.1",
"eclint": "^2.8.1",
"eslint": "^6.7.2",
"tape": "^4.11.0"
"eslint": "^7.1.0",
"foreach": "^2.0.5",
"safe-publish-latest": "^1.1.4",
"tape": "^5.0.1"
},

@@ -51,0 +55,0 @@ "testling": {

'use strict';
var hasSymbols = require('has-symbols')();
var hasToStringTag = hasSymbols && typeof Symbol.toStringTag === 'symbol';
var forEach = require('foreach');
var test = require('tape');
var isRegex = require('..');
var hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol';

@@ -59,1 +61,46 @@ test('not regexes', function (t) {

});
test('does not perform operations observable to Proxies', { skip: typeof Proxy !== 'function' }, function (t) {
var Handler = function () {
this.trapCalls = 0;
};
forEach([
'defineProperty',
'deleteProperty',
'get',
'getOwnPropertyDescriptor',
'getPrototypeOf',
'has',
'isExtensible',
'ownKeys',
'preventExtensions',
'set',
'setPrototypeOf'
], function (trapName) {
Handler.prototype[trapName] = function () {
this.trapCalls += 1;
return Reflect[trapName].apply(Reflect, arguments);
};
});
t.test('proxy of object', function (st) {
var handler = new Handler();
var proxy = new Proxy({ lastIndex: 0 }, handler);
st.equal(isRegex(proxy), false, 'proxy of plain object is not regex');
st.equal(handler.trapCalls, 0, 'no proxy traps were triggered');
st.end();
});
t.test('proxy of RegExp instance', function (st) {
var handler = new Handler();
var proxy = new Proxy(/a/, handler);
st.equal(isRegex(proxy), false, 'proxy of RegExp instance is not regex');
st.equal(handler.trapCalls, 0, 'no proxy traps were triggered');
st.end();
});
t.end();
});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc