regex-partial-match 1.3.0 → 2.0.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 +154 -301
- package/lib/core/corePartialMatchRegExp.d.ts +24 -0
- package/lib/core/corePartialMatchRegExp.js +22 -0
- package/lib/core/index.d.ts +4 -0
- package/lib/core/index.js +2 -0
- package/lib/extend/index.d.ts +6 -7
- package/lib/extend/index.js +1 -1
- package/lib/features/index.d.ts +20 -0
- package/lib/features/index.js +23 -0
- package/lib/hitEnd/index.d.ts +45 -0
- package/lib/hitEnd/index.js +57 -0
- package/lib/hitEnd/matchHitEnd.d.ts +4 -0
- package/lib/hitEnd/matchHitEnd.js +51 -0
- package/lib/{partialMatchRegExp/isComplete → hitEnd}/partRole.d.ts +1 -1
- package/lib/hitEnd/partRole.js +17 -0
- package/lib/hitEnd/truncationProbe.d.ts +8 -0
- package/lib/hitEnd/truncationProbe.js +187 -0
- package/lib/hitEnd/truncationProbeCache.d.ts +14 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +4 -0
- package/lib/modules/backreferences/asNativeAtom.d.ts +2 -0
- package/lib/{partialMatchRegExp/compilePartial → modules/backreferences}/asNativeAtom.js +2 -2
- package/lib/modules/backreferences/asPreScanPart.d.ts +2 -0
- package/lib/{partialMatchRegExp/compilePartial → modules/backreferences}/asPreScanPart.js +2 -2
- package/lib/modules/backreferences/backreferenceRecorder.d.ts +2 -0
- package/lib/modules/backreferences/backreferenceRecorder.js +38 -0
- package/lib/modules/backreferences/compileDynamic.d.ts +4 -0
- package/lib/modules/backreferences/compileDynamic.js +53 -0
- package/lib/modules/backreferences/compiledBackreferences.d.ts +9 -0
- package/lib/modules/backreferences/compiledBackreferences.js +9 -0
- package/lib/modules/backreferences/constants.d.ts +2 -0
- package/lib/modules/backreferences/constants.js +2 -0
- package/lib/modules/backreferences/execDynamic.d.ts +2 -0
- package/lib/modules/backreferences/execDynamic.js +43 -0
- package/lib/{partialMatchRegExp/compilePartial → modules/backreferences}/flagsAtBackreference.d.ts +1 -1
- package/lib/{partialMatchRegExp → modules/backreferences}/groupName.js +1 -1
- package/lib/modules/backreferences/index.d.ts +10 -0
- package/lib/modules/backreferences/index.js +20 -0
- package/lib/modules/backreferences/longestBakedPrefixEndingInput.js +46 -0
- package/lib/{partialMatchRegExp/compilePartial → modules/backreferences}/renderParts.d.ts +1 -1
- package/lib/{partialMatchRegExp/compilePartial → modules/backreferences}/renderParts.js +1 -1
- package/lib/{partialMatchRegExp/compilePartial → modules/backreferences}/resolvedFromScan.d.ts +1 -1
- package/lib/{partialMatchRegExp/compilePartial → modules/backreferences}/resolvedFromScan.js +2 -2
- package/lib/{partialMatchRegExp/compilePartial → modules/backreferences}/startsWithUnderFlags.js +1 -1
- package/lib/modules/carets/appendMultilineCaret.d.ts +7 -0
- package/lib/modules/carets/appendMultilineCaret.js +181 -0
- package/lib/modules/carets/caretRecorder.d.ts +2 -0
- package/lib/modules/carets/caretRecorder.js +164 -0
- package/lib/modules/carets/caretSyntax.d.ts +3 -0
- package/lib/modules/carets/caretSyntax.js +11 -0
- package/lib/modules/carets/index.d.ts +9 -0
- package/lib/modules/carets/index.js +18 -0
- package/lib/modules/carets/lineTerminator.d.ts +1 -0
- package/lib/modules/carets/lineTerminator.js +31 -0
- package/lib/modules/carets/needsCaretRules.d.ts +1 -0
- package/lib/modules/carets/needsCaretRules.js +15 -0
- package/lib/modules/carets/quantifierBounds.d.ts +3 -0
- package/lib/modules/carets/quantifierBounds.js +18 -0
- package/lib/modules/index.d.ts +3 -0
- package/lib/modules/index.js +2 -0
- package/lib/partialMatchRegExp/atomSyntax.d.ts +14 -1
- package/lib/partialMatchRegExp/atomSyntax.js +24 -1
- package/lib/partialMatchRegExp/backreferenceExpansion.d.ts +1 -6
- package/lib/partialMatchRegExp/backreferenceHook.d.ts +11 -0
- package/lib/partialMatchRegExp/backreferenceHook.js +1 -0
- package/lib/partialMatchRegExp/caretHook.d.ts +17 -0
- package/lib/partialMatchRegExp/caretHook.js +5 -0
- package/lib/partialMatchRegExp/compilePartial/compileWith.d.ts +3 -0
- package/lib/partialMatchRegExp/compilePartial/compileWith.js +36 -0
- package/lib/partialMatchRegExp/compilePartial/compiled.d.ts +17 -17
- package/lib/partialMatchRegExp/compilePartial/compiled.js +8 -21
- package/lib/partialMatchRegExp/compilePartial/constants.d.ts +4 -0
- package/lib/partialMatchRegExp/compilePartial/constants.js +4 -0
- package/lib/partialMatchRegExp/compilePartial/groupShape.d.ts +4 -0
- package/lib/partialMatchRegExp/compilePartial/groupShape.js +9 -0
- package/lib/partialMatchRegExp/compilePartial/toStatic.d.ts +2 -2
- package/lib/partialMatchRegExp/compilePartial/toStatic.js +2 -2
- package/lib/partialMatchRegExp/constants.d.ts +5 -0
- package/lib/partialMatchRegExp/constants.js +5 -0
- package/lib/partialMatchRegExp/createPartialMatchRegExp.d.ts +3 -0
- package/lib/partialMatchRegExp/createPartialMatchRegExp.js +21 -0
- package/lib/partialMatchRegExp/execFrom.d.ts +1 -0
- package/lib/partialMatchRegExp/execFrom.js +4 -0
- package/lib/partialMatchRegExp/index.d.ts +49 -3
- package/lib/partialMatchRegExp/index.js +31 -3
- package/lib/partialMatchRegExp/moduleHooks.d.ts +14 -0
- package/lib/partialMatchRegExp/moduleHooks.js +15 -0
- package/lib/partialMatchRegExp/opaqueModule.d.ts +9 -0
- package/lib/partialMatchRegExp/opaqueModule.js +1 -0
- package/lib/partialMatchRegExp/part.d.ts +2 -11
- package/lib/partialMatchRegExp/partialMatchInternals.d.ts +2 -1
- package/lib/partialMatchRegExp/partialMatchInternals.js +3 -1
- package/lib/partialMatchRegExp/quantifier.d.ts +6 -0
- package/lib/partialMatchRegExp/quantifier.js +9 -0
- package/lib/partialMatchRegExp/rawLookaroundInfo.d.ts +11 -0
- package/lib/partialMatchRegExp/rawLookaroundInfo.js +1 -0
- package/lib/partialMatchRegExp/regexFeatures.d.ts +1 -5
- package/lib/partialMatchRegExp/regexFeatures.js +2 -8
- package/lib/partialMatchRegExp/scope.d.ts +12 -0
- package/lib/partialMatchRegExp/scope.js +45 -0
- package/lib/partialMatchRegExp/walk.d.ts +13 -5
- package/lib/partialMatchRegExp/walk.js +211 -165
- package/lib/partialMatchRegExp/withModules.d.ts +13 -0
- package/lib/partialMatchRegExp/withModules.js +27 -0
- package/package.json +39 -56
- package/lib/partialMatchRegExp/compilePartial/asNativeAtom.d.ts +0 -2
- package/lib/partialMatchRegExp/compilePartial/asOptionalAtom.d.ts +0 -1
- package/lib/partialMatchRegExp/compilePartial/asOptionalAtom.js +0 -4
- package/lib/partialMatchRegExp/compilePartial/asPreScanPart.d.ts +0 -2
- package/lib/partialMatchRegExp/compilePartial/index.d.ts +0 -2
- package/lib/partialMatchRegExp/compilePartial/index.js +0 -79
- package/lib/partialMatchRegExp/compilePartial/longestBakedPrefixEndingInput.js +0 -50
- package/lib/partialMatchRegExp/compilePartial/reclassifyLegacyEscapes.d.ts +0 -2
- package/lib/partialMatchRegExp/compilePartial/reclassifyLegacyEscapes.js +0 -17
- package/lib/partialMatchRegExp/compilePartial/spliceOriginalSource.d.ts +0 -2
- package/lib/partialMatchRegExp/compilePartial/spliceOriginalSource.js +0 -12
- package/lib/partialMatchRegExp/isComplete/index.d.ts +0 -38
- package/lib/partialMatchRegExp/isComplete/index.js +0 -41
- package/lib/partialMatchRegExp/isComplete/isMatchComplete.d.ts +0 -3
- package/lib/partialMatchRegExp/isComplete/isMatchComplete.js +0 -14
- package/lib/partialMatchRegExp/isComplete/partRole.js +0 -28
- package/lib/partialMatchRegExp/isComplete/truncationProbe.d.ts +0 -8
- package/lib/partialMatchRegExp/isComplete/truncationProbe.js +0 -105
- package/lib/partialMatchRegExp/isComplete/truncationProbeCache.d.ts +0 -4
- package/lib/partialMatchRegExp/partialMatchRegExp.d.ts +0 -55
- package/lib/partialMatchRegExp/partialMatchRegExp.js +0 -114
- package/lib/partialMatchRegExp/preferLongerCaptures.d.ts +0 -1
- package/lib/partialMatchRegExp/preferLongerCaptures.js +0 -30
- /package/lib/{partialMatchRegExp/isComplete → hitEnd}/truncationProbeCache.js +0 -0
- /package/lib/{partialMatchRegExp/compilePartial → modules/backreferences}/caseFoldFlags.d.ts +0 -0
- /package/lib/{partialMatchRegExp/compilePartial → modules/backreferences}/caseFoldFlags.js +0 -0
- /package/lib/{partialMatchRegExp → modules/backreferences}/escapeAtom.d.ts +0 -0
- /package/lib/{partialMatchRegExp → modules/backreferences}/escapeAtom.js +0 -0
- /package/lib/{partialMatchRegExp/compilePartial → modules/backreferences}/flagsAtBackreference.js +0 -0
- /package/lib/{partialMatchRegExp → modules/backreferences}/groupName.d.ts +0 -0
- /package/lib/{partialMatchRegExp/compilePartial → modules/backreferences}/longestBakedPrefixEndingInput.d.ts +0 -0
- /package/lib/{partialMatchRegExp/compilePartial → modules/backreferences}/startsWithUnderFlags.d.ts +0 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface RawReference {
|
|
2
|
+
ref: number;
|
|
3
|
+
start: number;
|
|
4
|
+
end: number;
|
|
5
|
+
}
|
|
6
|
+
export interface RawLookaroundInfo {
|
|
7
|
+
sourceStart: number;
|
|
8
|
+
capturingGroupsOpened: number;
|
|
9
|
+
references: readonly RawReference[];
|
|
10
|
+
}
|
|
11
|
+
export type RawLookarounds = readonly (RawLookaroundInfo | undefined)[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
declare const REGEX_FEATURES: readonly ["patternCharacter", "startAnchor", "endAnchor", "wordBoundary", "nonWordBoundary", "lookahead", "negativeLookahead", "lookbehind", "negativeLookbehind", "backreference", "namedBackreference", "namedGroup", "capturingGroup", "lookaroundCapture", "nonCapturingGroup", "modifierGroup", "modifierGroupWithRemoval", "characterClass", "nestedCharacterClass", "classIntersection", "classSubtraction", "disjunction", "quantifier", "unicodePropertyEscape", "characterClassEscape", "controlEscape", "controlLetterEscape", "hexEscapeSequence", "unicodeEscapeSequence", "otherEscape"];
|
|
1
|
+
export declare const REGEX_FEATURES: readonly ["patternCharacter", "startAnchor", "endAnchor", "wordBoundary", "nonWordBoundary", "lookahead", "negativeLookahead", "lookbehind", "negativeLookbehind", "backreference", "namedBackreference", "namedGroup", "capturingGroup", "lookaroundCapture", "nonCapturingGroup", "modifierGroup", "modifierGroupWithRemoval", "characterClass", "nestedCharacterClass", "classIntersection", "classSubtraction", "disjunction", "quantifier", "unicodePropertyEscape", "characterClassEscape", "controlEscape", "controlLetterEscape", "hexEscapeSequence", "unicodeEscapeSequence", "otherEscape"];
|
|
2
2
|
export type RegexFeature = (typeof REGEX_FEATURES)[number];
|
|
3
|
-
export declare const FEATURE_BIT: Record<RegexFeature, number>;
|
|
4
|
-
export declare function hasFeature(mask: number, feature: RegexFeature): boolean;
|
|
5
|
-
export declare function featureSet(mask: number): Set<RegexFeature>;
|
|
6
|
-
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const REGEX_FEATURES = [
|
|
1
|
+
export const REGEX_FEATURES = [
|
|
2
2
|
"patternCharacter",
|
|
3
3
|
"startAnchor",
|
|
4
4
|
"endAnchor",
|
|
@@ -30,13 +30,7 @@ const REGEX_FEATURES = [
|
|
|
30
30
|
"unicodeEscapeSequence",
|
|
31
31
|
"otherEscape"
|
|
32
32
|
];
|
|
33
|
-
|
|
34
|
-
for (let index = 0; index < REGEX_FEATURES.length; index++) {
|
|
35
|
-
FEATURE_BIT[REGEX_FEATURES[index]] = 1 << index;
|
|
36
|
-
}
|
|
37
|
-
export function hasFeature(mask, feature) {
|
|
38
|
-
return (mask & FEATURE_BIT[feature]) !== 0;
|
|
39
|
-
}
|
|
33
|
+
/** @internal */
|
|
40
34
|
export function featureSet(mask) {
|
|
41
35
|
const features = new Set();
|
|
42
36
|
for (let index = 0; index < REGEX_FEATURES.length; index++) {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const CASE_INSENSITIVE = 1;
|
|
2
|
+
export declare const MULTILINE = 2;
|
|
3
|
+
export declare const DOT_ALL = 4;
|
|
4
|
+
export declare const UNICODE = 8;
|
|
5
|
+
export declare const UNICODE_SETS = 16;
|
|
6
|
+
export declare const WITHIN_LOOKAROUND = 32;
|
|
7
|
+
export declare const WITHIN_GROUP = 64;
|
|
8
|
+
export declare const WITHIN_RAW_LOOKAROUND = 128;
|
|
9
|
+
export declare function scopeOf(regex: RegExp): number;
|
|
10
|
+
export type ModifiersHook = (scope: number, modifiers: string) => number;
|
|
11
|
+
export declare function scopeWithModifiers(scope: number, modifiers: string): number;
|
|
12
|
+
export declare function flagsOf(scope: number): string;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export const CASE_INSENSITIVE = 1;
|
|
2
|
+
export const MULTILINE = 2;
|
|
3
|
+
export const DOT_ALL = 4;
|
|
4
|
+
export const UNICODE = 8;
|
|
5
|
+
export const UNICODE_SETS = 16;
|
|
6
|
+
export const WITHIN_LOOKAROUND = 32;
|
|
7
|
+
export const WITHIN_GROUP = 64;
|
|
8
|
+
export const WITHIN_RAW_LOOKAROUND = 128;
|
|
9
|
+
const MODIFIER_REMOVAL = "-";
|
|
10
|
+
function modifierBit(modifier) {
|
|
11
|
+
switch (modifier) {
|
|
12
|
+
case "i":
|
|
13
|
+
return CASE_INSENSITIVE;
|
|
14
|
+
case "m":
|
|
15
|
+
return MULTILINE;
|
|
16
|
+
default:
|
|
17
|
+
return DOT_ALL;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export function scopeOf(regex) {
|
|
21
|
+
return ((regex.ignoreCase ? CASE_INSENSITIVE : 0) |
|
|
22
|
+
(regex.multiline ? MULTILINE : 0) |
|
|
23
|
+
(regex.dotAll ? DOT_ALL : 0) |
|
|
24
|
+
(regex.unicode ? UNICODE : 0) |
|
|
25
|
+
(regex.unicodeSets ? UNICODE | UNICODE_SETS : 0));
|
|
26
|
+
}
|
|
27
|
+
export function scopeWithModifiers(scope, modifiers) {
|
|
28
|
+
let removing = false;
|
|
29
|
+
for (let index = 0; index < modifiers.length; index++) {
|
|
30
|
+
const modifier = modifiers[index];
|
|
31
|
+
if (modifier === MODIFIER_REMOVAL)
|
|
32
|
+
removing = true;
|
|
33
|
+
else if (removing)
|
|
34
|
+
scope &= ~modifierBit(modifier);
|
|
35
|
+
else
|
|
36
|
+
scope |= modifierBit(modifier);
|
|
37
|
+
}
|
|
38
|
+
return scope;
|
|
39
|
+
}
|
|
40
|
+
export function flagsOf(scope) {
|
|
41
|
+
return ((scope & CASE_INSENSITIVE ? "i" : "") +
|
|
42
|
+
(scope & MULTILINE ? "m" : "") +
|
|
43
|
+
(scope & DOT_ALL ? "s" : "") +
|
|
44
|
+
(scope & UNICODE_SETS ? "v" : scope & UNICODE ? "u" : ""));
|
|
45
|
+
}
|
|
@@ -1,8 +1,16 @@
|
|
|
1
|
-
import type { Part
|
|
2
|
-
|
|
1
|
+
import type { Part } from "./part.ts";
|
|
2
|
+
import { type CaretHook, type CaretRecorder } from "./caretHook.ts";
|
|
3
|
+
import type { BackreferenceRecorder, BackreferenceHook } from "./backreferenceHook.ts";
|
|
4
|
+
import type { RawLookaroundInfo } from "./rawLookaroundInfo.ts";
|
|
5
|
+
import { type ModifiersHook } from "./scope.ts";
|
|
6
|
+
export interface Hooks {
|
|
7
|
+
caret?: CaretHook;
|
|
8
|
+
backreference?: BackreferenceHook;
|
|
9
|
+
modifiers?: ModifiersHook;
|
|
10
|
+
}
|
|
11
|
+
export declare function walk(regex: RegExp, declaresNamedGroup: boolean, groupLimit: number, caretRecorder: CaretRecorder | undefined, backreferenceRecorder: BackreferenceRecorder | undefined, withModifiers: Hooks["modifiers"]): {
|
|
3
12
|
parts: Part[];
|
|
4
|
-
groupCount: number;
|
|
5
13
|
featureMask: number;
|
|
6
|
-
|
|
7
|
-
|
|
14
|
+
needs: number;
|
|
15
|
+
rawLookarounds: RawLookaroundInfo[] | undefined;
|
|
8
16
|
};
|