Socket
Socket
Sign inDemoInstall

regexpu-core

Package Overview
Dependencies
9
Maintainers
4
Versions
47
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 5.3.2 to 6.0.0

6

data/iu-mappings.js

@@ -20,2 +20,3 @@ module.exports = new Map([

[0x345, 0x1FBE],
[0x390, 0x1FD3],
[0x392, 0x3D0],

@@ -32,2 +33,3 @@ [0x395, 0x3F5],

[0x3A9, 0x2126],
[0x3B0, 0x1FE3],
[0x3B8, 0x3F4],

@@ -126,2 +128,4 @@ [0x3C2, 0x3A3],

[0x1FCC, 0x1FC3],
[0x1FD3, 0x390],
[0x1FE3, 0x3B0],
[0x1FF3, 0x1FFC],

@@ -139,2 +143,4 @@ [0x1FFC, 0x1FF3],

[0xA64A, 0x1C88],
[0xFB05, 0xFB06],
[0xFB06, 0xFB05],
[0x10400, 0x10428],

@@ -141,0 +147,0 @@ [0x10401, 0x10429],

20

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

@@ -47,10 +47,11 @@ "homepage": "https://mths.be/regexpu",

"build": "node scripts/iu-mappings.js && node scripts/character-class-escape-sets.js",
"test": "mocha tests",
"cover": "istanbul cover --report html node_modules/.bin/_mocha tests -- -u exports -R spec"
"test": "node --test tests/tests.js",
"test-node6": "mocha tests",
"cover": "NODE_V8_COVERAGE=coverage node --test --experimental-test-coverage tests/tests.js"
},
"dependencies": {
"regenerate": "^1.4.2",
"regenerate-unicode-properties": "^10.1.0",
"@babel/regjsgen": "^0.8.0",
"regjsparser": "^0.9.1",
"regenerate-unicode-properties": "^10.1.1",
"regjsgen": "^0.8.0",
"regjsparser": "^0.10.0",
"unicode-match-property-ecmascript": "^2.0.0",

@@ -60,10 +61,5 @@ "unicode-match-property-value-ecmascript": "^2.1.0"

"devDependencies": {
"codecov": "^3.8.3",
"istanbul": "^0.4.5",
"jsesc": "^3.0.2",
"lodash": "^4.17.21",
"mocha": "^10.1.0",
"regexpu-fixtures": "^2.1.6",
"@unicode/unicode-15.0.0": "^1.3.1"
"@unicode/unicode-15.1.0": "^1.5.2"
}
}

26

README.md

@@ -30,9 +30,9 @@ # 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)

```js
rewritePattern('foo.bar', 'u');
rewritePattern('foo.bar', 'u', { unicodeFlag: "transform" });
// → 'foo(?:[\\0-\\t\\x0B\\f\\x0E-\\u2027\\u202A-\\uD7FF\\uDC00-\\uFFFF]|[\\uD800-\\uDBFF][\\uDC00-\\uDFFF]|[\\uD800-\\uDBFF])bar'
rewritePattern('[\\u{1D306}-\\u{1D308}a-z]', 'u');
rewritePattern('[\\u{1D306}-\\u{1D308}a-z]', 'u', { unicodeFlag: "transform" });
// → '(?:[a-z]|\\uD834[\\uDF06-\\uDF08])'
rewritePattern('[\\u{1D306}-\\u{1D308}a-z]', 'ui');
rewritePattern('[\\u{1D306}-\\u{1D308}a-z]', 'ui', { unicodeFlag: "transform" });
// → '(?:[a-z\\u017F\\u212A]|\\uD834[\\uDF06-\\uDF08])'

@@ -45,7 +45,7 @@ ```

// In ES5, the dot operator only matches BMP symbols:
rewritePattern('foo.bar');
rewritePattern('foo.bar', '', { unicodeFlag: "transform" });
// → 'foo(?:[\\0-\\t\\x0B\\f\\x0E-\\u2027\\u202A-\\uFFFF])bar'
// But with the ES2015 `u` flag, it matches astral symbols too:
rewritePattern('foo.bar', 'u');
rewritePattern('foo.bar', 'u', { unicodeFlag: "transform" });
// → 'foo(?:[\\0-\\t\\x0B\\f\\x0E-\\u2027\\u202A-\\uD7FF\\uDC00-\\uFFFF]|[\\uD800-\\uDBFF][\\uDC00-\\uDFFF]|[\\uD800-\\uDBFF])bar'

@@ -119,15 +119,9 @@ ```

#### Experimental regular expression features
These options can be set to `false`, `'parse'` and `'transform'`. When using `'transform'`, the corresponding features are compiled to older syntax that can run in older browsers. When using `'parse'`, they are parsed and left as-is in the output pattern. When using `false` (the default), they result in a syntax error if used.
Once these features become stable (when the proposals are accepted as part of ECMAScript), they will be parsed by default and thus `'parse'` will behave like `false`.
- `unicodeSetsFlag` - [The `v` (`unicodeSets`) flag](https://github.com/tc39/proposal-regexp-set-notation)
```js
rewritePattern('[\\p{Emoji}&&\\p{ASCII}]', 'u', {
rewritePattern('[\\p{Emoji}&&\\p{ASCII}]', 'v', {
unicodeSetsFlag: 'transform'
});
// → '[#\*0-9]'
// → '[#\\*0-9]'
```

@@ -152,2 +146,8 @@

#### Experimental regular expression features
These options can be set to `false`, `'parse'` and `'transform'`. When using `'transform'`, the corresponding features are compiled to older syntax that can run in older browsers. When using `'parse'`, they are parsed and left as-is in the output pattern. When using `false` (the default), they result in a syntax error if used.
Once these features become stable (when the proposals are accepted as part of ECMAScript), they will be parsed by default and thus `'parse'` will behave like `false`.
- `modifiers` - [Inline `m`/`s`/`i` modifiers](https://github.com/tc39/proposal-regexp-modifiers)

@@ -154,0 +154,0 @@

'use strict';
const generate = require('@babel/regjsgen').generate;
const generate = require('regjsgen').generate;
const parse = require('regjsparser').parse;

@@ -24,2 +24,7 @@ const regenerate = require('regenerate');

function regenerateContainsAstral(regenerateData) {
const data = regenerateData.data;
return data.length >= 1 && data[data.length - 1] >= 0x10000;
}
const SPECIAL_CHARS = /([\\^$.*+?()[\]{}|])/g;

@@ -334,3 +339,3 @@

// reached. Code coverage tools should ignore it.
/* istanbul ignore next */
/* node:coverage ignore next */
default:

@@ -419,3 +424,3 @@ throw new Error(`Unknown set action: ${ characterClassItem.kind }`);

// reached. Code coverage tools should ignore it.
/* istanbul ignore next */
/* node:coverage ignore next */
default:

@@ -447,3 +452,3 @@ throw new Error(`Unknown character class kind: ${ characterClassItem.kind }`);

item.value,
config.flags.unicode,
config.flags.unicode || config.flags.unicodeSets,
config.flags.ignoreCase

@@ -458,3 +463,3 @@ ));

config.transform.unicodePropertyEscapes ||
(config.transform.unicodeSetsFlag && nestedData.maybeIncludesStrings);
(config.transform.unicodeSetsFlag && (nestedData.maybeIncludesStrings || characterClassItem.kind !== "union"));
break;

@@ -473,3 +478,3 @@ case 'characterClass':

// reached. Code coverage tools should ignore it.
/* istanbul ignore next */
/* node:coverage ignore next */
default:

@@ -497,3 +502,5 @@ throw new Error(`Unknown term type: ${ item.type }`);

if (transformed) {
const setStr = singleChars.toString(regenerateOptions);
// If single chars already contains some astral character, regenerate (bmpOnly: true) will create valid regex strings
const bmpOnly = regenerateContainsAstral(singleChars);
const setStr = singleChars.toString(Object.assign({}, regenerateOptions, { bmpOnly: bmpOnly }));

@@ -504,3 +511,3 @@ if (negative) {

} else {
if (config.flags.unicode) {
if (config.flags.unicode || config.flags.unicodeSets) {
if (config.flags.ignoreCase) {

@@ -529,6 +536,5 @@ const astralCharsSet = singleChars.clone().intersection(ASTRAL_SET);

// Generate negative set directly when case folding is not involved.
update(
characterClassItem,
UNICODE_SET.clone().remove(singleChars).toString(regenerateOptions)
);
const negativeSet = UNICODE_SET.clone().remove(singleChars);
const bmpOnly = regenerateContainsAstral(negativeSet);
update(characterClassItem, negativeSet.toString({ bmpOnly: bmpOnly }));
}

@@ -743,3 +749,3 @@ } else {

// reached. Code coverage tools should ignore it.
/* istanbul ignore next */
/* node:coverage ignore next */
default:

@@ -786,2 +792,3 @@ throw new Error(`Unknown term type: ${ item.type }`);

case 'unicodePropertyEscapes':
case 'unicodeSetsFlag':
case 'namedGroups':

@@ -793,3 +800,2 @@ if (value != null && value !== false && value !== 'transform') {

case 'modifiers':
case 'unicodeSetsFlag':
if (value != null && value !== false && value !== 'parse' && value !== 'transform') {

@@ -828,3 +834,3 @@ throw new Error(`.${key} must be false (default), 'parse' or 'transform'.`);

// unicodeFlag: 'transform' implies unicodePropertyEscapes: 'transform'
config.transform.unicodePropertyEscapes = config.flags.unicode && (
config.transform.unicodePropertyEscapes = (config.flags.unicode || config.flags.unicodeSets) && (
transform(options, 'unicodeFlag') || transform(options, 'unicodePropertyEscapes')

@@ -840,3 +846,2 @@ );

const regjsparserFeatures = {
'unicodeSet': Boolean(options && options.unicodeSetsFlag),
'modifiers': Boolean(options && options.modifiers),

@@ -846,2 +851,3 @@

'unicodePropertyEscape': true,
'unicodeSet': true,
'namedGroups': true,

@@ -853,3 +859,3 @@ 'lookbehind': true,

'hasUnicodeFlag': config.useUnicodeFlag,
'bmpOnly': !config.flags.unicode
'bmpOnly': !config.flags.unicode && !config.flags.unicodeSets
};

@@ -856,0 +862,0 @@

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc