nav tabs on admin dashboard

This commit is contained in:
2019-03-07 00:20:34 -06:00
parent f73d6ae228
commit e4f473f376
11661 changed files with 216240 additions and 1544253 deletions

92
node_modules/regexpu-core/README.md generated vendored
View File

@@ -1,4 +1,4 @@
# regexpu-core [![Build status](https://travis-ci.org/mathiasbynens/regexpu-core.svg?branch=master)](https://travis-ci.org/mathiasbynens/regexpu-core) [![Code coverage status](http://img.shields.io/coveralls/mathiasbynens/regexpu-core/master.svg)](https://coveralls.io/r/mathiasbynens/regexpu-core) [![Dependency status](https://gemnasium.com/mathiasbynens/regexpu-core.svg)](https://gemnasium.com/mathiasbynens/regexpu-core)
# 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).
@@ -9,7 +9,7 @@ _regexpu-core_ contains _regexpu_s core functionality, i.e. `rewritePattern(p
To use _regexpu-core_ programmatically, install it as a dependency via [npm](https://www.npmjs.com/):
```bash
npm install regexpu-core --save-dev
npm install regexpu-core --save
```
Then, `require` it:
@@ -22,7 +22,7 @@ const rewritePattern = require('regexpu-core');
This module exports a single function named `rewritePattern`.
### `rewritePattern(pattern, flags)`
### `rewritePattern(pattern, flags, options)`
This function takes a string that represents a regular expression pattern as well as a string representing its flags, and returns an ES5-compatible version of the pattern.
@@ -49,7 +49,91 @@ rewritePattern('foo.bar', 'u');
// → 'foo(?:[\\0-\\t\\x0B\\f\\x0E-\\u2027\\u202A-\\uD7FF\\uDC00-\\uFFFF]|[\\uD800-\\uDBFF][\\uDC00-\\uDFFF]|[\\uD800-\\uDBFF])bar'
```
`rewritePattern` uses [regjsgen](https://github.com/d10/regjsgen), [regjsparser](https://github.com/jviereck/regjsparser), and [regenerate](https://github.com/mathiasbynens/regenerate) as internal dependencies.
The optional `options` argument recognizes the following properties:
#### `dotAllFlag` (default: `false`)
Setting this option to `true` enables experimental support for [the `s` (`dotAll`) flag](https://github.com/mathiasbynens/es-regexp-dotall-flag).
```js
rewritePattern('.');
// → '[\\0-\\t\\x0B\\f\\x0E-\\u2027\\u202A-\\uFFFF]'
rewritePattern('.', '', {
'dotAllFlag': true
});
// → '[\\0-\\t\\x0B\\f\\x0E-\\u2027\\u202A-\\uFFFF]'
rewritePattern('.', 's', {
'dotAllFlag': true
});
// → '[\\0-\\uFFFF]'
rewritePattern('.', 'su', {
'dotAllFlag': true
});
// → '(?:[\\0-\\uD7FF\\uE000-\\uFFFF]|[\\uD800-\\uDBFF][\\uDC00-\\uDFFF]|[\\uD800-\\uDBFF](?![\\uDC00-\\uDFFF])|(?:[^\\uD800-\\uDBFF]|^)[\\uDC00-\\uDFFF])'
```
#### `unicodePropertyEscape` (default: `false`)
Setting this option to `true` enables [experimental support for Unicode property escapes](property-escapes.md):
```js
rewritePattern('\\p{Script_Extensions=Anatolian_Hieroglyphs}', 'u', {
'unicodePropertyEscape': true
});
// → '(?:\\uD811[\\uDC00-\\uDE46])'
```
#### `lookbehind` (default: `false`)
Setting this option to `true` enables experimental support for [lookbehind assertions](https://github.com/tc39/proposal-regexp-lookbehind).
```js
rewritePattern('(?<=.)a', '', {
'lookbehind': true
});
// → '(?<=[\\0-\\t\\x0B\\f\\x0E-\\u2027\\u202A-\\uFFFF])a'
```
#### `namedGroup` (default: `false`)
Setting this option to `true` enables experimental support for [named capture groups](https://github.com/tc39/proposal-regexp-named-groups).
```js
rewritePattern('(?<name>.)\k<name>', '', {
'namedGroups': true
});
// → '(.)\1'
```
#### `onNamedGroup`
This option is a function that gets called when a named capture group is found. It receives two parameters:
the name of the group, and its index.
```js
rewritePattern('(?<name>.)\k<name>', '', {
'namedGroups': true,
onNamedGroup(name, index) {
console.log(name, index);
// → 'name', 1
}
});
```
#### `useUnicodeFlag` (default: `false`)
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.
```js
rewritePattern('\\p{Script_Extensions=Anatolian_Hieroglyphs}', 'u', {
'unicodePropertyEscape': true,
'useUnicodeFlag': true
});
// → '[\\u{14400}-\\u{14646}]'
```
## Author

View File

@@ -1,17 +1,19 @@
// Generated by `/scripts/character-class-escape-sets.js`. Do not edit.
var regenerate = require('regenerate');
// Generated using `npm run build`. Do not edit.
'use strict';
exports.REGULAR = {
'd': regenerate()
.addRange(0x30, 0x39),
'D': regenerate()
const regenerate = require('regenerate');
exports.REGULAR = new Map([
['d', regenerate()
.addRange(0x30, 0x39)],
['D', regenerate()
.addRange(0x0, 0x2F)
.addRange(0x3A, 0xFFFF),
's': regenerate(0x20, 0xA0, 0x1680, 0x202F, 0x205F, 0x3000, 0xFEFF)
.addRange(0x3A, 0xFFFF)],
['s', regenerate(0x20, 0xA0, 0x1680, 0x202F, 0x205F, 0x3000, 0xFEFF)
.addRange(0x9, 0xD)
.addRange(0x2000, 0x200A)
.addRange(0x2028, 0x2029),
'S': regenerate()
.addRange(0x2028, 0x2029)],
['S', regenerate()
.addRange(0x0, 0x8)
.addRange(0xE, 0x1F)
.addRange(0x21, 0x9F)
@@ -22,29 +24,29 @@ exports.REGULAR = {
.addRange(0x2030, 0x205E)
.addRange(0x2060, 0x2FFF)
.addRange(0x3001, 0xFEFE)
.addRange(0xFF00, 0xFFFF),
'w': regenerate(0x5F)
.addRange(0xFF00, 0xFFFF)],
['w', regenerate(0x5F)
.addRange(0x30, 0x39)
.addRange(0x41, 0x5A)
.addRange(0x61, 0x7A),
'W': regenerate(0x60)
.addRange(0x61, 0x7A)],
['W', regenerate(0x60)
.addRange(0x0, 0x2F)
.addRange(0x3A, 0x40)
.addRange(0x5B, 0x5E)
.addRange(0x7B, 0xFFFF)
};
.addRange(0x7B, 0xFFFF)]
]);
exports.UNICODE = {
'd': regenerate()
.addRange(0x30, 0x39),
'D': regenerate()
exports.UNICODE = new Map([
['d', regenerate()
.addRange(0x30, 0x39)],
['D', regenerate()
.addRange(0x0, 0x2F)
.addRange(0x3A, 0x10FFFF),
's': regenerate(0x20, 0xA0, 0x1680, 0x202F, 0x205F, 0x3000, 0xFEFF)
.addRange(0x3A, 0x10FFFF)],
['s', regenerate(0x20, 0xA0, 0x1680, 0x202F, 0x205F, 0x3000, 0xFEFF)
.addRange(0x9, 0xD)
.addRange(0x2000, 0x200A)
.addRange(0x2028, 0x2029),
'S': regenerate()
.addRange(0x2028, 0x2029)],
['S', regenerate()
.addRange(0x0, 0x8)
.addRange(0xE, 0x1F)
.addRange(0x21, 0x9F)
@@ -55,29 +57,29 @@ exports.UNICODE = {
.addRange(0x2030, 0x205E)
.addRange(0x2060, 0x2FFF)
.addRange(0x3001, 0xFEFE)
.addRange(0xFF00, 0x10FFFF),
'w': regenerate(0x5F)
.addRange(0xFF00, 0x10FFFF)],
['w', regenerate(0x5F)
.addRange(0x30, 0x39)
.addRange(0x41, 0x5A)
.addRange(0x61, 0x7A),
'W': regenerate(0x60)
.addRange(0x61, 0x7A)],
['W', regenerate(0x60)
.addRange(0x0, 0x2F)
.addRange(0x3A, 0x40)
.addRange(0x5B, 0x5E)
.addRange(0x7B, 0x10FFFF)
};
.addRange(0x7B, 0x10FFFF)]
]);
exports.UNICODE_IGNORE_CASE = {
'd': regenerate()
.addRange(0x30, 0x39),
'D': regenerate()
exports.UNICODE_IGNORE_CASE = new Map([
['d', regenerate()
.addRange(0x30, 0x39)],
['D', regenerate()
.addRange(0x0, 0x2F)
.addRange(0x3A, 0x10FFFF),
's': regenerate(0x20, 0xA0, 0x1680, 0x202F, 0x205F, 0x3000, 0xFEFF)
.addRange(0x3A, 0x10FFFF)],
['s', regenerate(0x20, 0xA0, 0x1680, 0x202F, 0x205F, 0x3000, 0xFEFF)
.addRange(0x9, 0xD)
.addRange(0x2000, 0x200A)
.addRange(0x2028, 0x2029),
'S': regenerate()
.addRange(0x2028, 0x2029)],
['S', regenerate()
.addRange(0x0, 0x8)
.addRange(0xE, 0x1F)
.addRange(0x21, 0x9F)
@@ -88,14 +90,16 @@ exports.UNICODE_IGNORE_CASE = {
.addRange(0x2030, 0x205E)
.addRange(0x2060, 0x2FFF)
.addRange(0x3001, 0xFEFE)
.addRange(0xFF00, 0x10FFFF),
'w': regenerate(0x5F, 0x17F, 0x212A)
.addRange(0xFF00, 0x10FFFF)],
['w', regenerate(0x5F, 0x17F, 0x212A)
.addRange(0x30, 0x39)
.addRange(0x41, 0x5A)
.addRange(0x61, 0x7A),
'W': regenerate(0x4B, 0x53, 0x60)
.addRange(0x61, 0x7A)],
['W', regenerate(0x60)
.addRange(0x0, 0x2F)
.addRange(0x3A, 0x40)
.addRange(0x5B, 0x5E)
.addRange(0x7B, 0x10FFFF)
};
.addRange(0x7B, 0x17E)
.addRange(0x180, 0x2129)
.addRange(0x212B, 0x10FFFF)]
]);

View File

@@ -1,296 +0,0 @@
{
"75": 8490,
"83": 383,
"107": 8490,
"115": 383,
"181": 924,
"197": 8491,
"383": 83,
"452": 453,
"453": 452,
"455": 456,
"456": 455,
"458": 459,
"459": 458,
"497": 498,
"498": 497,
"837": 8126,
"914": 976,
"917": 1013,
"920": 1012,
"921": 8126,
"922": 1008,
"924": 181,
"928": 982,
"929": 1009,
"931": 962,
"934": 981,
"937": 8486,
"962": 931,
"976": 914,
"977": 1012,
"981": 934,
"982": 928,
"1008": 922,
"1009": 929,
"1012": [
920,
977
],
"1013": 917,
"7776": 7835,
"7835": 7776,
"8126": [
837,
921
],
"8486": 937,
"8490": 75,
"8491": 197,
"66560": 66600,
"66561": 66601,
"66562": 66602,
"66563": 66603,
"66564": 66604,
"66565": 66605,
"66566": 66606,
"66567": 66607,
"66568": 66608,
"66569": 66609,
"66570": 66610,
"66571": 66611,
"66572": 66612,
"66573": 66613,
"66574": 66614,
"66575": 66615,
"66576": 66616,
"66577": 66617,
"66578": 66618,
"66579": 66619,
"66580": 66620,
"66581": 66621,
"66582": 66622,
"66583": 66623,
"66584": 66624,
"66585": 66625,
"66586": 66626,
"66587": 66627,
"66588": 66628,
"66589": 66629,
"66590": 66630,
"66591": 66631,
"66592": 66632,
"66593": 66633,
"66594": 66634,
"66595": 66635,
"66596": 66636,
"66597": 66637,
"66598": 66638,
"66599": 66639,
"66600": 66560,
"66601": 66561,
"66602": 66562,
"66603": 66563,
"66604": 66564,
"66605": 66565,
"66606": 66566,
"66607": 66567,
"66608": 66568,
"66609": 66569,
"66610": 66570,
"66611": 66571,
"66612": 66572,
"66613": 66573,
"66614": 66574,
"66615": 66575,
"66616": 66576,
"66617": 66577,
"66618": 66578,
"66619": 66579,
"66620": 66580,
"66621": 66581,
"66622": 66582,
"66623": 66583,
"66624": 66584,
"66625": 66585,
"66626": 66586,
"66627": 66587,
"66628": 66588,
"66629": 66589,
"66630": 66590,
"66631": 66591,
"66632": 66592,
"66633": 66593,
"66634": 66594,
"66635": 66595,
"66636": 66596,
"66637": 66597,
"66638": 66598,
"66639": 66599,
"68736": 68800,
"68737": 68801,
"68738": 68802,
"68739": 68803,
"68740": 68804,
"68741": 68805,
"68742": 68806,
"68743": 68807,
"68744": 68808,
"68745": 68809,
"68746": 68810,
"68747": 68811,
"68748": 68812,
"68749": 68813,
"68750": 68814,
"68751": 68815,
"68752": 68816,
"68753": 68817,
"68754": 68818,
"68755": 68819,
"68756": 68820,
"68757": 68821,
"68758": 68822,
"68759": 68823,
"68760": 68824,
"68761": 68825,
"68762": 68826,
"68763": 68827,
"68764": 68828,
"68765": 68829,
"68766": 68830,
"68767": 68831,
"68768": 68832,
"68769": 68833,
"68770": 68834,
"68771": 68835,
"68772": 68836,
"68773": 68837,
"68774": 68838,
"68775": 68839,
"68776": 68840,
"68777": 68841,
"68778": 68842,
"68779": 68843,
"68780": 68844,
"68781": 68845,
"68782": 68846,
"68783": 68847,
"68784": 68848,
"68785": 68849,
"68786": 68850,
"68800": 68736,
"68801": 68737,
"68802": 68738,
"68803": 68739,
"68804": 68740,
"68805": 68741,
"68806": 68742,
"68807": 68743,
"68808": 68744,
"68809": 68745,
"68810": 68746,
"68811": 68747,
"68812": 68748,
"68813": 68749,
"68814": 68750,
"68815": 68751,
"68816": 68752,
"68817": 68753,
"68818": 68754,
"68819": 68755,
"68820": 68756,
"68821": 68757,
"68822": 68758,
"68823": 68759,
"68824": 68760,
"68825": 68761,
"68826": 68762,
"68827": 68763,
"68828": 68764,
"68829": 68765,
"68830": 68766,
"68831": 68767,
"68832": 68768,
"68833": 68769,
"68834": 68770,
"68835": 68771,
"68836": 68772,
"68837": 68773,
"68838": 68774,
"68839": 68775,
"68840": 68776,
"68841": 68777,
"68842": 68778,
"68843": 68779,
"68844": 68780,
"68845": 68781,
"68846": 68782,
"68847": 68783,
"68848": 68784,
"68849": 68785,
"68850": 68786,
"71840": 71872,
"71841": 71873,
"71842": 71874,
"71843": 71875,
"71844": 71876,
"71845": 71877,
"71846": 71878,
"71847": 71879,
"71848": 71880,
"71849": 71881,
"71850": 71882,
"71851": 71883,
"71852": 71884,
"71853": 71885,
"71854": 71886,
"71855": 71887,
"71856": 71888,
"71857": 71889,
"71858": 71890,
"71859": 71891,
"71860": 71892,
"71861": 71893,
"71862": 71894,
"71863": 71895,
"71864": 71896,
"71865": 71897,
"71866": 71898,
"71867": 71899,
"71868": 71900,
"71869": 71901,
"71870": 71902,
"71871": 71903,
"71872": 71840,
"71873": 71841,
"71874": 71842,
"71875": 71843,
"71876": 71844,
"71877": 71845,
"71878": 71846,
"71879": 71847,
"71880": 71848,
"71881": 71849,
"71882": 71850,
"71883": 71851,
"71884": 71852,
"71885": 71853,
"71886": 71854,
"71887": 71855,
"71888": 71856,
"71889": 71857,
"71890": 71858,
"71891": 71859,
"71892": 71860,
"71893": 71861,
"71894": 71862,
"71895": 71863,
"71896": 71864,
"71897": 71865,
"71898": 71866,
"71899": 71867,
"71900": 71868,
"71901": 71869,
"71902": 71870,
"71903": 71871
}

View File

@@ -1,27 +1,29 @@
{
"_from": "regexpu-core@^2.0.0",
"_id": "regexpu-core@2.0.0",
"_from": "regexpu-core@^4.2.0",
"_id": "regexpu-core@4.5.3",
"_inBundle": false,
"_integrity": "sha1-SdA4g3uNz4v6W5pCE5k45uoq4kA=",
"_integrity": "sha512-LON8666bTAlViVEPXMv65ZqiaR3rMNLz36PIaQ7D+er5snu93k0peR7FSvO0QteYbZ3GOkvfHKbGr/B1xDu9FA==",
"_location": "/regexpu-core",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "regexpu-core@^2.0.0",
"raw": "regexpu-core@^4.2.0",
"name": "regexpu-core",
"escapedName": "regexpu-core",
"rawSpec": "^2.0.0",
"rawSpec": "^4.2.0",
"saveSpec": null,
"fetchSpec": "^2.0.0"
"fetchSpec": "^4.2.0"
},
"_requiredBy": [
"/babel-plugin-transform-es2015-unicode-regex"
"/@babel/plugin-proposal-unicode-property-regex",
"/@babel/plugin-transform-dotall-regex",
"/@babel/plugin-transform-unicode-regex"
],
"_resolved": "https://registry.npmjs.org/regexpu-core/-/regexpu-core-2.0.0.tgz",
"_shasum": "49d038837b8dcf8bfa5b9a42139938e6ea2ae240",
"_spec": "regexpu-core@^2.0.0",
"_where": "C:\\xampp\\htdocs\\w4rpservices\\node_modules\\babel-plugin-transform-es2015-unicode-regex",
"_resolved": "https://registry.npmjs.org/regexpu-core/-/regexpu-core-4.5.3.tgz",
"_shasum": "72f572e03bb8b9f4f4d895a0ccc57e707f4af2e4",
"_spec": "regexpu-core@^4.2.0",
"_where": "C:\\xampp\\htdocs\\w4rpservices\\node_modules\\@babel\\plugin-proposal-unicode-property-regex",
"author": {
"name": "Mathias Bynens",
"url": "https://mathiasbynens.be/"
@@ -31,26 +33,32 @@
},
"bundleDependencies": false,
"dependencies": {
"regenerate": "^1.2.1",
"regjsgen": "^0.2.0",
"regjsparser": "^0.1.4"
"regenerate": "^1.4.0",
"regenerate-unicode-properties": "^8.0.1",
"regjsgen": "^0.5.0",
"regjsparser": "^0.6.0",
"unicode-match-property-ecmascript": "^1.0.4",
"unicode-match-property-value-ecmascript": "^1.1.0"
},
"deprecated": false,
"description": "regexpus core functionality (i.e. `rewritePattern(pattern, flag)`), capable of translating ES6 Unicode regular expressions to ES5.",
"devDependencies": {
"coveralls": "^2.11.2",
"istanbul": "^0.4.0",
"jsesc": "^0.5.0",
"lodash": "^3.6.0",
"mocha": "^2.2.1",
"regexpu-fixtures": "^2.0.0",
"unicode-8.0.0": "^0.1.5"
"codecov": "^3.2.0",
"istanbul": "^0.4.5",
"jsesc": "^2.5.2",
"lodash": "^4.17.11",
"mocha": "^6.0.2",
"regexpu-fixtures": "^2.1.2",
"unicode-12.0.0": "^0.7.9"
},
"engines": {
"node": ">=4"
},
"files": [
"LICENSE-MIT.txt",
"rewrite-pattern.js",
"data/character-class-escape-sets.js",
"data/iu-mappings.json"
"data/iu-mappings.js"
],
"homepage": "https://mths.be/regexpu",
"keywords": [
@@ -81,8 +89,8 @@
},
"scripts": {
"build": "node scripts/iu-mappings.js && node scripts/character-class-escape-sets.js",
"coverage": "istanbul cover --report html node_modules/.bin/_mocha tests/tests.js -- -u exports -R spec",
"cover": "istanbul cover --report html node_modules/.bin/_mocha tests -- -u exports -R spec",
"test": "mocha tests"
},
"version": "2.0.0"
"version": "4.5.3"
}

View File

@@ -1,35 +1,23 @@
var generate = require('regjsgen').generate;
var parse = require('regjsparser').parse;
var regenerate = require('regenerate');
var iuMappings = require('./data/iu-mappings.json');
var ESCAPE_SETS = require('./data/character-class-escape-sets.js');
'use strict';
function getCharacterClassEscapeSet(character) {
if (unicode) {
if (ignoreCase) {
return ESCAPE_SETS.UNICODE_IGNORE_CASE[character];
}
return ESCAPE_SETS.UNICODE[character];
}
return ESCAPE_SETS.REGULAR[character];
}
var object = {};
var hasOwnProperty = object.hasOwnProperty;
function has(object, property) {
return hasOwnProperty.call(object, property);
}
const generate = require('regjsgen').generate;
const parse = require('regjsparser').parse;
const regenerate = require('regenerate');
const unicodeMatchProperty = require('unicode-match-property-ecmascript');
const unicodeMatchPropertyValue = require('unicode-match-property-value-ecmascript');
const iuMappings = require('./data/iu-mappings.js');
const ESCAPE_SETS = require('./data/character-class-escape-sets.js');
// Prepare a Regenerate set containing all code points, used for negative
// character classes (if any).
var UNICODE_SET = regenerate().addRange(0x0, 0x10FFFF);
const UNICODE_SET = regenerate().addRange(0x0, 0x10FFFF);
// Without the `u` flag, the range stops at 0xFFFF.
// https://mths.be/es6#sec-pattern-semantics
var BMP_SET = regenerate().addRange(0x0, 0xFFFF);
const BMP_SET = regenerate().addRange(0x0, 0xFFFF);
// Prepare a Regenerate set containing all code points that are supposed to be
// matched by `/./u`. https://mths.be/es6#sec-atom
var DOT_SET_UNICODE = UNICODE_SET.clone() // all Unicode code points
const DOT_SET_UNICODE = UNICODE_SET.clone() // all Unicode code points
.remove(
// minus `LineTerminator`s (https://mths.be/es6#sec-line-terminators):
0x000A, // Line Feed <LF>
@@ -39,15 +27,78 @@ var DOT_SET_UNICODE = UNICODE_SET.clone() // all Unicode code points
);
// Prepare a Regenerate set containing all code points that are supposed to be
// matched by `/./` (only BMP code points).
var DOT_SET = DOT_SET_UNICODE.clone()
const DOT_SET = DOT_SET_UNICODE.clone()
.intersection(BMP_SET);
// Add a range of code points + any case-folded code points in that range to a
// set.
const getCharacterClassEscapeSet = (character, unicode, ignoreCase) => {
if (unicode) {
if (ignoreCase) {
return ESCAPE_SETS.UNICODE_IGNORE_CASE.get(character);
}
return ESCAPE_SETS.UNICODE.get(character);
}
return ESCAPE_SETS.REGULAR.get(character);
};
const getDotSet = (unicode, dotAll) => {
if (dotAll) {
return unicode ? UNICODE_SET : BMP_SET;
}
return unicode ? DOT_SET_UNICODE : DOT_SET;
};
const getUnicodePropertyValueSet = (property, value) => {
const path = value ?
`${ property }/${ value }` :
`Binary_Property/${ property }`;
try {
return require(`regenerate-unicode-properties/${ path }.js`);
} catch (exception) {
throw new Error(
`Failed to recognize value \`${ value }\` for property ` +
`\`${ property }\`.`
);
}
};
const handleLoneUnicodePropertyNameOrValue = (value) => {
// It could be a `General_Category` value or a binary property.
// Note: `unicodeMatchPropertyValue` throws on invalid values.
try {
const property = 'General_Category';
const category = unicodeMatchPropertyValue(property, value);
return getUnicodePropertyValueSet(property, category);
} catch (exception) {}
// Its not a `General_Category` value, so check if its a binary
// property. Note: `unicodeMatchProperty` throws on invalid properties.
const property = unicodeMatchProperty(value);
return getUnicodePropertyValueSet(property);
};
const getUnicodePropertyEscapeSet = (value, isNegative) => {
const parts = value.split('=');
const firstPart = parts[0];
let set;
if (parts.length == 1) {
set = handleLoneUnicodePropertyNameOrValue(firstPart);
} else {
// The pattern consists of two parts, i.e. `Property=Value`.
const property = unicodeMatchProperty(firstPart);
const value = unicodeMatchPropertyValue(property, parts[1]);
set = getUnicodePropertyValueSet(property, value);
}
if (isNegative) {
return UNICODE_SET.clone().remove(set);
}
return set.clone();
};
// Given a range of code points, add any case-folded code points in that range
// to a set.
regenerate.prototype.iuAddRange = function(min, max) {
var $this = this;
const $this = this;
do {
var folded = caseFold(min);
const folded = caseFold(min);
if (folded) {
$this.add(folded);
}
@@ -55,19 +106,8 @@ regenerate.prototype.iuAddRange = function(min, max) {
return $this;
};
function assign(target, source) {
for (var key in source) {
// Note: `hasOwnProperty` is not needed here.
target[key] = source[key];
}
}
function update(item, pattern) {
// TODO: Test if memoizing `pattern` here is worth the effort.
if (!pattern) {
return;
}
var tree = parse(pattern, '');
const update = (item, pattern) => {
let tree = parse(pattern, config.useUnicodeFlag ? 'u' : '');
switch (tree.type) {
case 'characterClass':
case 'group':
@@ -78,116 +118,215 @@ function update(item, pattern) {
// Wrap the pattern in a non-capturing group.
tree = wrap(tree, pattern);
}
assign(item, tree);
}
Object.assign(item, tree);
};
function wrap(tree, pattern) {
const wrap = (tree, pattern) => {
// Wrap the pattern in a non-capturing group.
return {
'type': 'group',
'behavior': 'ignore',
'body': [tree],
'raw': '(?:' + pattern + ')'
'raw': `(?:${ pattern })`
};
}
};
function caseFold(codePoint) {
return has(iuMappings, codePoint) ? iuMappings[codePoint] : false;
}
const caseFold = (codePoint) => {
return iuMappings.get(codePoint) || false;
};
var ignoreCase = false;
var unicode = false;
function processCharacterClass(characterClassItem) {
var set = regenerate();
var body = characterClassItem.body.forEach(function(item) {
const processCharacterClass = (characterClassItem, regenerateOptions) => {
let set = regenerate();
for (const item of characterClassItem.body) {
switch (item.type) {
case 'value':
set.add(item.codePoint);
if (ignoreCase && unicode) {
var folded = caseFold(item.codePoint);
if (config.ignoreCase && config.unicode && !config.useUnicodeFlag) {
const folded = caseFold(item.codePoint);
if (folded) {
set.add(folded);
}
}
break;
case 'characterClassRange':
var min = item.min.codePoint;
var max = item.max.codePoint;
const min = item.min.codePoint;
const max = item.max.codePoint;
set.addRange(min, max);
if (ignoreCase && unicode) {
if (config.ignoreCase && config.unicode && !config.useUnicodeFlag) {
set.iuAddRange(min, max);
}
break;
case 'characterClassEscape':
set.add(getCharacterClassEscapeSet(item.value));
set.add(getCharacterClassEscapeSet(
item.value,
config.unicode,
config.ignoreCase
));
break;
case 'unicodePropertyEscape':
set.add(getUnicodePropertyEscapeSet(item.value, item.negative));
break;
// The `default` clause is only here as a safeguard; it should never be
// reached. Code coverage tools should ignore it.
/* istanbul ignore next */
default:
throw Error('Unknown term type: ' + item.type);
throw new Error(`Unknown term type: ${ item.type }`);
}
});
if (characterClassItem.negative) {
set = (unicode ? UNICODE_SET : BMP_SET).clone().remove(set);
}
update(characterClassItem, set.toString());
if (characterClassItem.negative) {
set = (config.unicode ? UNICODE_SET : BMP_SET).clone().remove(set);
}
update(characterClassItem, set.toString(regenerateOptions));
return characterClassItem;
}
};
function processTerm(item) {
const updateNamedReference = (item, index) => {
delete item.name;
item.matchIndex = index;
};
const assertNoUnmatchedReferences = (groups) => {
const unmatchedReferencesNames = Object.keys(groups.unmatchedReferences);
if (unmatchedReferencesNames.length > 0) {
throw new Error(`Unknown group names: ${unmatchedReferencesNames}`);
}
};
const processTerm = (item, regenerateOptions, groups) => {
switch (item.type) {
case 'dot':
update(
item,
(unicode ? DOT_SET_UNICODE : DOT_SET).toString()
getDotSet(config.unicode, config.dotAll).toString(regenerateOptions)
);
break;
case 'characterClass':
item = processCharacterClass(item);
item = processCharacterClass(item, regenerateOptions);
break;
case 'unicodePropertyEscape':
update(
item,
getUnicodePropertyEscapeSet(item.value, item.negative)
.toString(regenerateOptions)
);
break;
case 'characterClassEscape':
update(
item,
getCharacterClassEscapeSet(item.value).toString()
getCharacterClassEscapeSet(
item.value,
config.unicode,
config.ignoreCase
).toString(regenerateOptions)
);
break;
case 'group':
groups.lastIndex++;
if (item.name) {
const name = item.name.value;
if (groups.names[name]) {
throw new Error(
`Multiple groups with the same name (${ name }) are not allowed.`
);
}
const index = groups.lastIndex;
delete item.name;
groups.names[name] = index;
if (groups.onNamedGroup) {
groups.onNamedGroup.call(null, name, index);
}
if (groups.unmatchedReferences[name]) {
groups.unmatchedReferences[name].forEach(reference => {
updateNamedReference(reference, index);
});
delete groups.unmatchedReferences[name];
}
}
/* falls through */
case 'alternative':
case 'disjunction':
case 'group':
case 'quantifier':
item.body = item.body.map(processTerm);
item.body = item.body.map(term => {
return processTerm(term, regenerateOptions, groups);
});
break;
case 'value':
var codePoint = item.codePoint;
var set = regenerate(codePoint);
if (ignoreCase && unicode) {
var folded = caseFold(codePoint);
const codePoint = item.codePoint;
const set = regenerate(codePoint);
if (config.ignoreCase && config.unicode && !config.useUnicodeFlag) {
const folded = caseFold(codePoint);
if (folded) {
set.add(folded);
}
}
update(item, set.toString());
update(item, set.toString(regenerateOptions));
break;
case 'reference':
if (item.name) {
const name = item.name.value;
const index = groups.names[name];
if (index) {
updateNamedReference(item, index);
break;
}
if (!groups.unmatchedReferences[name]) {
groups.unmatchedReferences[name] = [];
}
// Keep track of references used before the corresponding group.
groups.unmatchedReferences[name].push(item);
}
break;
case 'anchor':
case 'empty':
case 'group':
case 'reference':
// Nothing to do here.
break;
// The `default` clause is only here as a safeguard; it should never be
// reached. Code coverage tools should ignore it.
/* istanbul ignore next */
default:
throw Error('Unknown term type: ' + item.type);
throw new Error(`Unknown term type: ${ item.type }`);
}
return item;
};
module.exports = function(pattern, flags) {
var tree = parse(pattern, flags);
ignoreCase = flags ? flags.indexOf('i') > -1 : false;
unicode = flags ? flags.indexOf('u') > -1 : false;
assign(tree, processTerm(tree));
const config = {
'ignoreCase': false,
'unicode': false,
'dotAll': false,
'useUnicodeFlag': false
};
const rewritePattern = (pattern, flags, options) => {
const regjsparserFeatures = {
'unicodePropertyEscape': options && options.unicodePropertyEscape,
'namedGroups': options && options.namedGroup,
'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.useUnicodeFlag = options && options.useUnicodeFlag;
const regenerateOptions = {
'hasUnicodeFlag': config.useUnicodeFlag,
'bmpOnly': !config.unicode
};
const groups = {
'onNamedGroup': options && options.onNamedGroup,
'lastIndex': 0,
'names': Object.create(null), // { [name]: index }
'unmatchedReferences': Object.create(null) // { [name]: Array<reference> }
};
const tree = parse(pattern, flags, regjsparserFeatures);
// Note: `processTerm` mutates `tree` and `groups`.
processTerm(tree, regenerateOptions, groups);
assertNoUnmatchedReferences(groups);
return generate(tree);
};
module.exports = rewritePattern;