New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

is-regex

Package Overview
Dependencies
Maintainers
0
Versions
14
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.1.4 to 1.2.0

index.d.ts

28

CHANGELOG.md

@@ -8,2 +8,30 @@ # Changelog

## [v1.2.0](https://github.com/inspect-js/is-regex/compare/v1.1.4...v1.2.0) - 2024-11-29
### Fixed
- [Tests] allow tests to pass if zero traps are triggered [`#35`](https://github.com/inspect-js/is-regex/issues/35)
### Commits
- [actions] reuse common workflows [`be7bf6a`](https://github.com/inspect-js/is-regex/commit/be7bf6af175271e9db74e092d636307f6cf5e848)
- [New] add types [`39066a4`](https://github.com/inspect-js/is-regex/commit/39066a426da0f0c597b888c3c839fb2efc2bf613)
- [meta] use `npmignore` to autogenerate an npmignore file [`8938588`](https://github.com/inspect-js/is-regex/commit/89385885c2da891644e07220b4407f760c3dd629)
- [Refactor] reorganize code [`2f76f26`](https://github.com/inspect-js/is-regex/commit/2f76f26e0008a01a2f9a849dc2687cf3e3146f3e)
- [actions] split out node 10-20, and 20+ [`8c9aedf`](https://github.com/inspect-js/is-regex/commit/8c9aedf2cd9b3fd4ee045d747580265de223b4b2)
- [meta] better `eccheck` command [`6b39408`](https://github.com/inspect-js/is-regex/commit/6b39408bc4cce49ac85de70fba4a843da4b78b84)
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `safe-publish-latest`, `tape` [`e38cf3c`](https://github.com/inspect-js/is-regex/commit/e38cf3c4e5b234c9a0d64fcf75e45df9b2416557)
- [actions] update codecov uploader [`487c75d`](https://github.com/inspect-js/is-regex/commit/487c75da7bbc2d977c2aed68815e7a58d269011f)
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `aud`, `auto-changelog`, `core-js`, `foreach`, `tape` [`0d7da87`](https://github.com/inspect-js/is-regex/commit/0d7da87be90b637c094abfd9e68568097d391e38)
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `aud`, `core-js`, `tape` [`c1c1198`](https://github.com/inspect-js/is-regex/commit/c1c1198143feaadee0370b78f7fd878e64e57a58)
- [actions] update rebase action to use reusable workflow [`213646e`](https://github.com/inspect-js/is-regex/commit/213646e1e9b5211bf621ccaaaa29f03b706b139c)
- [Dev Deps] update `@ljharb/eslint-config`, `auto-changelog`, `core-js`, `npmignore`, `tape` [`0a44e77`](https://github.com/inspect-js/is-regex/commit/0a44e77855db0ee8077f8b4351164fa500ba0d1f)
- [Refactor] use `hasown` [`d939332`](https://github.com/inspect-js/is-regex/commit/d939332c57cf46b95bc45e721fb66db64cf4743a)
- [Deps] update `call-bind`, `has-tostringtag` [`46bfdc9`](https://github.com/inspect-js/is-regex/commit/46bfdc9226df0495b5eb4e753e3f61e9a648cf44)
- [Tests] use `for-each` instead of `foreach` [`138b3f2`](https://github.com/inspect-js/is-regex/commit/138b3f2e6340eb4b6caf62981b0a1f59e960cbc9)
- [Tests] replace `aud` with `npm audit` [`37ed80a`](https://github.com/inspect-js/is-regex/commit/37ed80a3a5eeec2312f45956bc928fc7937480b8)
- [Deps] update `gopd` [`6fd4097`](https://github.com/inspect-js/is-regex/commit/6fd4097f23c3f031d0e659b29174216bed7b4f0f)
- [Dev Deps] update `core-js` [`97c1c60`](https://github.com/inspect-js/is-regex/commit/97c1c6044684f8a661055f4614ab2dd58fbfcc2b)
- [Dev Deps] add missing peer dep [`7329b8e`](https://github.com/inspect-js/is-regex/commit/7329b8edc9d9440439f190704f03740c853d15da)
## [v1.1.4](https://github.com/inspect-js/is-regex/compare/v1.1.3...v1.1.4) - 2021-08-05

@@ -10,0 +38,0 @@

51

index.js

@@ -5,11 +5,13 @@ 'use strict';

var hasToStringTag = require('has-tostringtag/shams')();
var has;
var $exec;
var isRegexMarker;
var badStringifier;
var hasOwn = require('hasown');
var gOPD = require('gopd');
/** @type {import('.')} */
var fn;
if (hasToStringTag) {
has = callBound('Object.prototype.hasOwnProperty');
$exec = callBound('RegExp.prototype.exec');
isRegexMarker = {};
/** @type {(receiver: ThisParameterType<typeof RegExp.prototype.exec>, ...args: Parameters<typeof RegExp.prototype.exec>) => ReturnType<typeof RegExp.prototype.exec>} */
var $exec = callBound('RegExp.prototype.exec');
/** @type {object} */
var isRegexMarker = {};

@@ -19,3 +21,4 @@ var throwRegexMarker = function () {

};
badStringifier = {
/** @type {{ toString(): never, valueOf(): never, [Symbol.toPrimitive]?(): never }} */
var badStringifier = {
toString: throwRegexMarker,

@@ -28,11 +31,7 @@ valueOf: throwRegexMarker

}
}
var $toString = callBound('Object.prototype.toString');
var gOPD = Object.getOwnPropertyDescriptor;
var regexClass = '[object RegExp]';
module.exports = hasToStringTag
/** @type {import('.')} */
// @ts-expect-error TS can't figure out that the $exec call always throws
// eslint-disable-next-line consistent-return
? function isRegex(value) {
fn = function isRegex(value) {
if (!value || typeof value !== 'object') {

@@ -42,4 +41,5 @@ return false;

var descriptor = gOPD(value, 'lastIndex');
var hasLastIndexDataProperty = descriptor && has(descriptor, 'value');
// eslint-disable-next-line no-extra-parens
var descriptor = /** @type {NonNullable<typeof gOPD>} */ (gOPD)(/** @type {{ lastIndex?: unknown }} */ (value), 'lastIndex');
var hasLastIndexDataProperty = descriptor && hasOwn(descriptor, 'value');
if (!hasLastIndexDataProperty) {

@@ -50,8 +50,16 @@ return false;

try {
$exec(value, badStringifier);
// eslint-disable-next-line no-extra-parens
$exec(value, /** @type {string} */ (/** @type {unknown} */ (badStringifier)));
} catch (e) {
return e === isRegexMarker;
}
}
: function isRegex(value) {
};
} else {
/** @type {(receiver: ThisParameterType<typeof Object.prototype.toString>, ...args: Parameters<typeof Object.prototype.toString>) => ReturnType<typeof Object.prototype.toString>} */
var $toString = callBound('Object.prototype.toString');
/** @const @type {'[object RegExp]'} */
var regexClass = '[object RegExp]';
/** @type {import('.')} */
fn = function isRegex(value) {
// In older browsers, typeof regex incorrectly returns 'function'

@@ -64,1 +72,4 @@ if (!value || (typeof value !== 'object' && typeof value !== 'function')) {

};
}
module.exports = fn;
{
"name": "is-regex",
"version": "1.1.4",
"version": "1.2.0",
"description": "Is this value a JS regex? Works cross-realm/iframe, and despite ES6 @@toStringTag",

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

"scripts": {
"prepack": "npmignore --auto --commentLines=autogenerated",
"prepublishOnly": "safe-publish-latest",

@@ -20,5 +21,6 @@ "prepublish": "not-in-publish || npm run prepublishOnly",

"test:corejs": "nyc tape test-corejs.js",
"posttest": "npx aud --production",
"lint": "eslint .",
"eccheck": "eclint check *.js **/*.js > /dev/null",
"posttest": "npx npm@'>=10.2' audit --production",
"prelint": "eclint check $(git ls-files | xargs find 2> /dev/null | grep -vE 'node_modules|\\.git')",
"lint": "eslint --ext=js,mjs .",
"postlint": "tsc -p . && attw -P",
"version": "auto-changelog && git add CHANGELOG.md",

@@ -44,16 +46,27 @@ "postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\""

"dependencies": {
"call-bind": "^1.0.2",
"has-tostringtag": "^1.0.0"
"call-bind": "^1.0.7",
"gopd": "^1.1.0",
"has-tostringtag": "^1.0.2",
"hasown": "^2.0.2"
},
"devDependencies": {
"@ljharb/eslint-config": "^17.6.0",
"aud": "^1.1.5",
"auto-changelog": "^2.3.0",
"core-js": "^3.16.0",
"@arethetypeswrong/cli": "^0.17.0",
"@ljharb/eslint-config": "^21.1.1",
"@ljharb/tsconfig": "^0.2.0",
"@types/call-bind": "^1.0.5",
"@types/core-js": "^2.5.8",
"@types/for-each": "^0.3.3",
"@types/tape": "^5.6.5",
"auto-changelog": "^2.5.0",
"core-js": "^3.39.0",
"eclint": "^2.8.1",
"eslint": "^7.32.0",
"foreach": "^2.0.5",
"encoding": "^0.1.13",
"eslint": "=8.8.0",
"for-each": "^0.3.3",
"in-publish": "^2.0.1",
"npmignore": "^0.3.1",
"nyc": "^10.3.2",
"safe-publish-latest": "^1.1.4",
"tape": "^5.3.0"
"safe-publish-latest": "^2.0.0",
"tape": "^5.9.0",
"typescript": "^5.8.0-dev.20241129"
},

@@ -88,3 +101,9 @@ "testling": {

"hideCredit": true
},
"publishConfig": {
"ignore": [
".github/workflows",
"test-corejs.js"
]
}
}
'use strict';
var hasToStringTag = require('has-tostringtag/shams')();
var forEach = require('foreach');
var forEach = require('for-each');
var test = require('tape');

@@ -9,2 +9,3 @@ var isRegex = require('..');

test('not regexes', function (t) {
// @ts-expect-error
t.notOk(isRegex(), 'undefined is not regex');

@@ -24,2 +25,3 @@ t.notOk(isRegex(null), 'null is not regex');

var regex = /a/g;
/** @type {{ toString(): string, valueOf(): RegExp, [Symbol.toStringTag]?: string}} */
var fakeRegex = {

@@ -44,2 +46,3 @@ toString: function () { return String(regex); },

var marker = {};
// @ts-expect-error
regex.lastIndex = marker;

@@ -65,7 +68,10 @@ st.equal(regex.lastIndex, marker, 'lastIndex is the marker object');

test('does not perform operations observable to Proxies', { skip: typeof Proxy !== 'function' }, function (t) {
var Handler = function () {
/** @constructor */
function Handler() {
/** @type (keyof Reflect)[]} */
this.trapCalls = [];
};
}
forEach([
// eslint-disable-next-line no-extra-parens
forEach(/** @const @type {(keyof Reflect)[]} */ ([
'defineProperty',

@@ -82,5 +88,6 @@ 'deleteProperty',

'setPrototypeOf'
], function (trapName) {
]), function (trapName) {
Handler.prototype[trapName] = function () {
this.trapCalls.push(trapName);
// @ts-expect-error TODO: not sure why this is erroring
return Reflect[trapName].apply(Reflect, arguments);

@@ -92,6 +99,11 @@ };

var handler = new Handler();
// @ts-expect-error Proxy handlers can be any object
var proxy = new Proxy({ lastIndex: 0 }, handler);
st.equal(isRegex(proxy), false, 'proxy of plain object is not regex');
st.deepEqual(handler.trapCalls, ['getOwnPropertyDescriptor'], 'no unexpected proxy traps were triggered');
st.deepEqual(
handler.trapCalls,
handler.trapCalls.length > 0 ? ['getOwnPropertyDescriptor'] : [],
'no unexpected proxy traps were triggered'
);
st.end();

@@ -102,6 +114,11 @@ });

var handler = new Handler();
// @ts-expect-error Proxy handlers can be any object
var proxy = new Proxy(/a/, handler);
st.equal(isRegex(proxy), false, 'proxy of RegExp instance is not regex');
st.deepEqual(handler.trapCalls, ['getOwnPropertyDescriptor'], 'no unexpected proxy traps were triggered');
st.deepEqual(
handler.trapCalls,
handler.trapCalls.length > 0 ? ['getOwnPropertyDescriptor'] : [],
'no unexpected proxy traps were triggered'
);
st.end();

@@ -108,0 +125,0 @@ });

Sorry, the diff of this file is not supported yet

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