regexpu-core
Advanced tools
Comparing version 4.6.0 to 4.7.0
{ | ||
"name": "regexpu-core", | ||
"version": "4.6.0", | ||
"version": "4.7.0", | ||
"description": "regexpu’s core functionality (i.e. `rewritePattern(pattern, flag)`), capable of translating ES6 Unicode regular expressions to ES5.", | ||
@@ -52,17 +52,17 @@ "homepage": "https://mths.be/regexpu", | ||
"regenerate": "^1.4.0", | ||
"regenerate-unicode-properties": "^8.1.0", | ||
"regjsgen": "^0.5.0", | ||
"regjsparser": "^0.6.0", | ||
"regenerate-unicode-properties": "^8.2.0", | ||
"regjsgen": "^0.5.1", | ||
"regjsparser": "^0.6.4", | ||
"unicode-match-property-ecmascript": "^1.0.4", | ||
"unicode-match-property-value-ecmascript": "^1.1.0" | ||
"unicode-match-property-value-ecmascript": "^1.2.0" | ||
}, | ||
"devDependencies": { | ||
"codecov": "^3.5.0", | ||
"codecov": "^3.6.5", | ||
"istanbul": "^0.4.5", | ||
"jsesc": "^2.5.2", | ||
"lodash": "^4.17.15", | ||
"mocha": "^6.2.0", | ||
"mocha": "^7.1.0", | ||
"regexpu-fixtures": "^2.1.3", | ||
"unicode-12.1.0": "^0.8.0" | ||
"unicode-13.0.0": "^0.8.0" | ||
} | ||
} |
# regexpu-core [![Build status](https://travis-ci.org/mathiasbynens/regexpu-core.svg?branch=master)](https://travis-ci.org/mathiasbynens/regexpu-core) [![Code coverage status](https://img.shields.io/codecov/c/github/mathiasbynens/regexpu-core.svg)](https://codecov.io/gh/mathiasbynens/regexpu-core) | ||
_regexpu_ is a source code transpiler that enables the use of ES6 Unicode regular expressions in JavaScript-of-today (ES5). | ||
_regexpu_ is a source code transpiler that enables the use of ES2015 Unicode regular expressions in JavaScript-of-today (ES5). | ||
_regexpu-core_ contains _regexpu_’s core functionality, i.e. `rewritePattern(pattern, flag)`, which enables rewriting regular expressions that make use of [the ES6 `u` flag](https://mathiasbynens.be/notes/es6-unicode-regex) into equivalent ES5-compatible regular expression patterns. | ||
_regexpu-core_ contains _regexpu_’s core functionality, i.e. `rewritePattern(pattern, flag)`, which enables rewriting regular expressions that make use of [the ES2015 `u` flag](https://mathiasbynens.be/notes/es6-unicode-regex) into equivalent ES5-compatible regular expression patterns. | ||
@@ -47,3 +47,3 @@ ## Installation | ||
// But with the ES6 `u` flag, it matches astral symbols too: | ||
// But with the ES2015 `u` flag, it matches astral symbols too: | ||
rewritePattern('foo.bar', 'u'); | ||
@@ -129,3 +129,3 @@ // → 'foo(?:[\\0-\\t\\x0B\\f\\x0E-\\u2027\\u202A-\\uD7FF\\uDC00-\\uFFFF]|[\\uD800-\\uDBFF][\\uDC00-\\uDFFF]|[\\uD800-\\uDBFF])bar' | ||
Setting this option to `true` enables the use of Unicode code point escapes of the form `\u{…}`. Note that in regular expressions, such escape sequences only work correctly when the ES6 `u` flag is set. Enabling this setting often results in more compact output, although there are cases (such as `\p{Lu}`) where it actually _increases_ the output size. | ||
Setting this option to `true` enables the use of Unicode code point escapes of the form `\u{…}`. Note that in regular expressions, such escape sequences only work correctly when the ES2015 `u` flag is set. Enabling this setting often results in more compact output, although there are cases (such as `\p{Lu}`) where it actually _increases_ the output size. | ||
@@ -132,0 +132,0 @@ ```js |
@@ -205,7 +205,9 @@ 'use strict'; | ||
case 'unicodePropertyEscape': | ||
update( | ||
item, | ||
getUnicodePropertyEscapeSet(item.value, item.negative) | ||
.toString(regenerateOptions) | ||
); | ||
if (config.unicodePropertyEscape) { | ||
update( | ||
item, | ||
getUnicodePropertyEscapeSet(item.value, item.negative) | ||
.toString(regenerateOptions) | ||
); | ||
} | ||
break; | ||
@@ -226,3 +228,3 @@ case 'characterClassEscape': | ||
} | ||
if (item.name) { | ||
if (item.name && config.namedGroup) { | ||
const name = item.name.value; | ||
@@ -304,15 +306,19 @@ | ||
'dotAll': false, | ||
'useUnicodeFlag': false | ||
'useUnicodeFlag': false, | ||
'unicodePropertyEscape': false, | ||
'namedGroup': false | ||
}; | ||
const rewritePattern = (pattern, flags, options) => { | ||
config.unicode = flags && flags.includes('u'); | ||
const regjsparserFeatures = { | ||
'unicodePropertyEscape': options && options.unicodePropertyEscape, | ||
'namedGroups': options && options.namedGroup, | ||
'unicodePropertyEscape': config.unicode, | ||
'namedGroups': true, | ||
'lookbehind': options && options.lookbehind | ||
}; | ||
config.ignoreCase = flags && flags.includes('i'); | ||
config.unicode = flags && flags.includes('u'); | ||
const supportDotAllFlag = options && options.dotAllFlag; | ||
config.dotAll = supportDotAllFlag && flags && flags.includes('s'); | ||
config.namedGroup = options && options.namedGroup; | ||
config.useUnicodeFlag = options && options.useUnicodeFlag; | ||
config.unicodePropertyEscape = options && options.unicodePropertyEscape; | ||
const regenerateOptions = { | ||
@@ -319,0 +325,0 @@ 'hasUnicodeFlag': config.useUnicodeFlag, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
37714
1328