Socket
Socket
Sign inDemoInstall

regexpu-core

Package Overview
Dependencies
Maintainers
4
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

regexpu-core - npm Package Compare versions

Comparing version 5.0.1 to 5.1.0

10

data/iu-mappings.js

@@ -135,13 +135,3 @@ module.exports = new Map([

]],
[0x2C2F, 0x2C5F],
[0x2C5F, 0x2C2F],
[0xA64A, 0x1C88],
[0xA7C0, 0xA7C1],
[0xA7C1, 0xA7C0],
[0xA7D0, 0xA7D1],
[0xA7D1, 0xA7D0],
[0xA7D6, 0xA7D7],
[0xA7D7, 0xA7D6],
[0xA7D8, 0xA7D9],
[0xA7D9, 0xA7D8],
[0x10400, 0x10428],

@@ -148,0 +138,0 @@ [0x10401, 0x10429],

2

package.json
{
"name": "regexpu-core",
"version": "5.0.1",
"version": "5.1.0",
"description": "regexpu’s core functionality (i.e. `rewritePattern(pattern, flag)`), capable of translating ES6 Unicode regular expressions to ES5.",

@@ -5,0 +5,0 @@ "homepage": "https://mths.be/regexpu",

@@ -112,3 +112,3 @@ # regexpu-core [![Build status](https://github.com/mathiasbynens/regexpu-core/workflows/run-checks/badge.svg)](https://github.com/mathiasbynens/regexpu-core/actions?query=workflow%3Arun-checks) [![regexpu-core on npm](https://img.shields.io/npm/v/regexpu-core)](https://www.npmjs.com/package/regexpu-core)

rewritePattern('(?<name>.)\\k<name>', '', {
namedGroup: "transform"
namedGroups: 'transform'
});

@@ -115,0 +115,0 @@ // → '(.)\1'

@@ -11,2 +11,17 @@ 'use strict';

function flatMap(array, callback) {
const result = [];
array.forEach(item => {
const res = callback(item);
if (Array.isArray(res)) {
result.push.apply(result, res);
} else {
result.push(res);
}
});
return result;
}
const SPECIAL_CHARS = new Set('\\^$.*+?()[]{}|'.split(''));
// Prepare a Regenerate set containing all code points, used for negative

@@ -97,3 +112,6 @@ // character classes (if any).

characters: set.characters.clone(),
strings: new Set(set.strings || [])
strings: set.strings
// We need to escape strings like *️⃣ to make sure that they can be safelu used in unions
? new Set(set.strings.map(str => SPECIAL_CHARS.has(str[0]) ? `\\${str}` : str))
: new Set()
};

@@ -444,2 +462,3 @@ };

const pieces = Array.from(longStrings).sort((a, b) => b.length - a.length);
if (setStr !== '[]' || longStrings.size === 0) {

@@ -455,7 +474,2 @@ pieces.splice(pieces.length - (hasEmptyString ? 1 : 0), 0, setStr);

const updateNamedReference = (item, index) => {
delete item.name;
item.matchIndex = index;
};
const assertNoUnmatchedReferences = (groups) => {

@@ -522,7 +536,8 @@ const unmatchedReferencesNames = Object.keys(groups.unmatchedReferences);

if (groups.names[name]) {
if (groups.namesConflicts[name]) {
throw new Error(
`Multiple groups with the same name (${ name }) are not allowed.`
`Group '${ name }' has already been defined in this context.`
);
}
groups.namesConflicts[name] = true;

@@ -532,3 +547,7 @@ const index = groups.lastIndex;

groups.names[name] = index;
if (!groups.names[name]) {
groups.names[name] = [];
}
groups.names[name].push(index);
if (groups.onNamedGroup) {

@@ -539,5 +558,2 @@ groups.onNamedGroup.call(null, name, index);

if (groups.unmatchedReferences[name]) {
groups.unmatchedReferences[name].forEach(reference => {
updateNamedReference(reference, index);
});
delete groups.unmatchedReferences[name];

@@ -547,4 +563,2 @@ }

/* falls through */
case 'alternative':
case 'disjunction':
case 'quantifier':

@@ -555,2 +569,16 @@ item.body = item.body.map(term => {

break;
case 'disjunction':
const outerNamesConflicts = groups.namesConflicts;
item.body = item.body.map(term => {
groups.namesConflicts = Object.create(outerNamesConflicts);
return processTerm(term, regenerateOptions, groups);
});
break;
case 'alternative':
item.body = flatMap(item.body, term => {
const res = processTerm(term, regenerateOptions, groups);
// Alternatives cannot contain alternatives; flatten them.
return res.type === 'alternative' ? res.body : res;
});
break;
case 'value':

@@ -570,13 +598,28 @@ const codePoint = item.codePoint;

const name = item.name.value;
const index = groups.names[name];
if (index) {
updateNamedReference(item, index);
break;
const indexes = groups.names[name];
if (indexes) {
const body = indexes.map(index => ({
'type': 'reference',
'matchIndex': index,
'raw': '\\' + index,
}));
if (body.length === 1) {
return body[0];
}
return {
'type': 'alternative',
'body': body,
'raw': body.map(term => term.raw).join(''),
};
}
if (!groups.unmatchedReferences[name]) {
groups.unmatchedReferences[name] = [];
}
// Keep track of references used before the corresponding group.
groups.unmatchedReferences[name].push(item);
// This named reference comes before the group where it’s defined,
// so it’s always an empty match.
groups.unmatchedReferences[name] = true;
return {
'type': 'group',
'behavior': 'ignore',
'body': [],
'raw': '(?:)',
};
}

@@ -685,4 +728,5 @@ break;

'lastIndex': 0,
'names': Object.create(null), // { [name]: index }
'unmatchedReferences': Object.create(null) // { [name]: Array<reference> }
'names': Object.create(null), // { [name]: Array<index> }
'namesConflicts': Object.create(null), // { [name]: true }
'unmatchedReferences': Object.create(null) // { [name]: true }
};

@@ -689,0 +733,0 @@

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