regex-partial-match 1.1.2 → 1.3.0
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 +151 -10
- package/lib/{extend.d.ts → extend/index.d.ts} +1 -1
- package/lib/{extend.js → extend/index.js} +1 -1
- package/lib/partialMatchRegExp/atomSyntax.d.ts +4 -0
- package/lib/partialMatchRegExp/atomSyntax.js +4 -0
- package/lib/partialMatchRegExp/backreferenceExpansion.d.ts +10 -0
- package/lib/partialMatchRegExp/backreferenceExpansion.js +1 -0
- package/lib/partialMatchRegExp/compilePartial/asNativeAtom.d.ts +2 -0
- package/lib/partialMatchRegExp/compilePartial/asNativeAtom.js +10 -0
- package/lib/partialMatchRegExp/compilePartial/asOptionalAtom.d.ts +1 -0
- package/lib/partialMatchRegExp/compilePartial/asOptionalAtom.js +4 -0
- package/lib/partialMatchRegExp/compilePartial/asPreScanPart.d.ts +2 -0
- package/lib/partialMatchRegExp/compilePartial/asPreScanPart.js +8 -0
- package/lib/partialMatchRegExp/compilePartial/caseFoldFlags.d.ts +1 -0
- package/lib/partialMatchRegExp/compilePartial/caseFoldFlags.js +3 -0
- package/lib/partialMatchRegExp/compilePartial/compiled.d.ts +29 -0
- package/lib/partialMatchRegExp/compilePartial/compiled.js +27 -0
- package/lib/partialMatchRegExp/compilePartial/flagsAtBackreference.d.ts +2 -0
- package/lib/partialMatchRegExp/compilePartial/flagsAtBackreference.js +4 -0
- package/lib/partialMatchRegExp/compilePartial/index.d.ts +2 -0
- package/lib/partialMatchRegExp/compilePartial/index.js +79 -0
- package/lib/partialMatchRegExp/compilePartial/longestBakedPrefixEndingInput.d.ts +1 -0
- package/lib/partialMatchRegExp/compilePartial/longestBakedPrefixEndingInput.js +50 -0
- package/lib/partialMatchRegExp/compilePartial/reclassifyLegacyEscapes.d.ts +2 -0
- package/lib/partialMatchRegExp/compilePartial/reclassifyLegacyEscapes.js +17 -0
- package/lib/partialMatchRegExp/compilePartial/renderParts.d.ts +2 -0
- package/lib/partialMatchRegExp/compilePartial/renderParts.js +9 -0
- package/lib/partialMatchRegExp/compilePartial/resolvedFromScan.d.ts +2 -0
- package/lib/partialMatchRegExp/compilePartial/resolvedFromScan.js +10 -0
- package/lib/partialMatchRegExp/compilePartial/spliceOriginalSource.d.ts +2 -0
- package/lib/partialMatchRegExp/compilePartial/spliceOriginalSource.js +12 -0
- package/lib/partialMatchRegExp/compilePartial/startsWithUnderFlags.d.ts +1 -0
- package/lib/partialMatchRegExp/compilePartial/startsWithUnderFlags.js +7 -0
- package/lib/partialMatchRegExp/compilePartial/toStatic.d.ts +3 -0
- package/lib/partialMatchRegExp/compilePartial/toStatic.js +4 -0
- package/lib/partialMatchRegExp/groupName.d.ts +2 -0
- package/lib/partialMatchRegExp/groupName.js +8 -0
- package/lib/partialMatchRegExp/index.d.ts +3 -0
- package/lib/partialMatchRegExp/index.js +3 -0
- package/lib/partialMatchRegExp/isComplete/index.d.ts +38 -0
- package/lib/partialMatchRegExp/isComplete/index.js +41 -0
- package/lib/partialMatchRegExp/isComplete/isMatchComplete.d.ts +3 -0
- package/lib/partialMatchRegExp/isComplete/isMatchComplete.js +14 -0
- package/lib/partialMatchRegExp/isComplete/partRole.d.ts +3 -0
- package/lib/partialMatchRegExp/isComplete/partRole.js +28 -0
- package/lib/partialMatchRegExp/isComplete/truncationProbe.d.ts +8 -0
- package/lib/partialMatchRegExp/isComplete/truncationProbe.js +105 -0
- package/lib/partialMatchRegExp/isComplete/truncationProbeCache.d.ts +4 -0
- package/lib/partialMatchRegExp/isComplete/truncationProbeCache.js +1 -0
- package/lib/partialMatchRegExp/legacyEscape.d.ts +2 -0
- package/lib/partialMatchRegExp/legacyEscape.js +18 -0
- package/lib/partialMatchRegExp/part.d.ts +24 -0
- package/lib/partialMatchRegExp/part.js +2 -0
- package/lib/partialMatchRegExp/partialMatchInternals.d.ts +2 -0
- package/lib/partialMatchRegExp/partialMatchInternals.js +2 -0
- package/lib/{partialMatchRegExp.d.ts → partialMatchRegExp/partialMatchRegExp.d.ts} +22 -3
- package/lib/partialMatchRegExp/partialMatchRegExp.js +114 -0
- package/lib/partialMatchRegExp/preferLongerCaptures.d.ts +1 -0
- package/lib/partialMatchRegExp/preferLongerCaptures.js +30 -0
- package/lib/partialMatchRegExp/regexFeatures.d.ts +6 -0
- package/lib/partialMatchRegExp/regexFeatures.js +47 -0
- package/lib/partialMatchRegExp/walk.d.ts +8 -0
- package/lib/partialMatchRegExp/walk.js +366 -0
- package/package.json +25 -15
- package/lib/compilePartial.d.ts +0 -16
- package/lib/compilePartial.js +0 -334
- package/lib/partialMatchRegExp.js +0 -122
- /package/lib/{escapeAtom.d.ts → partialMatchRegExp/escapeAtom.d.ts} +0 -0
- /package/lib/{escapeAtom.js → partialMatchRegExp/escapeAtom.js} +0 -0
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
import { DISJUNCTION_TO_END_OF_INPUT, OPTIONAL_ATOM_OPENING } from "./atomSyntax.js";
|
|
2
|
+
import { groupNameOf, decodeGroupName } from "./groupName.js";
|
|
3
|
+
import { FEATURE_BIT } from "./regexFeatures.js";
|
|
4
|
+
const OCCURRENCES_REGEX = /\{\d+,?\d*\}/y;
|
|
5
|
+
const NOT_NUMBERS_REGEX = /\D/g;
|
|
6
|
+
const LITERAL_K_ATOM = OPTIONAL_ATOM_OPENING + "k" + DISJUNCTION_TO_END_OF_INPUT;
|
|
7
|
+
const NO_RAW_LOOKAROUNDS = [];
|
|
8
|
+
const NO_NAMED_GROUP_OPENINGS = [];
|
|
9
|
+
const declaresGroupNamed = (closedGroupNames, name) => { var _a; return (_a = closedGroupNames === null || closedGroupNames === void 0 ? void 0 : closedGroupNames.has(decodeGroupName(name))) !== null && _a !== void 0 ? _a : false; };
|
|
10
|
+
export function walk(regex, declaresNamedGroup) {
|
|
11
|
+
const source = regex.source;
|
|
12
|
+
const isUnicode = regex.unicode || regex.unicodeSets;
|
|
13
|
+
let i = 0;
|
|
14
|
+
let groupCount = 0;
|
|
15
|
+
let featureMask = 0;
|
|
16
|
+
let rawLookarounds;
|
|
17
|
+
let namedGroupOpenings;
|
|
18
|
+
let closedGroupNumbers;
|
|
19
|
+
let closedGroupNames;
|
|
20
|
+
let namedBackreferencesSeen;
|
|
21
|
+
let currentRawLookaroundBackreferences;
|
|
22
|
+
function extractSlice(length) {
|
|
23
|
+
return source.slice(i, (i += length));
|
|
24
|
+
}
|
|
25
|
+
function process(withinLookaround, declaresNamedGroup, caseInsensitive) {
|
|
26
|
+
const result = [];
|
|
27
|
+
function appendOptional(length) {
|
|
28
|
+
result.push("(?:" + extractSlice(length) + DISJUNCTION_TO_END_OF_INPUT);
|
|
29
|
+
}
|
|
30
|
+
function appendRaw(length) {
|
|
31
|
+
result.push(extractSlice(length));
|
|
32
|
+
}
|
|
33
|
+
function appendDigitRun(forcedRef) {
|
|
34
|
+
featureMask |= FEATURE_BIT.backreference;
|
|
35
|
+
NOT_NUMBERS_REGEX.lastIndex = i + 1;
|
|
36
|
+
const nextNonDigit = NOT_NUMBERS_REGEX.exec(source);
|
|
37
|
+
const start = i;
|
|
38
|
+
const end = nextNonDigit ? nextNonDigit.index : source.length;
|
|
39
|
+
const ref = forcedRef !== null && forcedRef !== void 0 ? forcedRef : Number(source.slice(start + 1, end));
|
|
40
|
+
i = end;
|
|
41
|
+
const backreference = {
|
|
42
|
+
ref,
|
|
43
|
+
start,
|
|
44
|
+
end,
|
|
45
|
+
forward: !(closedGroupNumbers === null || closedGroupNumbers === void 0 ? void 0 : closedGroupNumbers.has(ref)),
|
|
46
|
+
caseInsensitive
|
|
47
|
+
};
|
|
48
|
+
result.push(backreference);
|
|
49
|
+
currentRawLookaroundBackreferences === null || currentRawLookaroundBackreferences === void 0 ? void 0 : currentRawLookaroundBackreferences.push(backreference);
|
|
50
|
+
}
|
|
51
|
+
function appendRawLookaround(prefixLength) {
|
|
52
|
+
const start = i;
|
|
53
|
+
i += prefixLength;
|
|
54
|
+
const groupCountBefore = groupCount;
|
|
55
|
+
const isOutermost = currentRawLookaroundBackreferences === undefined;
|
|
56
|
+
const backreferences = currentRawLookaroundBackreferences !== null && currentRawLookaroundBackreferences !== void 0 ? currentRawLookaroundBackreferences : [];
|
|
57
|
+
if (isOutermost)
|
|
58
|
+
currentRawLookaroundBackreferences = backreferences;
|
|
59
|
+
process(true, declaresNamedGroup, caseInsensitive);
|
|
60
|
+
if (isOutermost) {
|
|
61
|
+
(rawLookarounds !== null && rawLookarounds !== void 0 ? rawLookarounds : (rawLookarounds = [])).push({
|
|
62
|
+
sourceStart: start,
|
|
63
|
+
capturingGroupsOpened: groupCount - groupCountBefore,
|
|
64
|
+
backreferences
|
|
65
|
+
});
|
|
66
|
+
currentRawLookaroundBackreferences = undefined;
|
|
67
|
+
}
|
|
68
|
+
result.push(source.slice(start, i));
|
|
69
|
+
}
|
|
70
|
+
while (i < source.length) {
|
|
71
|
+
switch (source[i]) {
|
|
72
|
+
case "\\":
|
|
73
|
+
switch (source[i + 1]) {
|
|
74
|
+
case "c":
|
|
75
|
+
featureMask |= FEATURE_BIT.controlLetterEscape;
|
|
76
|
+
appendOptional(3);
|
|
77
|
+
break;
|
|
78
|
+
case "k": {
|
|
79
|
+
const referenceEnd = source[i + 2] === "<" ? source.indexOf(">", i) : -1;
|
|
80
|
+
if (referenceEnd !== -1 && declaresNamedGroup) {
|
|
81
|
+
featureMask |= FEATURE_BIT.namedBackreference;
|
|
82
|
+
const start = i;
|
|
83
|
+
const ref = source.slice(i + 3, referenceEnd);
|
|
84
|
+
i = referenceEnd + 1;
|
|
85
|
+
const namedBackreference = {
|
|
86
|
+
ref,
|
|
87
|
+
start,
|
|
88
|
+
end: i,
|
|
89
|
+
forward: !declaresGroupNamed(closedGroupNames, ref),
|
|
90
|
+
caseInsensitive
|
|
91
|
+
};
|
|
92
|
+
result.push(namedBackreference);
|
|
93
|
+
currentRawLookaroundBackreferences === null || currentRawLookaroundBackreferences === void 0 ? void 0 : currentRawLookaroundBackreferences.push(namedBackreference);
|
|
94
|
+
(namedBackreferencesSeen !== null && namedBackreferencesSeen !== void 0 ? namedBackreferencesSeen : (namedBackreferencesSeen = [])).push(namedBackreference);
|
|
95
|
+
}
|
|
96
|
+
else if (currentRawLookaroundBackreferences) {
|
|
97
|
+
const start = i;
|
|
98
|
+
i += 2;
|
|
99
|
+
currentRawLookaroundBackreferences.push({
|
|
100
|
+
ref: "",
|
|
101
|
+
start,
|
|
102
|
+
end: i,
|
|
103
|
+
caseInsensitive
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
result.push(LITERAL_K_ATOM);
|
|
108
|
+
i += 2;
|
|
109
|
+
}
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
case "u":
|
|
113
|
+
featureMask |= FEATURE_BIT.unicodeEscapeSequence;
|
|
114
|
+
if (isUnicode && source[i + 2] === "{") {
|
|
115
|
+
appendOptional(source.indexOf("}", i) - i + 1);
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
appendOptional(6);
|
|
119
|
+
}
|
|
120
|
+
break;
|
|
121
|
+
case "p":
|
|
122
|
+
case "P":
|
|
123
|
+
if (isUnicode) {
|
|
124
|
+
featureMask |= FEATURE_BIT.unicodePropertyEscape;
|
|
125
|
+
appendOptional(source.indexOf("}", i) - i + 1);
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
appendOptional(2);
|
|
129
|
+
}
|
|
130
|
+
break;
|
|
131
|
+
case "x":
|
|
132
|
+
featureMask |= FEATURE_BIT.hexEscapeSequence;
|
|
133
|
+
appendOptional(4);
|
|
134
|
+
break;
|
|
135
|
+
case "b":
|
|
136
|
+
featureMask |= FEATURE_BIT.wordBoundary;
|
|
137
|
+
appendOptional(2);
|
|
138
|
+
break;
|
|
139
|
+
case "B":
|
|
140
|
+
featureMask |= FEATURE_BIT.nonWordBoundary;
|
|
141
|
+
appendOptional(2);
|
|
142
|
+
break;
|
|
143
|
+
case "f":
|
|
144
|
+
case "n":
|
|
145
|
+
case "r":
|
|
146
|
+
case "t":
|
|
147
|
+
case "v":
|
|
148
|
+
featureMask |= FEATURE_BIT.controlEscape;
|
|
149
|
+
appendOptional(2);
|
|
150
|
+
break;
|
|
151
|
+
case "0":
|
|
152
|
+
if (isUnicode) {
|
|
153
|
+
featureMask |= FEATURE_BIT.otherEscape;
|
|
154
|
+
appendOptional(2);
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
appendDigitRun(0);
|
|
158
|
+
}
|
|
159
|
+
break;
|
|
160
|
+
case "1":
|
|
161
|
+
case "2":
|
|
162
|
+
case "3":
|
|
163
|
+
case "4":
|
|
164
|
+
case "5":
|
|
165
|
+
case "6":
|
|
166
|
+
case "7":
|
|
167
|
+
case "8":
|
|
168
|
+
case "9":
|
|
169
|
+
appendDigitRun();
|
|
170
|
+
break;
|
|
171
|
+
case "d":
|
|
172
|
+
case "D":
|
|
173
|
+
case "w":
|
|
174
|
+
case "W":
|
|
175
|
+
case "s":
|
|
176
|
+
case "S":
|
|
177
|
+
featureMask |= FEATURE_BIT.characterClassEscape;
|
|
178
|
+
appendOptional(2);
|
|
179
|
+
break;
|
|
180
|
+
default:
|
|
181
|
+
featureMask |= FEATURE_BIT.otherEscape;
|
|
182
|
+
appendOptional(2);
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
break;
|
|
186
|
+
case "[": {
|
|
187
|
+
featureMask |= FEATURE_BIT.characterClass;
|
|
188
|
+
let depth = 1, j = i + 1, previousSetOperatorCharacter;
|
|
189
|
+
while (depth) {
|
|
190
|
+
const character = source[j];
|
|
191
|
+
switch (character) {
|
|
192
|
+
case "\\":
|
|
193
|
+
j += 2;
|
|
194
|
+
previousSetOperatorCharacter = undefined;
|
|
195
|
+
continue;
|
|
196
|
+
case "[":
|
|
197
|
+
if (regex.unicodeSets) {
|
|
198
|
+
featureMask |= FEATURE_BIT.nestedCharacterClass;
|
|
199
|
+
depth++;
|
|
200
|
+
}
|
|
201
|
+
break;
|
|
202
|
+
case "]":
|
|
203
|
+
depth--;
|
|
204
|
+
break;
|
|
205
|
+
case "&":
|
|
206
|
+
if (regex.unicodeSets && previousSetOperatorCharacter === "&") {
|
|
207
|
+
featureMask |= FEATURE_BIT.classIntersection;
|
|
208
|
+
}
|
|
209
|
+
break;
|
|
210
|
+
case "-":
|
|
211
|
+
if (regex.unicodeSets && previousSetOperatorCharacter === "-") {
|
|
212
|
+
featureMask |= FEATURE_BIT.classSubtraction;
|
|
213
|
+
}
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
previousSetOperatorCharacter = character;
|
|
217
|
+
j++;
|
|
218
|
+
}
|
|
219
|
+
appendOptional(j - i);
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
case "^":
|
|
223
|
+
featureMask |= FEATURE_BIT.startAnchor;
|
|
224
|
+
appendRaw(1);
|
|
225
|
+
break;
|
|
226
|
+
case "$":
|
|
227
|
+
featureMask |= FEATURE_BIT.endAnchor;
|
|
228
|
+
appendRaw(1);
|
|
229
|
+
break;
|
|
230
|
+
case "|":
|
|
231
|
+
featureMask |= FEATURE_BIT.disjunction;
|
|
232
|
+
appendRaw(1);
|
|
233
|
+
break;
|
|
234
|
+
case "*":
|
|
235
|
+
case "+":
|
|
236
|
+
case "?":
|
|
237
|
+
featureMask |= FEATURE_BIT.quantifier;
|
|
238
|
+
appendRaw(1);
|
|
239
|
+
break;
|
|
240
|
+
case "{": {
|
|
241
|
+
OCCURRENCES_REGEX.lastIndex = i;
|
|
242
|
+
const regExpExecArray = OCCURRENCES_REGEX.exec(source);
|
|
243
|
+
if (regExpExecArray) {
|
|
244
|
+
featureMask |= FEATURE_BIT.quantifier;
|
|
245
|
+
appendRaw(regExpExecArray[0].length);
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
appendOptional(1);
|
|
249
|
+
}
|
|
250
|
+
break;
|
|
251
|
+
}
|
|
252
|
+
case "(":
|
|
253
|
+
if (source[i + 1] == "?") {
|
|
254
|
+
switch (source[i + 2]) {
|
|
255
|
+
case ":":
|
|
256
|
+
featureMask |= FEATURE_BIT.nonCapturingGroup;
|
|
257
|
+
result.push("(?:");
|
|
258
|
+
i += 3;
|
|
259
|
+
result.push(...process(withinLookaround, declaresNamedGroup, caseInsensitive), DISJUNCTION_TO_END_OF_INPUT);
|
|
260
|
+
break;
|
|
261
|
+
case "=":
|
|
262
|
+
featureMask |= FEATURE_BIT.lookahead;
|
|
263
|
+
result.push("(?=");
|
|
264
|
+
i += 3;
|
|
265
|
+
result.push(...process(true, declaresNamedGroup, caseInsensitive), ")");
|
|
266
|
+
break;
|
|
267
|
+
case "-":
|
|
268
|
+
case "i":
|
|
269
|
+
case "s":
|
|
270
|
+
case "m": {
|
|
271
|
+
const flagsStart = i + 2, colonIndex = source.indexOf(":", flagsStart);
|
|
272
|
+
const modifiers = source.slice(flagsStart, colonIndex);
|
|
273
|
+
const [additions, removals] = modifiers.split("-");
|
|
274
|
+
featureMask |= removals
|
|
275
|
+
? FEATURE_BIT.modifierGroupWithRemoval
|
|
276
|
+
: FEATURE_BIT.modifierGroup;
|
|
277
|
+
const modifierGroupCaseInsensitive = (removals === null || removals === void 0 ? void 0 : removals.includes("i"))
|
|
278
|
+
? false
|
|
279
|
+
: caseInsensitive || additions.includes("i");
|
|
280
|
+
result.push("(?" + modifiers + ":");
|
|
281
|
+
i = colonIndex + 1;
|
|
282
|
+
result.push(...process(withinLookaround, declaresNamedGroup, modifierGroupCaseInsensitive), ")");
|
|
283
|
+
break;
|
|
284
|
+
}
|
|
285
|
+
case "!":
|
|
286
|
+
featureMask |= FEATURE_BIT.negativeLookahead;
|
|
287
|
+
appendRawLookaround(3);
|
|
288
|
+
break;
|
|
289
|
+
case "<":
|
|
290
|
+
switch (source[i + 3]) {
|
|
291
|
+
case "=":
|
|
292
|
+
featureMask |= FEATURE_BIT.lookbehind;
|
|
293
|
+
appendRawLookaround(4);
|
|
294
|
+
break;
|
|
295
|
+
case "!":
|
|
296
|
+
featureMask |= FEATURE_BIT.negativeLookbehind;
|
|
297
|
+
appendRawLookaround(4);
|
|
298
|
+
break;
|
|
299
|
+
default: {
|
|
300
|
+
featureMask |= FEATURE_BIT.namedGroup;
|
|
301
|
+
featureMask |= FEATURE_BIT.capturingGroup;
|
|
302
|
+
if (withinLookaround)
|
|
303
|
+
featureMask |= FEATURE_BIT.lookaroundCapture;
|
|
304
|
+
const groupNumber = ++groupCount;
|
|
305
|
+
const opening = extractSlice(source.indexOf(">", i) - i + 1);
|
|
306
|
+
(namedGroupOpenings !== null && namedGroupOpenings !== void 0 ? namedGroupOpenings : (namedGroupOpenings = [])).push(opening);
|
|
307
|
+
const declaredName = decodeGroupName(groupNameOf(opening));
|
|
308
|
+
result.push(opening);
|
|
309
|
+
result.push(...process(withinLookaround, declaresNamedGroup, caseInsensitive), DISJUNCTION_TO_END_OF_INPUT);
|
|
310
|
+
(closedGroupNumbers !== null && closedGroupNumbers !== void 0 ? closedGroupNumbers : (closedGroupNumbers = new Set())).add(groupNumber);
|
|
311
|
+
(closedGroupNames !== null && closedGroupNames !== void 0 ? closedGroupNames : (closedGroupNames = new Set())).add(declaredName);
|
|
312
|
+
break;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
break;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
else {
|
|
319
|
+
featureMask |= FEATURE_BIT.capturingGroup;
|
|
320
|
+
if (withinLookaround)
|
|
321
|
+
featureMask |= FEATURE_BIT.lookaroundCapture;
|
|
322
|
+
const groupNumber = ++groupCount;
|
|
323
|
+
appendRaw(1);
|
|
324
|
+
result.push(...process(withinLookaround, declaresNamedGroup, caseInsensitive), DISJUNCTION_TO_END_OF_INPUT);
|
|
325
|
+
(closedGroupNumbers !== null && closedGroupNumbers !== void 0 ? closedGroupNumbers : (closedGroupNumbers = new Set())).add(groupNumber);
|
|
326
|
+
}
|
|
327
|
+
break;
|
|
328
|
+
case ")":
|
|
329
|
+
++i;
|
|
330
|
+
return result;
|
|
331
|
+
default:
|
|
332
|
+
featureMask |= FEATURE_BIT.patternCharacter;
|
|
333
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- i < source.length is the loop invariant, so codePointAt(i) is always defined
|
|
334
|
+
appendOptional(isUnicode && source.codePointAt(i) > 0xffff ? 2 : 1);
|
|
335
|
+
break;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
return result;
|
|
339
|
+
}
|
|
340
|
+
const parts = process(false, declaresNamedGroup, regex.flags.includes("i"));
|
|
341
|
+
if (namedGroupOpenings && namedBackreferencesSeen) {
|
|
342
|
+
const seenOnce = new Set();
|
|
343
|
+
let duplicated;
|
|
344
|
+
for (const opening of namedGroupOpenings) {
|
|
345
|
+
const name = decodeGroupName(groupNameOf(opening));
|
|
346
|
+
if (seenOnce.has(name))
|
|
347
|
+
(duplicated !== null && duplicated !== void 0 ? duplicated : (duplicated = new Set())).add(name);
|
|
348
|
+
else
|
|
349
|
+
seenOnce.add(name);
|
|
350
|
+
}
|
|
351
|
+
if (duplicated) {
|
|
352
|
+
for (const backreference of namedBackreferencesSeen) {
|
|
353
|
+
if (duplicated.has(decodeGroupName(backreference.ref))) {
|
|
354
|
+
backreference.forward = true;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
return {
|
|
360
|
+
parts,
|
|
361
|
+
groupCount,
|
|
362
|
+
featureMask,
|
|
363
|
+
rawLookarounds: rawLookarounds !== null && rawLookarounds !== void 0 ? rawLookarounds : NO_RAW_LOOKAROUNDS,
|
|
364
|
+
namedGroupOpenings: namedGroupOpenings !== null && namedGroupOpenings !== void 0 ? namedGroupOpenings : NO_NAMED_GROUP_OPENINGS
|
|
365
|
+
};
|
|
366
|
+
}
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "regex-partial-match",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "A regular expression transform for partial matching",
|
|
5
5
|
"devEngines": {
|
|
6
6
|
"runtime": {
|
|
7
7
|
"name": "node",
|
|
8
|
-
"version": ">=
|
|
8
|
+
"version": ">=24.12"
|
|
9
9
|
},
|
|
10
10
|
"packageManager": {
|
|
11
11
|
"name": "npm",
|
|
12
|
-
"version": "11.
|
|
12
|
+
"version": "11.19.0+sha512.48377f8478372aa1c4e47b763475b135836da82436a5700f2e5e8eb5084fc840f93c7b117eb3ad3b5f7d3194c81b6710a10d59448f6ddbcb21ac3fb672bdc003"
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
15
|
"keywords": [
|
|
@@ -33,17 +33,22 @@
|
|
|
33
33
|
}
|
|
34
34
|
],
|
|
35
35
|
"type": "module",
|
|
36
|
-
"main": "lib/partialMatchRegExp.js",
|
|
36
|
+
"main": "lib/partialMatchRegExp/index.js",
|
|
37
37
|
"exports": {
|
|
38
38
|
".": {
|
|
39
|
-
"types": "./lib/partialMatchRegExp.d.ts",
|
|
40
|
-
"import": "./lib/partialMatchRegExp.js",
|
|
41
|
-
"default": "./lib/partialMatchRegExp.js"
|
|
39
|
+
"types": "./lib/partialMatchRegExp/index.d.ts",
|
|
40
|
+
"import": "./lib/partialMatchRegExp/index.js",
|
|
41
|
+
"default": "./lib/partialMatchRegExp/index.js"
|
|
42
42
|
},
|
|
43
43
|
"./extend": {
|
|
44
|
-
"types": "./lib/extend.d.ts",
|
|
45
|
-
"import": "./lib/extend.js",
|
|
46
|
-
"default": "./lib/extend.js"
|
|
44
|
+
"types": "./lib/extend/index.d.ts",
|
|
45
|
+
"import": "./lib/extend/index.js",
|
|
46
|
+
"default": "./lib/extend/index.js"
|
|
47
|
+
},
|
|
48
|
+
"./partialMatchRegExp": {
|
|
49
|
+
"types": "./lib/partialMatchRegExp/partialMatchRegExp.d.ts",
|
|
50
|
+
"import": "./lib/partialMatchRegExp/partialMatchRegExp.js",
|
|
51
|
+
"default": "./lib/partialMatchRegExp/partialMatchRegExp.js"
|
|
47
52
|
}
|
|
48
53
|
},
|
|
49
54
|
"files": [
|
|
@@ -54,9 +59,11 @@
|
|
|
54
59
|
"url": "git+https://github.com/TomStrepsil/regex-partial-match.git"
|
|
55
60
|
},
|
|
56
61
|
"workspaces": [
|
|
57
|
-
"benchmarking"
|
|
62
|
+
"test/benchmarking"
|
|
63
|
+
],
|
|
64
|
+
"sideEffects": [
|
|
65
|
+
"./lib/extend/index.js"
|
|
58
66
|
],
|
|
59
|
-
"sideEffects": false,
|
|
60
67
|
"scripts": {
|
|
61
68
|
"lint": "eslint .",
|
|
62
69
|
"lint:fix": "eslint . --fix",
|
|
@@ -64,7 +71,8 @@
|
|
|
64
71
|
"prepublishOnly": "tsc -p tsconfig.build.json",
|
|
65
72
|
"ci:smoke-test-built-package": "node .github/scripts/smoke-test-built-package.ts",
|
|
66
73
|
"test": "vitest run --config ./test/vitest.config.ts",
|
|
67
|
-
"test:watch": "vitest --config ./test/vitest.config.ts"
|
|
74
|
+
"test:watch": "vitest --config ./test/vitest.config.ts",
|
|
75
|
+
"test:coverage": "vitest run --config ./test/vitest.config.ts --coverage"
|
|
68
76
|
},
|
|
69
77
|
"simple-git-hooks": {
|
|
70
78
|
"pre-commit": "node_modules/.bin/lint-staged"
|
|
@@ -78,11 +86,13 @@
|
|
|
78
86
|
"registry": "https://registry.npmjs.org"
|
|
79
87
|
},
|
|
80
88
|
"devDependencies": {
|
|
81
|
-
"@typescript/lib-es2018": "file:types/lib-es2018",
|
|
82
|
-
"@typescript/lib-es2022": "file:types/lib-es2022",
|
|
83
89
|
"@eslint/js": "^9.17.0",
|
|
84
90
|
"@eslint/markdown": "^7.5.1",
|
|
85
91
|
"@types/node": "^25.9.3",
|
|
92
|
+
"@typescript/lib-es2018": "file:types/lib-es2018",
|
|
93
|
+
"@typescript/lib-es2022": "file:types/lib-es2022",
|
|
94
|
+
"@vitest/coverage-v8": "^4.1.11",
|
|
95
|
+
"esbuild": "^0.28.1",
|
|
86
96
|
"eslint": "^9.17.0",
|
|
87
97
|
"jiti": "^2.6.1",
|
|
88
98
|
"lint-staged": "^15.2.11",
|
package/lib/compilePartial.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export type RegexFeature = "patternCharacter" | "startAnchor" | "endAnchor" | "wordBoundary" | "nonWordBoundary" | "lookahead" | "negativeLookahead" | "lookbehind" | "negativeLookbehind" | "backreference" | "namedBackreference" | "namedGroup" | "capturingGroup" | "nonCapturingGroup" | "modifierGroup" | "modifierGroupWithRemoval" | "characterClass" | "nestedCharacterClass" | "classIntersection" | "classSubtraction" | "disjunction" | "quantifier" | "unicodePropertyEscape" | "characterClassEscape" | "controlEscape" | "controlLetterEscape" | "hexEscapeSequence" | "unicodeEscapeSequence" | "otherEscape";
|
|
2
|
-
export interface DynamicPath {
|
|
3
|
-
originalCaptureScan: RegExp;
|
|
4
|
-
preScan: RegExp;
|
|
5
|
-
expand: (capture: RegExpExecArray) => string;
|
|
6
|
-
}
|
|
7
|
-
export type CompiledPartial = ({
|
|
8
|
-
kind: "static";
|
|
9
|
-
regex: RegExp;
|
|
10
|
-
} | {
|
|
11
|
-
kind: "dynamic";
|
|
12
|
-
dynamic: DynamicPath;
|
|
13
|
-
}) & {
|
|
14
|
-
features: Set<RegexFeature>;
|
|
15
|
-
};
|
|
16
|
-
export declare const compilePartial: (regex: RegExp) => CompiledPartial;
|