@ptolemy2002/rgx 7.6.0 → 7.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -1376,6 +1376,12 @@ A pre-built `RegExpFlagTransformer` that makes a regex pattern accent-insensitiv
|
|
|
1376
1376
|
|
|
1377
1377
|
Note that this transformer intentionally excludes replacing characters preceded by an odd number of backslashes, to allow for escaping. For example, in the pattern `\\a`, the `a` is preceded by two backslashes (an even number), so it will be replaced with `(a|á|à|ä|â|ã)`. In the pattern `\a`, the `a` is preceded by one backslash (an odd number), so it will not be replaced.
|
|
1378
1378
|
|
|
1379
|
+
Also, characters part of a localized flag diff inline modifier (e.g., `(?i:a)`) are not replaced, as that would introduce invalid syntax. This refers to the `i` here, not the `a`, since only `i` is a localizable flag.
|
|
1380
|
+
|
|
1381
|
+
Finally, characters part of a character class are avoided for transformation, since that would introduce syntax errors again. For example, in the pattern `[a]`, the `a` is part of a character class and will not be replaced.
|
|
1382
|
+
|
|
1383
|
+
These conditions (especially the last two) may cause some patterns that should be transformed to be skipped, but that is better than having the transformer produce invalid regex patterns.
|
|
1384
|
+
|
|
1379
1385
|
#### Parameters
|
|
1380
1386
|
- `exp` (`RegExp`): The regular expression to transform.
|
|
1381
1387
|
|
|
@@ -10,13 +10,23 @@ const accentPatterns = [
|
|
|
10
10
|
"(o|ó|ò|ö|ô|õ)", "(O|Ó|Ò|Ö|Ô|Õ)",
|
|
11
11
|
"(u|ú|ù|ü|û)", "(U|Ú|Ù|Ü|Û)"
|
|
12
12
|
];
|
|
13
|
+
const nonEscapeBound = (0, resolve_1.resolveRGXToken)((0, constants_1.rgxConstant)("non-escape-bound"));
|
|
14
|
+
const nonLocalizedFlagBound = (0, resolve_1.resolveRGXToken)({
|
|
15
|
+
rgxGroupWrap: false,
|
|
16
|
+
rgxIsRepeatable: false,
|
|
17
|
+
toRgx() { return /(?<!\(\?\-?[ims]*)/; }
|
|
18
|
+
});
|
|
19
|
+
const nonCharacterClassBound = (0, resolve_1.resolveRGXToken)({
|
|
20
|
+
rgxGroupWrap: false,
|
|
21
|
+
rgxIsRepeatable: false,
|
|
22
|
+
toRgx() { return /(?<!\[[^\]]*)/; }
|
|
23
|
+
});
|
|
13
24
|
const accentInsensitiveFlagTransformer = function (exp) {
|
|
14
25
|
let source = exp.source;
|
|
15
26
|
const flags = exp.flags;
|
|
16
|
-
const nonEscapeBound = (0, resolve_1.resolveRGXToken)((0, constants_1.rgxConstant)("non-escape-bound"));
|
|
17
27
|
accentPatterns.forEach((pattern) => {
|
|
18
28
|
// Replace any of the characters in the pattern with the pattern itself
|
|
19
|
-
source = source.replaceAll(new RegExp(nonEscapeBound + pattern, "g"), pattern);
|
|
29
|
+
source = source.replaceAll(new RegExp(nonEscapeBound + nonLocalizedFlagBound + nonCharacterClassBound + pattern, "g"), pattern);
|
|
20
30
|
});
|
|
21
31
|
return new RegExp(source, flags);
|
|
22
32
|
};
|
package/dist/walker/base.js
CHANGED
|
@@ -138,7 +138,11 @@ class RGXWalker {
|
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
}
|
|
141
|
-
const captureResult = {
|
|
141
|
+
const captureResult = {
|
|
142
|
+
raw, value, start, end, branch,
|
|
143
|
+
ownerId: isPart && token.hasId() ? token.id : null,
|
|
144
|
+
groups: isPart ? capture.groups ?? null : null
|
|
145
|
+
};
|
|
142
146
|
// Validate the part. If validation fails, it will throw an error, so nothing below will run.
|
|
143
147
|
if (isPart) {
|
|
144
148
|
token.validate(captureResult, this);
|
package/dist/walker/part.d.ts
CHANGED