Comparing version 5.0.0 to 5.0.1
@@ -1,5 +0,1 @@ | ||
export function flagXPreprocessor(value: import("./utils.js").InterpolatedValue, runningContext: import("./utils.js").RunningContext, options: Required<import("./utils.js").RegexTagOptions>): { | ||
transformed: string; | ||
runningContext: import("./utils.js").RunningContext; | ||
}; | ||
/** | ||
@@ -11,1 +7,5 @@ Remove `(?:)` token separators (most likely added by flag x) in cases where it's safe to do so. | ||
export function clean(expression: string): string; | ||
export function flagXPreprocessor(value: import("./utils.js").InterpolatedValue, runningContext: import("./utils.js").RunningContext, options: Required<import("./utils.js").RegexTagOptions>): { | ||
transformed: string; | ||
runningContext: import("./utils.js").RunningContext; | ||
}; |
@@ -0,1 +1,8 @@ | ||
export class Pattern { | ||
/** @param {string} value */ | ||
constructor(value: string); | ||
/** @returns {string} */ | ||
toString(): string; | ||
#private; | ||
} | ||
/** | ||
@@ -37,8 +44,1 @@ Returns a value that can be interpolated into a `regex` template string without having its special | ||
export function pattern(template: TemplateStringsArray, ...substitutions: string[]): Pattern; | ||
export class Pattern { | ||
/** @param {string} value */ | ||
constructor(value: string); | ||
/** @returns {string} */ | ||
toString(): string; | ||
#private; | ||
} |
@@ -123,5 +123,17 @@ var __defProp = Object.defineProperty; | ||
var RegExpSubclass = class _RegExpSubclass extends RegExp { | ||
// Avoid #private to allow for subclassing | ||
/** | ||
Avoid `#private` to allow for subclassing. | ||
@private | ||
@type {Array<boolean> | undefined} | ||
*/ | ||
_captureMap; | ||
/** | ||
@param {string | RegExpSubclass} expression | ||
@param {string} [flags] | ||
@param {{useEmulationGroups: boolean;}} [options] | ||
*/ | ||
constructor(expression, flags, options) { | ||
if (expression instanceof RegExp && options) { | ||
throw new Error("Cannot provide options when copying regexp"); | ||
} | ||
let captureMap; | ||
@@ -240,6 +252,6 @@ if (options?.useEmulationGroups) { | ||
]); | ||
var patternModsSupported = (() => { | ||
var envSupportsFlagGroups = (() => { | ||
try { | ||
new RegExp("(?i:)"); | ||
} catch (e) { | ||
} catch { | ||
return false; | ||
@@ -249,6 +261,6 @@ } | ||
})(); | ||
var flagVSupported = (() => { | ||
var envSupportsFlagV = (() => { | ||
try { | ||
new RegExp("", "v"); | ||
} catch (e) { | ||
} catch { | ||
return false; | ||
@@ -359,8 +371,10 @@ } | ||
`.replace(/\s+/g, ""), "gsu"); | ||
function getEndContextForIncompleteExpression(incompleteExpression, { | ||
regexContext = RegexContext.DEFAULT, | ||
charClassContext = CharClassContext.DEFAULT, | ||
charClassDepth = 0, | ||
lastPos = 0 | ||
} = {}) { | ||
function getEndContextForIncompleteExpression(incompleteExpression, runningContext) { | ||
let { regexContext, charClassContext, charClassDepth, lastPos } = { | ||
regexContext: RegexContext.DEFAULT, | ||
charClassContext: CharClassContext.DEFAULT, | ||
charClassDepth: 0, | ||
lastPos: 0, | ||
...runningContext | ||
}; | ||
contextToken.lastIndex = lastPos; | ||
@@ -719,4 +733,9 @@ let match; | ||
let separatorNeeded = false; | ||
const update = (str, { prefix = true, postfix = false } = {}) => { | ||
str = (separatorNeeded && prefix ? "(?:)" : "") + str + (postfix ? "(?:)" : ""); | ||
const update = (str, options2) => { | ||
const opts = { | ||
prefix: true, | ||
postfix: false, | ||
...options2 | ||
}; | ||
str = (separatorNeeded && opts.prefix ? "(?:)" : "") + str + (opts.postfix ? "(?:)" : ""); | ||
separatorNeeded = false; | ||
@@ -963,3 +982,3 @@ return str; | ||
} else { | ||
const nestedNamedGroups = getNamedCapturingGroups(group.contents); | ||
const nestedNamedGroups = getNamedCapturingGroups(group.contents, { includeContents: false }); | ||
for (const name of nestedNamedGroups.keys()) { | ||
@@ -1010,3 +1029,3 @@ if (!namedGroups.get(name).isUnique) { | ||
} | ||
function getNamedCapturingGroups(expression, { includeContents } = {}) { | ||
function getNamedCapturingGroups(expression, { includeContents }) { | ||
const namedGroups = /* @__PURE__ */ new Map(); | ||
@@ -1082,3 +1101,3 @@ forEachUnescaped( | ||
}; | ||
function rewrite(expression = "", options = {}) { | ||
function rewrite(expression = "", options) { | ||
const opts = getOptions(options); | ||
@@ -1113,3 +1132,3 @@ if (opts.subclass) { | ||
} | ||
const useFlagV = opts.force.v || (opts.disable.v ? false : flagVSupported); | ||
const useFlagV = opts.force.v || (opts.disable.v ? false : envSupportsFlagV); | ||
opts.flags += useFlagV ? "v" : "u"; | ||
@@ -1206,3 +1225,3 @@ if (useFlagV) { | ||
if (re.ignoreCase !== outerFlags.includes("i")) { | ||
if (patternModsSupported) { | ||
if (envSupportsFlagGroups) { | ||
modFlagsObj.i = re.ignoreCase; | ||
@@ -1214,3 +1233,3 @@ } else { | ||
if (re.dotAll !== outerFlags.includes("s")) { | ||
if (patternModsSupported) { | ||
if (envSupportsFlagGroups) { | ||
modFlagsObj.s = re.dotAll; | ||
@@ -1222,3 +1241,3 @@ } else { | ||
if (re.multiline !== outerFlags.includes("m")) { | ||
if (patternModsSupported) { | ||
if (envSupportsFlagGroups) { | ||
modFlagsObj.m = re.multiline; | ||
@@ -1230,3 +1249,3 @@ } else { | ||
} | ||
if (patternModsSupported) { | ||
if (envSupportsFlagGroups) { | ||
const keys = Object.keys(modFlagsObj); | ||
@@ -1233,0 +1252,0 @@ let modifier = keys.filter((k) => modFlagsObj[k] === true).join(""); |
export const emulationGroupMarker: "$E$"; | ||
/** | ||
@class | ||
@param {string | RegExpSubclass} expression | ||
@param {string} [flags] | ||
@param {{useEmulationGroups: boolean;}} [options] | ||
Works the same as JavaScript's native `RegExp` constructor in all contexts, but automatically | ||
adjusts matches and subpattern indices (with flag `d`) to account for injected emulation groups. | ||
*/ | ||
export class RegExpSubclass extends RegExp { | ||
constructor(expression: any, flags: any, options: any); | ||
_captureMap: any; | ||
/** | ||
@param {string | RegExpSubclass} expression | ||
@param {string} [flags] | ||
@param {{useEmulationGroups: boolean;}} [options] | ||
*/ | ||
constructor(expression: string | RegExpSubclass, flags?: string, options?: { | ||
useEmulationGroups: boolean; | ||
}); | ||
/** | ||
Avoid `#private` to allow for subclassing. | ||
@private | ||
@type {Array<boolean> | undefined} | ||
*/ | ||
private _captureMap; | ||
} |
@@ -0,1 +1,7 @@ | ||
export type NamedCapturingGroupsMap = Map<string, { | ||
isUnique: boolean; | ||
contents?: string; | ||
groupNum?: number; | ||
numCaptures?: number; | ||
}>; | ||
/** | ||
@@ -7,7 +13,1 @@ @param {string} expression | ||
export function subroutines(expression: string, data?: import("./regex.js").PluginData): string; | ||
export type NamedCapturingGroupsMap = Map<string, { | ||
isUnique: boolean; | ||
contents?: string; | ||
groupNum?: number; | ||
numCaptures?: number; | ||
}>; |
@@ -0,1 +1,14 @@ | ||
export type RunningContext = { | ||
regexContext: string; | ||
charClassContext: string; | ||
charClassDepth: number; | ||
lastPos: number; | ||
}; | ||
export type InterpolatedValue = import("./regex.js").InterpolatedValue; | ||
export type RawTemplate = import("./regex.js").RawTemplate; | ||
export type RegexTagOptions = import("./regex.js").RegexTagOptions; | ||
export type Preprocessor = (value: InterpolatedValue, runningContext: RunningContext, options: Required<RegexTagOptions>) => { | ||
transformed: string; | ||
runningContext: RunningContext; | ||
}; | ||
/** | ||
@@ -7,2 +20,11 @@ @param {string} expression | ||
export function adjustNumberedBackrefs(expression: string, precedingCaptures: number): string; | ||
export const capturingDelim: any; | ||
export namespace CharClassContext { | ||
let DEFAULT: string; | ||
let ENCLOSED_P: string; | ||
let ENCLOSED_Q: string; | ||
let ENCLOSED_U: string; | ||
let INVALID_INCOMPLETE_TOKEN: string; | ||
let RANGE: string; | ||
} | ||
export function containsCharClassUnion(charClassPattern: any): boolean; | ||
@@ -14,2 +36,7 @@ /** | ||
export function countCaptures(expression: string): number; | ||
export const doublePunctuatorChars: "&!#$%*+,.:;<=>?@^`~"; | ||
export const enclosedTokenCharClassContexts: any; | ||
export const enclosedTokenRegexContexts: any; | ||
export const envSupportsFlagGroups: boolean; | ||
export const envSupportsFlagV: boolean; | ||
/** | ||
@@ -38,3 +65,5 @@ Escape special characters for the given context, assuming flag v. | ||
*/ | ||
export function getEndContextForIncompleteExpression(incompleteExpression: string, { regexContext, charClassContext, charClassDepth, lastPos, }?: Partial<RunningContext>): RunningContext; | ||
export function getEndContextForIncompleteExpression(incompleteExpression: string, runningContext?: Partial<RunningContext>): RunningContext; | ||
export const namedCapturingDelim: any; | ||
export const noncapturingDelim: any; | ||
/** | ||
@@ -66,2 +95,15 @@ @typedef {import('./regex.js').InterpolatedValue} InterpolatedValue | ||
}; | ||
export namespace RegexContext { | ||
let DEFAULT_1: string; | ||
export { DEFAULT_1 as DEFAULT }; | ||
export let CHAR_CLASS: string; | ||
let ENCLOSED_P_1: string; | ||
export { ENCLOSED_P_1 as ENCLOSED_P }; | ||
let ENCLOSED_U_1: string; | ||
export { ENCLOSED_U_1 as ENCLOSED_U }; | ||
export let GROUP_NAME: string; | ||
export let INTERVAL_QUANTIFIER: string; | ||
let INVALID_INCOMPLETE_TOKEN_1: string; | ||
export { INVALID_INCOMPLETE_TOKEN_1 as INVALID_INCOMPLETE_TOKEN }; | ||
} | ||
export function sandboxLoneCharClassCaret(str: any): any; | ||
@@ -84,43 +126,1 @@ export function sandboxLoneDoublePunctuatorChar(str: any): any; | ||
export function spliceStr(str: string, pos: number, oldValue: string, newValue: string): string; | ||
export namespace RegexContext { | ||
let DEFAULT: string; | ||
let CHAR_CLASS: string; | ||
let ENCLOSED_P: string; | ||
let ENCLOSED_U: string; | ||
let GROUP_NAME: string; | ||
let INTERVAL_QUANTIFIER: string; | ||
let INVALID_INCOMPLETE_TOKEN: string; | ||
} | ||
export namespace CharClassContext { | ||
let DEFAULT_1: string; | ||
export { DEFAULT_1 as DEFAULT }; | ||
let ENCLOSED_P_1: string; | ||
export { ENCLOSED_P_1 as ENCLOSED_P }; | ||
export let ENCLOSED_Q: string; | ||
let ENCLOSED_U_1: string; | ||
export { ENCLOSED_U_1 as ENCLOSED_U }; | ||
let INVALID_INCOMPLETE_TOKEN_1: string; | ||
export { INVALID_INCOMPLETE_TOKEN_1 as INVALID_INCOMPLETE_TOKEN }; | ||
export let RANGE: string; | ||
} | ||
export const enclosedTokenRegexContexts: any; | ||
export const enclosedTokenCharClassContexts: any; | ||
export const patternModsSupported: boolean; | ||
export const flagVSupported: boolean; | ||
export const doublePunctuatorChars: "&!#$%*+,.:;<=>?@^`~"; | ||
export const namedCapturingDelim: any; | ||
export const capturingDelim: any; | ||
export const noncapturingDelim: any; | ||
export type RunningContext = { | ||
regexContext: string; | ||
charClassContext: string; | ||
charClassDepth: number; | ||
lastPos: number; | ||
}; | ||
export type InterpolatedValue = import("./regex.js").InterpolatedValue; | ||
export type RawTemplate = import("./regex.js").RawTemplate; | ||
export type RegexTagOptions = import("./regex.js").RegexTagOptions; | ||
export type Preprocessor = (value: InterpolatedValue, runningContext: RunningContext, options: Required<RegexTagOptions>) => { | ||
transformed: string; | ||
runningContext: RunningContext; | ||
}; |
@@ -1,5 +0,1 @@ | ||
export function flagXPreprocessor(value: import("./utils.js").InterpolatedValue, runningContext: import("./utils.js").RunningContext, options: Required<import("./utils.js").RegexTagOptions>): { | ||
transformed: string; | ||
runningContext: import("./utils.js").RunningContext; | ||
}; | ||
/** | ||
@@ -11,1 +7,5 @@ Remove `(?:)` token separators (most likely added by flag x) in cases where it's safe to do so. | ||
export function clean(expression: string): string; | ||
export function flagXPreprocessor(value: import("./utils.js").InterpolatedValue, runningContext: import("./utils.js").RunningContext, options: Required<import("./utils.js").RegexTagOptions>): { | ||
transformed: string; | ||
runningContext: import("./utils.js").RunningContext; | ||
}; |
@@ -0,1 +1,8 @@ | ||
export class Pattern { | ||
/** @param {string} value */ | ||
constructor(value: string); | ||
/** @returns {string} */ | ||
toString(): string; | ||
#private; | ||
} | ||
/** | ||
@@ -37,8 +44,1 @@ Returns a value that can be interpolated into a `regex` template string without having its special | ||
export function pattern(template: TemplateStringsArray, ...substitutions: string[]): Pattern; | ||
export class Pattern { | ||
/** @param {string} value */ | ||
constructor(value: string); | ||
/** @returns {string} */ | ||
toString(): string; | ||
#private; | ||
} |
@@ -96,5 +96,17 @@ // node_modules/regex-utilities/src/index.js | ||
var RegExpSubclass = class _RegExpSubclass extends RegExp { | ||
// Avoid #private to allow for subclassing | ||
/** | ||
Avoid `#private` to allow for subclassing. | ||
@private | ||
@type {Array<boolean> | undefined} | ||
*/ | ||
_captureMap; | ||
/** | ||
@param {string | RegExpSubclass} expression | ||
@param {string} [flags] | ||
@param {{useEmulationGroups: boolean;}} [options] | ||
*/ | ||
constructor(expression, flags, options) { | ||
if (expression instanceof RegExp && options) { | ||
throw new Error("Cannot provide options when copying regexp"); | ||
} | ||
let captureMap; | ||
@@ -213,6 +225,6 @@ if (options?.useEmulationGroups) { | ||
]); | ||
var patternModsSupported = (() => { | ||
var envSupportsFlagGroups = (() => { | ||
try { | ||
new RegExp("(?i:)"); | ||
} catch (e) { | ||
} catch { | ||
return false; | ||
@@ -222,6 +234,6 @@ } | ||
})(); | ||
var flagVSupported = (() => { | ||
var envSupportsFlagV = (() => { | ||
try { | ||
new RegExp("", "v"); | ||
} catch (e) { | ||
} catch { | ||
return false; | ||
@@ -332,8 +344,10 @@ } | ||
`.replace(/\s+/g, ""), "gsu"); | ||
function getEndContextForIncompleteExpression(incompleteExpression, { | ||
regexContext = RegexContext.DEFAULT, | ||
charClassContext = CharClassContext.DEFAULT, | ||
charClassDepth = 0, | ||
lastPos = 0 | ||
} = {}) { | ||
function getEndContextForIncompleteExpression(incompleteExpression, runningContext) { | ||
let { regexContext, charClassContext, charClassDepth, lastPos } = { | ||
regexContext: RegexContext.DEFAULT, | ||
charClassContext: CharClassContext.DEFAULT, | ||
charClassDepth: 0, | ||
lastPos: 0, | ||
...runningContext | ||
}; | ||
contextToken.lastIndex = lastPos; | ||
@@ -692,4 +706,9 @@ let match; | ||
let separatorNeeded = false; | ||
const update = (str, { prefix = true, postfix = false } = {}) => { | ||
str = (separatorNeeded && prefix ? "(?:)" : "") + str + (postfix ? "(?:)" : ""); | ||
const update = (str, options2) => { | ||
const opts = { | ||
prefix: true, | ||
postfix: false, | ||
...options2 | ||
}; | ||
str = (separatorNeeded && opts.prefix ? "(?:)" : "") + str + (opts.postfix ? "(?:)" : ""); | ||
separatorNeeded = false; | ||
@@ -936,3 +955,3 @@ return str; | ||
} else { | ||
const nestedNamedGroups = getNamedCapturingGroups(group.contents); | ||
const nestedNamedGroups = getNamedCapturingGroups(group.contents, { includeContents: false }); | ||
for (const name of nestedNamedGroups.keys()) { | ||
@@ -983,3 +1002,3 @@ if (!namedGroups.get(name).isUnique) { | ||
} | ||
function getNamedCapturingGroups(expression, { includeContents } = {}) { | ||
function getNamedCapturingGroups(expression, { includeContents }) { | ||
const namedGroups = /* @__PURE__ */ new Map(); | ||
@@ -1055,3 +1074,3 @@ forEachUnescaped( | ||
}; | ||
function rewrite(expression = "", options = {}) { | ||
function rewrite(expression = "", options) { | ||
const opts = getOptions(options); | ||
@@ -1086,3 +1105,3 @@ if (opts.subclass) { | ||
} | ||
const useFlagV = opts.force.v || (opts.disable.v ? false : flagVSupported); | ||
const useFlagV = opts.force.v || (opts.disable.v ? false : envSupportsFlagV); | ||
opts.flags += useFlagV ? "v" : "u"; | ||
@@ -1179,3 +1198,3 @@ if (useFlagV) { | ||
if (re.ignoreCase !== outerFlags.includes("i")) { | ||
if (patternModsSupported) { | ||
if (envSupportsFlagGroups) { | ||
modFlagsObj.i = re.ignoreCase; | ||
@@ -1187,3 +1206,3 @@ } else { | ||
if (re.dotAll !== outerFlags.includes("s")) { | ||
if (patternModsSupported) { | ||
if (envSupportsFlagGroups) { | ||
modFlagsObj.s = re.dotAll; | ||
@@ -1195,3 +1214,3 @@ } else { | ||
if (re.multiline !== outerFlags.includes("m")) { | ||
if (patternModsSupported) { | ||
if (envSupportsFlagGroups) { | ||
modFlagsObj.m = re.multiline; | ||
@@ -1203,3 +1222,3 @@ } else { | ||
} | ||
if (patternModsSupported) { | ||
if (envSupportsFlagGroups) { | ||
const keys = Object.keys(modFlagsObj); | ||
@@ -1206,0 +1225,0 @@ let modifier = keys.filter((k) => modFlagsObj[k] === true).join(""); |
export const emulationGroupMarker: "$E$"; | ||
/** | ||
@class | ||
@param {string | RegExpSubclass} expression | ||
@param {string} [flags] | ||
@param {{useEmulationGroups: boolean;}} [options] | ||
Works the same as JavaScript's native `RegExp` constructor in all contexts, but automatically | ||
adjusts matches and subpattern indices (with flag `d`) to account for injected emulation groups. | ||
*/ | ||
export class RegExpSubclass extends RegExp { | ||
constructor(expression: any, flags: any, options: any); | ||
_captureMap: any; | ||
/** | ||
@param {string | RegExpSubclass} expression | ||
@param {string} [flags] | ||
@param {{useEmulationGroups: boolean;}} [options] | ||
*/ | ||
constructor(expression: string | RegExpSubclass, flags?: string, options?: { | ||
useEmulationGroups: boolean; | ||
}); | ||
/** | ||
Avoid `#private` to allow for subclassing. | ||
@private | ||
@type {Array<boolean> | undefined} | ||
*/ | ||
private _captureMap; | ||
} |
@@ -0,1 +1,7 @@ | ||
export type NamedCapturingGroupsMap = Map<string, { | ||
isUnique: boolean; | ||
contents?: string; | ||
groupNum?: number; | ||
numCaptures?: number; | ||
}>; | ||
/** | ||
@@ -7,7 +13,1 @@ @param {string} expression | ||
export function subroutines(expression: string, data?: import("./regex.js").PluginData): string; | ||
export type NamedCapturingGroupsMap = Map<string, { | ||
isUnique: boolean; | ||
contents?: string; | ||
groupNum?: number; | ||
numCaptures?: number; | ||
}>; |
@@ -0,1 +1,14 @@ | ||
export type RunningContext = { | ||
regexContext: string; | ||
charClassContext: string; | ||
charClassDepth: number; | ||
lastPos: number; | ||
}; | ||
export type InterpolatedValue = import("./regex.js").InterpolatedValue; | ||
export type RawTemplate = import("./regex.js").RawTemplate; | ||
export type RegexTagOptions = import("./regex.js").RegexTagOptions; | ||
export type Preprocessor = (value: InterpolatedValue, runningContext: RunningContext, options: Required<RegexTagOptions>) => { | ||
transformed: string; | ||
runningContext: RunningContext; | ||
}; | ||
/** | ||
@@ -7,2 +20,11 @@ @param {string} expression | ||
export function adjustNumberedBackrefs(expression: string, precedingCaptures: number): string; | ||
export const capturingDelim: any; | ||
export namespace CharClassContext { | ||
let DEFAULT: string; | ||
let ENCLOSED_P: string; | ||
let ENCLOSED_Q: string; | ||
let ENCLOSED_U: string; | ||
let INVALID_INCOMPLETE_TOKEN: string; | ||
let RANGE: string; | ||
} | ||
export function containsCharClassUnion(charClassPattern: any): boolean; | ||
@@ -14,2 +36,7 @@ /** | ||
export function countCaptures(expression: string): number; | ||
export const doublePunctuatorChars: "&!#$%*+,.:;<=>?@^`~"; | ||
export const enclosedTokenCharClassContexts: any; | ||
export const enclosedTokenRegexContexts: any; | ||
export const envSupportsFlagGroups: boolean; | ||
export const envSupportsFlagV: boolean; | ||
/** | ||
@@ -38,3 +65,5 @@ Escape special characters for the given context, assuming flag v. | ||
*/ | ||
export function getEndContextForIncompleteExpression(incompleteExpression: string, { regexContext, charClassContext, charClassDepth, lastPos, }?: Partial<RunningContext>): RunningContext; | ||
export function getEndContextForIncompleteExpression(incompleteExpression: string, runningContext?: Partial<RunningContext>): RunningContext; | ||
export const namedCapturingDelim: any; | ||
export const noncapturingDelim: any; | ||
/** | ||
@@ -66,2 +95,15 @@ @typedef {import('./regex.js').InterpolatedValue} InterpolatedValue | ||
}; | ||
export namespace RegexContext { | ||
let DEFAULT_1: string; | ||
export { DEFAULT_1 as DEFAULT }; | ||
export let CHAR_CLASS: string; | ||
let ENCLOSED_P_1: string; | ||
export { ENCLOSED_P_1 as ENCLOSED_P }; | ||
let ENCLOSED_U_1: string; | ||
export { ENCLOSED_U_1 as ENCLOSED_U }; | ||
export let GROUP_NAME: string; | ||
export let INTERVAL_QUANTIFIER: string; | ||
let INVALID_INCOMPLETE_TOKEN_1: string; | ||
export { INVALID_INCOMPLETE_TOKEN_1 as INVALID_INCOMPLETE_TOKEN }; | ||
} | ||
export function sandboxLoneCharClassCaret(str: any): any; | ||
@@ -84,43 +126,1 @@ export function sandboxLoneDoublePunctuatorChar(str: any): any; | ||
export function spliceStr(str: string, pos: number, oldValue: string, newValue: string): string; | ||
export namespace RegexContext { | ||
let DEFAULT: string; | ||
let CHAR_CLASS: string; | ||
let ENCLOSED_P: string; | ||
let ENCLOSED_U: string; | ||
let GROUP_NAME: string; | ||
let INTERVAL_QUANTIFIER: string; | ||
let INVALID_INCOMPLETE_TOKEN: string; | ||
} | ||
export namespace CharClassContext { | ||
let DEFAULT_1: string; | ||
export { DEFAULT_1 as DEFAULT }; | ||
let ENCLOSED_P_1: string; | ||
export { ENCLOSED_P_1 as ENCLOSED_P }; | ||
export let ENCLOSED_Q: string; | ||
let ENCLOSED_U_1: string; | ||
export { ENCLOSED_U_1 as ENCLOSED_U }; | ||
let INVALID_INCOMPLETE_TOKEN_1: string; | ||
export { INVALID_INCOMPLETE_TOKEN_1 as INVALID_INCOMPLETE_TOKEN }; | ||
export let RANGE: string; | ||
} | ||
export const enclosedTokenRegexContexts: any; | ||
export const enclosedTokenCharClassContexts: any; | ||
export const patternModsSupported: boolean; | ||
export const flagVSupported: boolean; | ||
export const doublePunctuatorChars: "&!#$%*+,.:;<=>?@^`~"; | ||
export const namedCapturingDelim: any; | ||
export const capturingDelim: any; | ||
export const noncapturingDelim: any; | ||
export type RunningContext = { | ||
regexContext: string; | ||
charClassContext: string; | ||
charClassDepth: number; | ||
lastPos: number; | ||
}; | ||
export type InterpolatedValue = import("./regex.js").InterpolatedValue; | ||
export type RawTemplate = import("./regex.js").RawTemplate; | ||
export type RegexTagOptions = import("./regex.js").RegexTagOptions; | ||
export type Preprocessor = (value: InterpolatedValue, runningContext: RunningContext, options: Required<RegexTagOptions>) => { | ||
transformed: string; | ||
runningContext: RunningContext; | ||
}; |
@@ -1,4 +0,4 @@ | ||
var Regex=(()=>{var Z=Object.defineProperty;var De=Object.getOwnPropertyDescriptor;var be=Object.getOwnPropertyNames;var Te=Object.prototype.hasOwnProperty;var Ue=(e,t)=>{for(var n in t)Z(e,n,{get:t[n],enumerable:!0})},Re=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of be(t))!Te.call(e,s)&&s!==n&&Z(e,s,{get:()=>t[s],enumerable:!(r=De(t,s))||r.enumerable});return e};var Fe=e=>Re(Z({},"__esModule",{value:!0}),e);var Je={};Ue(Je,{pattern:()=>H,regex:()=>We,rewrite:()=>Ke});var d=Object.freeze({DEFAULT:"DEFAULT",CHAR_CLASS:"CHAR_CLASS"});function A(e,t,n,r){let s=new RegExp(String.raw`${t}|(?<$skip>\[\^?|\\?.)`,"gsu"),o=[!1],a=0,i="";for(let u of e.matchAll(s)){let{0:c,groups:{$skip:p}}=u;if(!p&&(!r||r===d.DEFAULT==!a)){n instanceof Function?i+=n(u,{context:a?d.CHAR_CLASS:d.DEFAULT,negated:o[o.length-1]}):i+=n;continue}c[0]==="["?(a++,o.push(c[1]==="^")):c==="]"&&a&&(a--,o.pop()),i+=c}return i}function k(e,t,n,r){A(e,t,n,r)}function V(e,t,n=0,r){if(!new RegExp(t,"su").test(e))return null;let s=new RegExp(`${t}|(?<$skip>\\\\?.)`,"gsu");s.lastIndex=n;let o=0,a;for(;a=s.exec(e);){let{0:i,groups:{$skip:u}}=a;if(!u&&(!r||r===d.DEFAULT==!o))return a;i==="["?o++:i==="]"&&o&&o--,s.lastIndex==a.index&&s.lastIndex++}return null}function j(e,t,n){return!!V(e,t,0,n)}function J(e,t){let n=/\\?./gsu;n.lastIndex=t;let r=e.length,s=0,o=1,a;for(;a=n.exec(e);){let[i]=a;if(i==="[")s++;else if(s)i==="]"&&s--;else if(i==="(")o++;else if(i===")"&&(o--,!o)){r=a.index;break}}return e.slice(t,r)}var I="$E$",Q=class e extends RegExp{_captureMap;constructor(t,n,r){let s;r?.useEmulationGroups&&({expression:t,captureMap:s}=Oe(t)),super(t,n),s?this._captureMap=s:t instanceof e&&(this._captureMap=t._captureMap)}exec(t){let n=RegExp.prototype.exec.call(this,t);if(!n||!this._captureMap)return n;let r=[...n];n.length=1;let s;this.hasIndices&&(s=[...n.indices],n.indices.length=1);for(let o=1;o<r.length;o++)this._captureMap[o]&&(n.push(r[o]),this.hasIndices&&n.indices.push(s[o]));return n}};function Oe(e){let t=I.replace(/\$/g,"\\$"),n=[!0];return e=A(e,String.raw`\((?:(?!\?)|\?<(?![=!])[^>]+>)(?<mark>${t})?`,({0:r,groups:{mark:s}})=>s?(n.push(!1),r.slice(0,-I.length)):(n.push(!0),r),d.DEFAULT),{captureMap:n,expression:e}}var L=class{#e;constructor(t){this.#e=t}toString(){return String(this.#e)}};function H(e,...t){if(Array.isArray(e?.raw))return new L(e.raw.flatMap((n,r)=>r<e.raw.length-1?[n,t[r]]:n).join(""));if(!t.length)return new L(e===void 0?"":e);throw new Error(`Unexpected arguments: ${JSON.stringify([e,...t])}`)}var f={DEFAULT:"DEFAULT",CHAR_CLASS:"CHAR_CLASS",ENCLOSED_P:"ENCLOSED_P",ENCLOSED_U:"ENCLOSED_U",GROUP_NAME:"GROUP_NAME",INTERVAL_QUANTIFIER:"INTERVAL_QUANTIFIER",INVALID_INCOMPLETE_TOKEN:"INVALID_INCOMPLETE_TOKEN"},m={DEFAULT:"DEFAULT",ENCLOSED_P:"ENCLOSED_P",ENCLOSED_Q:"ENCLOSED_Q",ENCLOSED_U:"ENCLOSED_U",INVALID_INCOMPLETE_TOKEN:"INVALID_INCOMPLETE_TOKEN",RANGE:"RANGE"},q=new Set([f.ENCLOSED_P,f.ENCLOSED_U]),x=new Set([m.ENCLOSED_P,m.ENCLOSED_Q,m.ENCLOSED_U]),G=(()=>{try{new RegExp("(?i:)")}catch{return!1}return!0})(),ie=(()=>{try{new RegExp("","v")}catch{return!1}return!0})(),b="&!#$%*+,.:;<=>?@^`~",B=String.raw`\(\?<(?![=!])(?<captureName>[^>]+)>`,W=String.raw`\((?!\?)(?!(?<=\(\?\()DEFINE\))|${B}`,T=String.raw`\(\?(?:[:=!>A-Za-z\-]|<[=!]|\(DEFINE\))`;function ue(e,t){return A(e,String.raw`\\(?<num>[1-9]\d*)`,({groups:{num:n}})=>`\\${+n+t}`,d.DEFAULT)}var Pe=["Basic_Emoji","Emoji_Keycap_Sequence","RGI_Emoji_Modifier_Sequence","RGI_Emoji_Flag_Sequence","RGI_Emoji_Tag_Sequence","RGI_Emoji_ZWJ_Sequence","RGI_Emoji"].join("|"),ke=new RegExp(String.raw` | ||
var Regex=(()=>{var Z=Object.defineProperty;var _e=Object.getOwnPropertyDescriptor;var be=Object.getOwnPropertyNames;var Te=Object.prototype.hasOwnProperty;var Ue=(e,t)=>{for(var n in t)Z(e,n,{get:t[n],enumerable:!0})},xe=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of be(t))!Te.call(e,s)&&s!==n&&Z(e,s,{get:()=>t[s],enumerable:!(r=_e(t,s))||r.enumerable});return e};var Re=e=>xe(Z({},"__esModule",{value:!0}),e);var Je={};Ue(Je,{pattern:()=>H,regex:()=>We,rewrite:()=>Ke});var g=Object.freeze({DEFAULT:"DEFAULT",CHAR_CLASS:"CHAR_CLASS"});function C(e,t,n,r){let s=new RegExp(String.raw`${t}|(?<$skip>\[\^?|\\?.)`,"gsu"),a=[!1],i=0,o="";for(let u of e.matchAll(s)){let{0:c,groups:{$skip:p}}=u;if(!p&&(!r||r===g.DEFAULT==!i)){n instanceof Function?o+=n(u,{context:i?g.CHAR_CLASS:g.DEFAULT,negated:a[a.length-1]}):o+=n;continue}c[0]==="["?(i++,a.push(c[1]==="^")):c==="]"&&i&&(i--,a.pop()),o+=c}return o}function P(e,t,n,r){C(e,t,n,r)}function V(e,t,n=0,r){if(!new RegExp(t,"su").test(e))return null;let s=new RegExp(`${t}|(?<$skip>\\\\?.)`,"gsu");s.lastIndex=n;let a=0,i;for(;i=s.exec(e);){let{0:o,groups:{$skip:u}}=i;if(!u&&(!r||r===g.DEFAULT==!a))return i;o==="["?a++:o==="]"&&a&&a--,s.lastIndex==i.index&&s.lastIndex++}return null}function j(e,t,n){return!!V(e,t,0,n)}function J(e,t){let n=/\\?./gsu;n.lastIndex=t;let r=e.length,s=0,a=1,i;for(;i=n.exec(e);){let[o]=i;if(o==="[")s++;else if(s)o==="]"&&s--;else if(o==="(")a++;else if(o===")"&&(a--,!a)){r=i.index;break}}return e.slice(t,r)}var I="$E$",Q=class e extends RegExp{_captureMap;constructor(t,n,r){if(t instanceof RegExp&&r)throw new Error("Cannot provide options when copying regexp");let s;r?.useEmulationGroups&&({expression:t,captureMap:s}=Fe(t)),super(t,n),s?this._captureMap=s:t instanceof e&&(this._captureMap=t._captureMap)}exec(t){let n=RegExp.prototype.exec.call(this,t);if(!n||!this._captureMap)return n;let r=[...n];n.length=1;let s;this.hasIndices&&(s=[...n.indices],n.indices.length=1);for(let a=1;a<r.length;a++)this._captureMap[a]&&(n.push(r[a]),this.hasIndices&&n.indices.push(s[a]));return n}};function Fe(e){let t=I.replace(/\$/g,"\\$"),n=[!0];return e=C(e,String.raw`\((?:(?!\?)|\?<(?![=!])[^>]+>)(?<mark>${t})?`,({0:r,groups:{mark:s}})=>s?(n.push(!1),r.slice(0,-I.length)):(n.push(!0),r),g.DEFAULT),{captureMap:n,expression:e}}var L=class{#e;constructor(t){this.#e=t}toString(){return String(this.#e)}};function H(e,...t){if(Array.isArray(e?.raw))return new L(e.raw.flatMap((n,r)=>r<e.raw.length-1?[n,t[r]]:n).join(""));if(!t.length)return new L(e===void 0?"":e);throw new Error(`Unexpected arguments: ${JSON.stringify([e,...t])}`)}var f={DEFAULT:"DEFAULT",CHAR_CLASS:"CHAR_CLASS",ENCLOSED_P:"ENCLOSED_P",ENCLOSED_U:"ENCLOSED_U",GROUP_NAME:"GROUP_NAME",INTERVAL_QUANTIFIER:"INTERVAL_QUANTIFIER",INVALID_INCOMPLETE_TOKEN:"INVALID_INCOMPLETE_TOKEN"},m={DEFAULT:"DEFAULT",ENCLOSED_P:"ENCLOSED_P",ENCLOSED_Q:"ENCLOSED_Q",ENCLOSED_U:"ENCLOSED_U",INVALID_INCOMPLETE_TOKEN:"INVALID_INCOMPLETE_TOKEN",RANGE:"RANGE"},q=new Set([f.ENCLOSED_P,f.ENCLOSED_U]),k=new Set([m.ENCLOSED_P,m.ENCLOSED_Q,m.ENCLOSED_U]),G=(()=>{try{new RegExp("(?i:)")}catch{return!1}return!0})(),ie=(()=>{try{new RegExp("","v")}catch{return!1}return!0})(),b="&!#$%*+,.:;<=>?@^`~",B=String.raw`\(\?<(?![=!])(?<captureName>[^>]+)>`,W=String.raw`\((?!\?)(?!(?<=\(\?\()DEFINE\))|${B}`,T=String.raw`\(\?(?:[:=!>A-Za-z\-]|<[=!]|\(DEFINE\))`;function ue(e,t){return C(e,String.raw`\\(?<num>[1-9]\d*)`,({groups:{num:n}})=>`\\${+n+t}`,g.DEFAULT)}var Oe=["Basic_Emoji","Emoji_Keycap_Sequence","RGI_Emoji_Modifier_Sequence","RGI_Emoji_Flag_Sequence","RGI_Emoji_Tag_Sequence","RGI_Emoji_ZWJ_Sequence","RGI_Emoji"].join("|"),Pe=new RegExp(String.raw` | ||
\\(?: c[A-Za-z] | ||
| p\{(?<pStrProp>${Pe})\} | ||
| p\{(?<pStrProp>${Oe})\} | ||
| [pP]\{[^\}]+\} | ||
@@ -13,3 +13,3 @@ | (?<qStrProp>q) | ||
| . | ||
`.replace(/\s+/g,""),"gsu");function X(e){let t=!1,n;for(let{0:r,groups:s}of e.matchAll(ke)){if(s.pStrProp||s.qStrProp||r==="["&&t)return!0;if(["-","--","&&"].includes(r))t=!1;else if(r!=="["&&r!=="]"){if(t||n==="]")return!0;t=!0}n=r}return!1}function U(e){let t=0;return k(e,W,()=>t++,d.DEFAULT),t}function Y(e,t){return t===d.CHAR_CLASS?e.replace(new RegExp(String.raw`[()\[\]{}|\\/\-${b}]`,"g"),"\\$&"):e.replace(/[()\[\]{}|\\^$*+?.]/g,"\\$&")}function le(e,t,n){let r=e.replace(/\\./gsu,"");if(r.endsWith("\\"))return"\\";if(t===f.DEFAULT)return ae(r,"(",")");if(t===f.CHAR_CLASS&&!x.has(n))return ae(r,"[","]");if(t===f.INTERVAL_QUANTIFIER||q.has(t)||x.has(n)){if(r.includes("}"))return"}"}else if(t===f.GROUP_NAME&&r.includes(">"))return">";return""}var oe=new RegExp(String.raw` | ||
`.replace(/\s+/g,""),"gsu");function X(e){let t=!1,n;for(let{0:r,groups:s}of e.matchAll(Pe)){if(s.pStrProp||s.qStrProp||r==="["&&t)return!0;if(["-","--","&&"].includes(r))t=!1;else if(r!=="["&&r!=="]"){if(t||n==="]")return!0;t=!0}n=r}return!1}function U(e){let t=0;return P(e,W,()=>t++,g.DEFAULT),t}function Y(e,t){return t===g.CHAR_CLASS?e.replace(new RegExp(String.raw`[()\[\]{}|\\/\-${b}]`,"g"),"\\$&"):e.replace(/[()\[\]{}|\\^$*+?.]/g,"\\$&")}function le(e,t,n){let r=e.replace(/\\./gsu,"");if(r.endsWith("\\"))return"\\";if(t===f.DEFAULT)return ae(r,"(",")");if(t===f.CHAR_CLASS&&!k.has(n))return ae(r,"[","]");if(t===f.INTERVAL_QUANTIFIER||q.has(t)||k.has(n)){if(r.includes("}"))return"}"}else if(t===f.GROUP_NAME&&r.includes(">"))return">";return""}var oe=new RegExp(String.raw` | ||
(?<groupN>\(\?<(?![=!])|\\[gk]<) | ||
@@ -27,3 +27,3 @@ | (?<enclosedPU>\\[pPu]\{) | ||
| \\?. | ||
`.replace(/\s+/g,""),"gsu");function R(e,{regexContext:t=f.DEFAULT,charClassContext:n=m.DEFAULT,charClassDepth:r=0,lastPos:s=0}={}){oe.lastIndex=s;let o;for(;o=oe.exec(e);){let{0:a,groups:{groupN:i,enclosedPU:u,enclosedQ:c,intervalQ:p,incompleteT:g}}=o;a==="["?(r++,t=f.CHAR_CLASS,n=m.DEFAULT):a==="]"&&t===f.CHAR_CLASS?(r&&r--,r||(t=f.DEFAULT),n=m.DEFAULT):t===f.CHAR_CLASS?g?n=m.INVALID_INCOMPLETE_TOKEN:a==="-"?n=m.RANGE:u?n=a[1]==="u"?m.ENCLOSED_U:m.ENCLOSED_P:c?n=m.ENCLOSED_Q:(a==="}"&&x.has(n)||n===m.INVALID_INCOMPLETE_TOKEN||n===m.RANGE)&&(n=m.DEFAULT):g?t=f.INVALID_INCOMPLETE_TOKEN:i?t=f.GROUP_NAME:u?t=a[1]==="u"?f.ENCLOSED_U:f.ENCLOSED_P:p?t=f.INTERVAL_QUANTIFIER:(a===">"&&t===f.GROUP_NAME||a==="}"&&(t===f.INTERVAL_QUANTIFIER||q.has(t))||t===f.INVALID_INCOMPLETE_TOKEN)&&(t=f.DEFAULT)}return{regexContext:t,charClassContext:n,charClassDepth:r,lastPos:e.length}}function ae(e,t,n){let r=0;for(let[s]of e.matchAll(new RegExp(`[${Y(t+n,d.CHAR_CLASS)}]`,"g")))if(r+=s===t?1:-1,r<0)return n;return r>0?t:""}function ce(e,t,n,r){let s={raw:[]},o=[],a;return e.raw.forEach((i,u)=>{let c=n(i,{...a,lastPos:0},r);if(s.raw.push(c.transformed),a=c.runningContext,u<e.raw.length-1){let p=t[u];if(p instanceof L){let g=n(p,{...a,lastPos:0},r);o.push(H(g.transformed)),a=g.runningContext}else o.push(p)}}),{template:s,substitutions:o}}function fe(e){return e.replace(/^\^/,"\\^^")}function K(e){return e.replace(new RegExp(`^([${b}])(?!\\1)`),(t,n,r)=>`\\${t}${r+1===e.length?"":t}`)}function M(e,t){return A(e,String.raw`\\0(?!\d)`,"\\x00",t)}function F(e,t,n,r){return e.slice(0,t)+r+e.slice(t+n.length)}var pe=new RegExp(String.raw`(?<noncapturingStart>${T})|(?<capturingStart>\((?:\?<[^>]+>)?)|\\?.`,"gsu");function de(e,t){if(!/\(\?>/.test(e))return e;let n="(?>",r=`(?:(?=(${t?.useEmulationGroups?I:""}`,s=[0],o=0,a=0,i=NaN,u;do{u=!1;let c=0,p=0,g=!1,l;for(pe.lastIndex=Number.isNaN(i)?0:i+r.length;l=pe.exec(e);){let{0:E,index:w,groups:{capturingStart:h,noncapturingStart:C}}=l;if(E==="[")c++;else if(c)E==="]"&&c--;else if(E===n&&!g)i=w,g=!0;else if(g&&C)p++;else if(h)g?p++:(o++,s.push(o+a));else if(E===")"&&g){if(!p){a++,e=`${e.slice(0,i)}${r}${e.slice(i+n.length,w)}))<$$${a+o}>)${e.slice(w+1)}`,u=!0;break}p--}}}while(u);return e=A(e,String.raw`\\(?<backrefNum>[1-9]\d*)|<\$\$(?<wrappedBackrefNum>\d+)>`,({0:c,groups:{backrefNum:p,wrappedBackrefNum:g}})=>{if(p){let l=+p;if(l>s.length-1)throw new Error(`Backref "${c}" greater than number of captures`);return`\\${s[l]}`}return`\\${g}`},d.DEFAULT),e}var Ee=String.raw`(?:[?*+]|\{\d+(?:,\d*)?\})`,ee=new RegExp(String.raw` | ||
`.replace(/\s+/g,""),"gsu");function x(e,t){let{regexContext:n,charClassContext:r,charClassDepth:s,lastPos:a}={regexContext:f.DEFAULT,charClassContext:m.DEFAULT,charClassDepth:0,lastPos:0,...t};oe.lastIndex=a;let i;for(;i=oe.exec(e);){let{0:o,groups:{groupN:u,enclosedPU:c,enclosedQ:p,intervalQ:E,incompleteT:l}}=i;o==="["?(s++,n=f.CHAR_CLASS,r=m.DEFAULT):o==="]"&&n===f.CHAR_CLASS?(s&&s--,s||(n=f.DEFAULT),r=m.DEFAULT):n===f.CHAR_CLASS?l?r=m.INVALID_INCOMPLETE_TOKEN:o==="-"?r=m.RANGE:c?r=o[1]==="u"?m.ENCLOSED_U:m.ENCLOSED_P:p?r=m.ENCLOSED_Q:(o==="}"&&k.has(r)||r===m.INVALID_INCOMPLETE_TOKEN||r===m.RANGE)&&(r=m.DEFAULT):l?n=f.INVALID_INCOMPLETE_TOKEN:u?n=f.GROUP_NAME:c?n=o[1]==="u"?f.ENCLOSED_U:f.ENCLOSED_P:E?n=f.INTERVAL_QUANTIFIER:(o===">"&&n===f.GROUP_NAME||o==="}"&&(n===f.INTERVAL_QUANTIFIER||q.has(n))||n===f.INVALID_INCOMPLETE_TOKEN)&&(n=f.DEFAULT)}return{regexContext:n,charClassContext:r,charClassDepth:s,lastPos:e.length}}function ae(e,t,n){let r=0;for(let[s]of e.matchAll(new RegExp(`[${Y(t+n,g.CHAR_CLASS)}]`,"g")))if(r+=s===t?1:-1,r<0)return n;return r>0?t:""}function ce(e,t,n,r){let s={raw:[]},a=[],i;return e.raw.forEach((o,u)=>{let c=n(o,{...i,lastPos:0},r);if(s.raw.push(c.transformed),i=c.runningContext,u<e.raw.length-1){let p=t[u];if(p instanceof L){let E=n(p,{...i,lastPos:0},r);a.push(H(E.transformed)),i=E.runningContext}else a.push(p)}}),{template:s,substitutions:a}}function fe(e){return e.replace(/^\^/,"\\^^")}function K(e){return e.replace(new RegExp(`^([${b}])(?!\\1)`),(t,n,r)=>`\\${t}${r+1===e.length?"":t}`)}function M(e,t){return C(e,String.raw`\\0(?!\d)`,"\\x00",t)}function R(e,t,n,r){return e.slice(0,t)+r+e.slice(t+n.length)}var pe=new RegExp(String.raw`(?<noncapturingStart>${T})|(?<capturingStart>\((?:\?<[^>]+>)?)|\\?.`,"gsu");function ge(e,t){if(!/\(\?>/.test(e))return e;let n="(?>",r=`(?:(?=(${t?.useEmulationGroups?I:""}`,s=[0],a=0,i=0,o=NaN,u;do{u=!1;let c=0,p=0,E=!1,l;for(pe.lastIndex=Number.isNaN(o)?0:o+r.length;l=pe.exec(e);){let{0:d,index:A,groups:{capturingStart:h,noncapturingStart:S}}=l;if(d==="[")c++;else if(c)d==="]"&&c--;else if(d===n&&!E)o=A,E=!0;else if(E&&S)p++;else if(h)E?p++:(a++,s.push(a+i));else if(d===")"&&E){if(!p){i++,e=`${e.slice(0,o)}${r}${e.slice(o+n.length,A)}))<$$${i+a}>)${e.slice(A+1)}`,u=!0;break}p--}}}while(u);return e=C(e,String.raw`\\(?<backrefNum>[1-9]\d*)|<\$\$(?<wrappedBackrefNum>\d+)>`,({0:c,groups:{backrefNum:p,wrappedBackrefNum:E}})=>{if(p){let l=+p;if(l>s.length-1)throw new Error(`Backref "${c}" greater than number of captures`);return`\\${s[l]}`}return`\\${E}`},g.DEFAULT),e}var de=String.raw`(?:[?*+]|\{\d+(?:,\d*)?\})`,ee=new RegExp(String.raw` | ||
\\(?: \d+ | ||
@@ -41,5 +41,5 @@ | c[A-Za-z] | ||
))? | ||
| (?<qBase>${Ee})(?<qMod>[?+]?)(?<invalidQ>[?*+\{]?) | ||
| (?<qBase>${de})(?<qMod>[?+]?)(?<invalidQ>[?*+\{]?) | ||
| \\?. | ||
`.replace(/\s+/g,""),"gsu");function ge(e){if(!new RegExp(`${Ee}\\+`).test(e))return e;let t=[],n=null,r=null,s="",o=0,a;for(ee.lastIndex=0;a=ee.exec(e);){let{0:i,index:u,groups:{qBase:c,qMod:p,invalidQ:g}}=a;if(i==="[")o||(r=u),o++;else if(i==="]")o?o--:r=null;else if(!o)if(p==="+"&&s&&!s.startsWith("(")){if(g)throw new Error(`Invalid quantifier "${i}"`);let l=-1;if(/^\{\d+\}$/.test(c))e=F(e,u+c.length,p,"");else{if(s===")"||s==="]"){let E=s===")"?n:r;if(E===null)throw new Error(`Invalid unmatched "${s}"`);e=`${e.slice(0,E)}(?>${e.slice(E,u)}${c})${e.slice(u+i.length)}`}else e=`${e.slice(0,u-s.length)}(?>${s}${c})${e.slice(u+i.length)}`;l+=4}ee.lastIndex+=l}else i[0]==="("?t.push(u):i===")"&&(n=t.length?t.pop():null);s=i}return e}var xe="&!#%,:;<=>@`~",Ge=new RegExp(String.raw` | ||
`.replace(/\s+/g,""),"gsu");function Ee(e){if(!new RegExp(`${de}\\+`).test(e))return e;let t=[],n=null,r=null,s="",a=0,i;for(ee.lastIndex=0;i=ee.exec(e);){let{0:o,index:u,groups:{qBase:c,qMod:p,invalidQ:E}}=i;if(o==="[")a||(r=u),a++;else if(o==="]")a?a--:r=null;else if(!a)if(p==="+"&&s&&!s.startsWith("(")){if(E)throw new Error(`Invalid quantifier "${o}"`);let l=-1;if(/^\{\d+\}$/.test(c))e=R(e,u+c.length,p,"");else{if(s===")"||s==="]"){let d=s===")"?n:r;if(d===null)throw new Error(`Invalid unmatched "${s}"`);e=`${e.slice(0,d)}(?>${e.slice(d,u)}${c})${e.slice(u+o.length)}`}else e=`${e.slice(0,u-s.length)}(?>${s}${c})${e.slice(u+o.length)}`;l+=4}ee.lastIndex+=l}else o[0]==="("?t.push(u):o===")"&&(n=t.length?t.pop():null);s=o}return e}var ke="&!#%,:;<=>@`~",Ge=new RegExp(String.raw` | ||
\[\^?-? | ||
@@ -49,6 +49,6 @@ | --?\] | ||
| -- | ||
| \\(?<vOnlyEscape>[${xe}]) | ||
| \\(?<vOnlyEscape>[${ke}]) | ||
| \\[pPu]\{[^}]+\} | ||
| \\?. | ||
`.replace(/\s+/g,""),"gsu");function me(e){let t='Invalid unescaped "-" in character class',n=!1,r="";for(let{0:s,groups:{dp:o,vOnlyEscape:a}}of e.matchAll(Ge)){if(s[0]==="["){if(n)throw new Error("Invalid nested character class when flag v not supported; possibly from interpolation");if(s.endsWith("-"))throw new Error(t);n=!0}else if(s.endsWith("]")){if(s[0]==="-")throw new Error(t);n=!1}else if(n){if(s==="&&"||s==="--")throw new Error(`Invalid set operator "${s}" when flag v not supported`);if(o)throw new Error(`Invalid double punctuator "${s}", reserved by flag v`);if("(){}/|".includes(s))throw new Error(`Invalid unescaped "${s}" in character class`);if(a){r+=a;continue}}r+=s}return r}var Me=new RegExp(String.raw` | ||
`.replace(/\s+/g,""),"gsu");function me(e){let t='Invalid unescaped "-" in character class',n=!1,r="";for(let{0:s,groups:{dp:a,vOnlyEscape:i}}of e.matchAll(Ge)){if(s[0]==="["){if(n)throw new Error("Invalid nested character class when flag v not supported; possibly from interpolation");if(s.endsWith("-"))throw new Error(t);n=!0}else if(s.endsWith("]")){if(s[0]==="-")throw new Error(t);n=!1}else if(n){if(s==="&&"||s==="--")throw new Error(`Invalid set operator "${s}" when flag v not supported`);if(a)throw new Error(`Invalid double punctuator "${s}", reserved by flag v`);if("(){}/|".includes(s))throw new Error(`Invalid unescaped "${s}" in character class`);if(i){r+=i;continue}}r+=s}return r}var Me=new RegExp(String.raw` | ||
${T} | ||
@@ -58,3 +58,3 @@ | \(\?< | ||
| \\?. | ||
`.replace(/\s+/g,""),"gsu");function he(e,t){e=String(e);let n="",r="";for(let{0:s,groups:{backrefNum:o}}of e.matchAll(Me)){n+=s,t=R(n,t);let{regexContext:a}=t;if(a===f.DEFAULT)if(s==="(")r+="(?:";else{if(o)throw new Error(`Invalid decimal escape "${s}" with implicit flag n; replace with named backreference`);r+=s}else r+=s}return{transformed:r,runningContext:t}}var Ae=/^\s$/,ye=/^\\[\s#]$/,te=/^[ \t]$/,ve=/^\\[ \t]$/,Ve=new RegExp(String.raw` | ||
`.replace(/\s+/g,""),"gsu");function he(e,t){e=String(e);let n="",r="";for(let{0:s,groups:{backrefNum:a}}of e.matchAll(Me)){n+=s,t=x(n,t);let{regexContext:i}=t;if(i===f.DEFAULT)if(s==="(")r+="(?:";else{if(a)throw new Error(`Invalid decimal escape "${s}" with implicit flag n; replace with named backreference`);r+=s}else r+=s}return{transformed:r,runningContext:t}}var Ce=/^\s$/,ye=/^\\[\s#]$/,te=/^[ \t]$/,ve=/^\\[ \t]$/,Ve=new RegExp(String.raw` | ||
\\(?: [gk]< | ||
@@ -73,4 +73,4 @@ | [pPu]\{ | ||
| \\?. | ||
`.replace(/\s+/g,""),"gsu");function we(e,t,n){e=String(e);let r=!1,s=!1,o=!1,a="",i="",u="",c="",p=!1,g=(l,{prefix:E=!0,postfix:w=!1}={})=>(l=(p&&E?"(?:)":"")+l+(w?"(?:)":""),p=!1,l);for(let{0:l,index:E}of e.matchAll(Ve)){if(o){l===` | ||
`&&(o=!1,p=!0);continue}if(r){if(Ae.test(l))continue;r=!1,p=!0}else if(s){if(te.test(l))continue;s=!1}a+=l,t=R(a,t);let{regexContext:w,charClassContext:h}=t;if(l==="-"&&w===f.CHAR_CLASS&&c===m.RANGE&&(n.flags.includes("v")||n.unicodeSetsPlugin))throw new Error("Invalid unescaped hyphen as the end value for a range");if(w===f.DEFAULT&&/^(?:[?*+]|\?\?)$/.test(l)||w===f.INTERVAL_QUANTIFIER&&l==="{")i+=g(l,{prefix:!1,postfix:u==="("&&l==="?"});else if(w===f.DEFAULT)Ae.test(l)?r=!0:l.startsWith("#")?o=!0:ye.test(l)?i+=g(l[1],{prefix:!1}):i+=g(l);else if(w===f.CHAR_CLASS&&l!=="["&&l!=="[^")if(te.test(l)&&(h===m.DEFAULT||h===m.ENCLOSED_Q||h===m.RANGE))s=!0;else{if(h===m.INVALID_INCOMPLETE_TOKEN)throw new Error(`Invalid incomplete token in character class: "${l}"`);if(ve.test(l)&&(h===m.DEFAULT||h===m.ENCLOSED_Q))i+=g(l[1],{prefix:!1});else if(h===m.DEFAULT){let C=e[E+1]??"",S=M(l);(te.test(C)||l==="^")&&(S=K(S)),i+=g(S)}else i+=g(l)}else i+=g(l);r||s||o||(u=l,c=h)}return{transformed:i,runningContext:t}}function Ne(e){let t=String.raw`\(\?:\)`;e=A(e,`(?:${t}){2,}`,"(?:)",d.DEFAULT);let n=I.replace(/\$/g,"\\$");return e=A(e,String.raw`(?:${t}(?=[)|.[$\\]|\((?!DEFINE)|$)|(?<=[()|.\]^>]|\\[bBdDfnrsStvwW]|\(\?(?:[:=!]|<[=!])|^)${t}(?![?*+{]))(?!${n})`,"",d.DEFAULT),e}function Ce(e,t){let n=Le(e,{includeContents:!0}),r=Qe(e,n,!!t?.useEmulationGroups);return He(r,n)}var je=String.raw`\\g<(?<subroutineName>[^>&]+)>`,y=new RegExp(String.raw` | ||
`.replace(/\s+/g,""),"gsu");function Ae(e,t,n){e=String(e);let r=!1,s=!1,a=!1,i="",o="",u="",c="",p=!1,E=(l,d)=>{let A={prefix:!0,postfix:!1,...d};return l=(p&&A.prefix?"(?:)":"")+l+(A.postfix?"(?:)":""),p=!1,l};for(let{0:l,index:d}of e.matchAll(Ve)){if(a){l===` | ||
`&&(a=!1,p=!0);continue}if(r){if(Ce.test(l))continue;r=!1,p=!0}else if(s){if(te.test(l))continue;s=!1}i+=l,t=x(i,t);let{regexContext:A,charClassContext:h}=t;if(l==="-"&&A===f.CHAR_CLASS&&c===m.RANGE&&(n.flags.includes("v")||n.unicodeSetsPlugin))throw new Error("Invalid unescaped hyphen as the end value for a range");if(A===f.DEFAULT&&/^(?:[?*+]|\?\?)$/.test(l)||A===f.INTERVAL_QUANTIFIER&&l==="{")o+=E(l,{prefix:!1,postfix:u==="("&&l==="?"});else if(A===f.DEFAULT)Ce.test(l)?r=!0:l.startsWith("#")?a=!0:ye.test(l)?o+=E(l[1],{prefix:!1}):o+=E(l);else if(A===f.CHAR_CLASS&&l!=="["&&l!=="[^")if(te.test(l)&&(h===m.DEFAULT||h===m.ENCLOSED_Q||h===m.RANGE))s=!0;else{if(h===m.INVALID_INCOMPLETE_TOKEN)throw new Error(`Invalid incomplete token in character class: "${l}"`);if(ve.test(l)&&(h===m.DEFAULT||h===m.ENCLOSED_Q))o+=E(l[1],{prefix:!1});else if(h===m.DEFAULT){let S=e[d+1]??"",N=M(l);(te.test(S)||l==="^")&&(N=K(N)),o+=E(N)}else o+=E(l)}else o+=E(l);r||s||a||(u=l,c=h)}return{transformed:o,runningContext:t}}function we(e){let t=String.raw`\(\?:\)`;e=C(e,`(?:${t}){2,}`,"(?:)",g.DEFAULT);let n=I.replace(/\$/g,"\\$");return e=C(e,String.raw`(?:${t}(?=[)|.[$\\]|\((?!DEFINE)|$)|(?<=[()|.\]^>]|\\[bBdDfnrsStvwW]|\(\?(?:[:=!]|<[=!])|^)${t}(?![?*+{]))(?!${n})`,"",g.DEFAULT),e}function Se(e,t){let n=Le(e,{includeContents:!0}),r=Qe(e,n,!!t?.useEmulationGroups);return He(r,n)}var je=String.raw`\\g<(?<subroutineName>[^>&]+)>`,y=new RegExp(String.raw` | ||
${je} | ||
@@ -81,3 +81,3 @@ | (?<capturingStart>${W}) | ||
| \\?. | ||
`.replace(/\s+/g,""),"gsu");function Qe(e,t,n){if(!/\\g</.test(e))return e;let r=j(e,"\\\\(?:[1-9]|k<[^>]+>)",d.DEFAULT),s=r?`(${n?I:""}`:"(?:",o=new Map,a=[],i=[0],u=0,c=0,p=0,g=0,l=0,E=e,w;for(y.lastIndex=0;w=y.exec(E);){let{0:h,index:C,groups:{subroutineName:S,capturingStart:z,backrefNum:O,backrefName:v}}=w;if(h==="[")l++;else if(l)h==="]"&&l--;else if(S){if(!t.has(S))throw new Error(`Invalid named capture referenced by subroutine ${h}`);if(o.has(S))throw new Error(`Subroutine ${h} followed a recursive reference`);let N=t.get(S).contents,_=`${s}${N})`;r&&(p=0,c++),o.set(S,{unclosedGroupCount:qe(_)}),a.push(S),E=F(E,C,h,_),y.lastIndex-=h.length-s.length}else if(z)o.size?(r&&(p++,c++),h!=="("&&(E=F(E,C,h,s),y.lastIndex-=h.length-s.length)):r&&(i.push(re(i)+1+c-g),g=c,u++);else if((O||v)&&o.size){let N=O?+O:t.get(v)?.groupNum,_=!1;for(let $ of a){let D=t.get($);if(N>=D.groupNum&&N<=D.groupNum+D.numCaptures){_=!0;break}}if(_){let $=t.get(re(a)),D=u+c-p,P=`\\k<$$b${N}s${D}r${$.groupNum}c${$.numCaptures}>`;E=F(E,C,h,P),y.lastIndex+=P.length-h.length}}else if(h===")"&&o.size){let N=o.get(re(a));N.unclosedGroupCount--,N.unclosedGroupCount||o.delete(a.pop())}}return r&&(E=A(E,String.raw`\\(?:(?<bNum>[1-9]\d*)|k<\$\$b(?<bNumSub>\d+)s(?<subNum>\d+)r(?<refNum>\d+)c(?<refCaps>\d+)>)`,({0:h,groups:{bNum:C,bNumSub:S,subNum:z,refNum:O,refCaps:v}})=>{if(C){let P=+C;if(P>i.length-1)throw new Error(`Backref "${h}" greater than number of captures`);return`\\${i[P]}`}let N=+S,_=+z,$=+O,D=+v;return N<$||N>$+D?`\\${i[N]}`:`\\${_-$+N}`},d.DEFAULT)),E}var ne=new RegExp(String.raw`${B}|\(\?:\)|(?<invalid>\\?.)`,"gsu");function He(e,t){let n=V(e,String.raw`\(\?\(DEFINE\)`,0,d.DEFAULT);if(!n)return e;let r=Se(e,n);if(r.afterPos<e.length)throw new Error("DEFINE group allowed only at the end of a regex");if(r.afterPos>e.length)throw new Error("DEFINE group is unclosed");let s;for(ne.lastIndex=0;s=ne.exec(r.contents);){let{captureName:o,invalid:a}=s.groups;if(o){let i=Se(r.contents,s),u;if(!t.get(o).isUnique)u=o;else{let c=Le(i.contents);for(let p of c.keys())if(!t.get(p).isUnique){u=p;break}}if(u)throw new Error(`Duplicate group name "${u}" within DEFINE`);ne.lastIndex=i.afterPos}else if(a)throw new Error("DEFINE group includes unsupported syntax at top level")}return e.slice(0,n.index)}function qe(e){let t=0;return k(e,"\\(",()=>t++,d.DEFAULT),t}function Be(e,t){let n=0,r=0,s;for(;s=V(e,W,r,d.DEFAULT);){let{0:o,index:a,groups:{captureName:i}}=s;if(n++,i===t)break;r=a+o.length}return n}function Se(e,t){let n=t.index+t[0].length,r=J(e,n),s=n+r.length+1;return{contents:r,afterPos:s}}function Le(e,{includeContents:t}={}){let n=new Map;return k(e,B,({0:r,index:s,groups:{captureName:o}})=>{if(n.has(o))n.get(o).isUnique=!1;else{let a={isUnique:!0};if(t){let i=J(e,s+r.length);Object.assign(a,{contents:i,groupNum:Be(e,o),numCaptures:U(i)})}n.set(o,a)}},d.DEFAULT),n}function re(e){return e[e.length-1]}var We=(e,...t)=>{if(Array.isArray(e?.raw))return se({},e,...t);if((typeof e=="string"||e===void 0)&&!t.length)return se.bind(null,{flags:e??""});if({}.toString.call(e)==="[object Object]"&&!t.length)return se.bind(null,e);throw new Error(`Unexpected arguments: ${JSON.stringify([e,...t])}`)},se=(e,t,...n)=>{let r=$e(e),s=Ie(t,n,r),o=0,a="",i;s.template.raw.forEach((u,c)=>{let p=!!(s.template.raw[c]||s.template.raw[c+1]);o+=U(u),a+=M(u,d.CHAR_CLASS),i=R(a,i);let{regexContext:g,charClassContext:l}=i;if(c<s.template.raw.length-1){let E=s.substitutions[c];a+=ze(E,r.flags,g,l,p,o),E instanceof RegExp?o+=U(E.source):E instanceof L&&(o+=U(String(E)))}}),a=_e(a,r);try{return r.subclass?new Q(a,r.flags,{useEmulationGroups:!0}):new RegExp(a,r.flags)}catch(u){let c=u.message.replace(/ \/.+\/[a-z]*:/,"");throw u.message=`${c}: /${a}/${r.flags}`,u}};function Ke(e="",t={}){let n=$e(t);if(n.subclass)throw new Error("Cannot use option subclass");return{expression:_e(Ie({raw:[e]},[],n).template.raw[0],n),flags:n.flags}}function $e(e){let t={flags:"",subclass:!1,plugins:[],unicodeSetsPlugin:me,disable:{},force:{},...e};if(/[nuvx]/.test(t.flags))throw new Error("Implicit flags v/u/x/n cannot be explicitly added");let n=t.force.v||(t.disable.v?!1:ie);return t.flags+=n?"v":"u",n&&(t.unicodeSetsPlugin=null),t}function Ie(e,t,n){let r=[];n.disable.x||r.push(we),n.disable.n||r.push(he);for(let s of r)({template:e,substitutions:t}=ce(e,t,s,n));return{template:e,substitutions:t}}function _e(e,t){let{flags:n,plugins:r,unicodeSetsPlugin:s,disable:o,subclass:a}=t;return[...r,...o.subroutines?[]:[Ce],...o.atomic?[]:[ge,de],...o.x?[]:[Ne],...s?[s]:[]].forEach(i=>e=i(e,{flags:n,useEmulationGroups:a})),e}function ze(e,t,n,r,s,o){if(e instanceof RegExp&&n!==f.DEFAULT)throw new Error("Cannot interpolate a RegExp at this position because the syntax context does not match");if(n===f.INVALID_INCOMPLETE_TOKEN||r===m.INVALID_INCOMPLETE_TOKEN)throw new Error("Interpolation preceded by invalid incomplete token");if(typeof e=="number"&&(n===f.ENCLOSED_U||r===m.ENCLOSED_U))return e.toString(16);let a=e instanceof L,i="";if(!(e instanceof RegExp)){e=String(e),a||(i=Y(e,n===f.CHAR_CLASS?d.CHAR_CLASS:d.DEFAULT));let u=le(i||e,n,r);if(u)throw new Error(`Unescaped stray "${u}" in the interpolated value would have side effects outside it`)}if(n===f.INTERVAL_QUANTIFIER||n===f.GROUP_NAME||q.has(n)||x.has(r))return a?String(e):i;if(n===f.CHAR_CLASS){if(a){if(j(String(e),"^-|^&&|-$|&&$"))throw new Error("Cannot use range or set operator at boundary of interpolated pattern; move the operation into the pattern or the operator outside of it");let u=fe(K(e));return X(e)?`[${u}]`:M(u)}return X(i)?`[${i}]`:i}if(e instanceof RegExp){let u=Ze(e,t),c=ue(u.value,o);return u.usedModifier?c:`(?:${c})`}return a?`(?:${e})`:s?`(?:${i})`:i}function Ze(e,t){let n={i:null,m:null,s:null},r="\\n\\r\\u2028\\u2029",s=e.source;if(e.ignoreCase!==t.includes("i"))if(G)n.i=e.ignoreCase;else throw new Error("Pattern modifiers not supported, so flag i on the outer and interpolated regex must match");if(e.dotAll!==t.includes("s")&&(G?n.s=e.dotAll:s=A(s,"\\.",e.dotAll?"[^]":`[^${r}]`,d.DEFAULT)),e.multiline!==t.includes("m")&&(G?n.m=e.multiline:(s=A(s,"\\^",e.multiline?`(?<=^|[${r}])`:"(?<![^])",d.DEFAULT),s=A(s,"\\$",e.multiline?`(?=$|[${r}])`:"(?![^])",d.DEFAULT))),G){let o=Object.keys(n),a=o.filter(u=>n[u]===!0).join(""),i=o.filter(u=>n[u]===!1).join("");if(i&&(a+=`-${i}`),a)return{value:`(?${a}:${s})`,usedModifier:!0}}return{value:s}}return Fe(Je);})(); | ||
`.replace(/\s+/g,""),"gsu");function Qe(e,t,n){if(!/\\g</.test(e))return e;let r=j(e,"\\\\(?:[1-9]|k<[^>]+>)",g.DEFAULT),s=r?`(${n?I:""}`:"(?:",a=new Map,i=[],o=[0],u=0,c=0,p=0,E=0,l=0,d=e,A;for(y.lastIndex=0;A=y.exec(d);){let{0:h,index:S,groups:{subroutineName:N,capturingStart:z,backrefNum:F,backrefName:v}}=A;if(h==="[")l++;else if(l)h==="]"&&l--;else if(N){if(!t.has(N))throw new Error(`Invalid named capture referenced by subroutine ${h}`);if(a.has(N))throw new Error(`Subroutine ${h} followed a recursive reference`);let w=t.get(N).contents,D=`${s}${w})`;r&&(p=0,c++),a.set(N,{unclosedGroupCount:qe(D)}),i.push(N),d=R(d,S,h,D),y.lastIndex-=h.length-s.length}else if(z)a.size?(r&&(p++,c++),h!=="("&&(d=R(d,S,h,s),y.lastIndex-=h.length-s.length)):r&&(o.push(re(o)+1+c-E),E=c,u++);else if((F||v)&&a.size){let w=F?+F:t.get(v)?.groupNum,D=!1;for(let $ of i){let _=t.get($);if(w>=_.groupNum&&w<=_.groupNum+_.numCaptures){D=!0;break}}if(D){let $=t.get(re(i)),_=u+c-p,O=`\\k<$$b${w}s${_}r${$.groupNum}c${$.numCaptures}>`;d=R(d,S,h,O),y.lastIndex+=O.length-h.length}}else if(h===")"&&a.size){let w=a.get(re(i));w.unclosedGroupCount--,w.unclosedGroupCount||a.delete(i.pop())}}return r&&(d=C(d,String.raw`\\(?:(?<bNum>[1-9]\d*)|k<\$\$b(?<bNumSub>\d+)s(?<subNum>\d+)r(?<refNum>\d+)c(?<refCaps>\d+)>)`,({0:h,groups:{bNum:S,bNumSub:N,subNum:z,refNum:F,refCaps:v}})=>{if(S){let O=+S;if(O>o.length-1)throw new Error(`Backref "${h}" greater than number of captures`);return`\\${o[O]}`}let w=+N,D=+z,$=+F,_=+v;return w<$||w>$+_?`\\${o[w]}`:`\\${D-$+w}`},g.DEFAULT)),d}var ne=new RegExp(String.raw`${B}|\(\?:\)|(?<invalid>\\?.)`,"gsu");function He(e,t){let n=V(e,String.raw`\(\?\(DEFINE\)`,0,g.DEFAULT);if(!n)return e;let r=Ne(e,n);if(r.afterPos<e.length)throw new Error("DEFINE group allowed only at the end of a regex");if(r.afterPos>e.length)throw new Error("DEFINE group is unclosed");let s;for(ne.lastIndex=0;s=ne.exec(r.contents);){let{captureName:a,invalid:i}=s.groups;if(a){let o=Ne(r.contents,s),u;if(!t.get(a).isUnique)u=a;else{let c=Le(o.contents,{includeContents:!1});for(let p of c.keys())if(!t.get(p).isUnique){u=p;break}}if(u)throw new Error(`Duplicate group name "${u}" within DEFINE`);ne.lastIndex=o.afterPos}else if(i)throw new Error("DEFINE group includes unsupported syntax at top level")}return e.slice(0,n.index)}function qe(e){let t=0;return P(e,"\\(",()=>t++,g.DEFAULT),t}function Be(e,t){let n=0,r=0,s;for(;s=V(e,W,r,g.DEFAULT);){let{0:a,index:i,groups:{captureName:o}}=s;if(n++,o===t)break;r=i+a.length}return n}function Ne(e,t){let n=t.index+t[0].length,r=J(e,n),s=n+r.length+1;return{contents:r,afterPos:s}}function Le(e,{includeContents:t}){let n=new Map;return P(e,B,({0:r,index:s,groups:{captureName:a}})=>{if(n.has(a))n.get(a).isUnique=!1;else{let i={isUnique:!0};if(t){let o=J(e,s+r.length);Object.assign(i,{contents:o,groupNum:Be(e,a),numCaptures:U(o)})}n.set(a,i)}},g.DEFAULT),n}function re(e){return e[e.length-1]}var We=(e,...t)=>{if(Array.isArray(e?.raw))return se({},e,...t);if((typeof e=="string"||e===void 0)&&!t.length)return se.bind(null,{flags:e??""});if({}.toString.call(e)==="[object Object]"&&!t.length)return se.bind(null,e);throw new Error(`Unexpected arguments: ${JSON.stringify([e,...t])}`)},se=(e,t,...n)=>{let r=$e(e),s=Ie(t,n,r),a=0,i="",o;s.template.raw.forEach((u,c)=>{let p=!!(s.template.raw[c]||s.template.raw[c+1]);a+=U(u),i+=M(u,g.CHAR_CLASS),o=x(i,o);let{regexContext:E,charClassContext:l}=o;if(c<s.template.raw.length-1){let d=s.substitutions[c];i+=ze(d,r.flags,E,l,p,a),d instanceof RegExp?a+=U(d.source):d instanceof L&&(a+=U(String(d)))}}),i=De(i,r);try{return r.subclass?new Q(i,r.flags,{useEmulationGroups:!0}):new RegExp(i,r.flags)}catch(u){let c=u.message.replace(/ \/.+\/[a-z]*:/,"");throw u.message=`${c}: /${i}/${r.flags}`,u}};function Ke(e="",t){let n=$e(t);if(n.subclass)throw new Error("Cannot use option subclass");return{expression:De(Ie({raw:[e]},[],n).template.raw[0],n),flags:n.flags}}function $e(e){let t={flags:"",subclass:!1,plugins:[],unicodeSetsPlugin:me,disable:{},force:{},...e};if(/[nuvx]/.test(t.flags))throw new Error("Implicit flags v/u/x/n cannot be explicitly added");let n=t.force.v||(t.disable.v?!1:ie);return t.flags+=n?"v":"u",n&&(t.unicodeSetsPlugin=null),t}function Ie(e,t,n){let r=[];n.disable.x||r.push(Ae),n.disable.n||r.push(he);for(let s of r)({template:e,substitutions:t}=ce(e,t,s,n));return{template:e,substitutions:t}}function De(e,t){let{flags:n,plugins:r,unicodeSetsPlugin:s,disable:a,subclass:i}=t;return[...r,...a.subroutines?[]:[Se],...a.atomic?[]:[Ee,ge],...a.x?[]:[we],...s?[s]:[]].forEach(o=>e=o(e,{flags:n,useEmulationGroups:i})),e}function ze(e,t,n,r,s,a){if(e instanceof RegExp&&n!==f.DEFAULT)throw new Error("Cannot interpolate a RegExp at this position because the syntax context does not match");if(n===f.INVALID_INCOMPLETE_TOKEN||r===m.INVALID_INCOMPLETE_TOKEN)throw new Error("Interpolation preceded by invalid incomplete token");if(typeof e=="number"&&(n===f.ENCLOSED_U||r===m.ENCLOSED_U))return e.toString(16);let i=e instanceof L,o="";if(!(e instanceof RegExp)){e=String(e),i||(o=Y(e,n===f.CHAR_CLASS?g.CHAR_CLASS:g.DEFAULT));let u=le(o||e,n,r);if(u)throw new Error(`Unescaped stray "${u}" in the interpolated value would have side effects outside it`)}if(n===f.INTERVAL_QUANTIFIER||n===f.GROUP_NAME||q.has(n)||k.has(r))return i?String(e):o;if(n===f.CHAR_CLASS){if(i){if(j(String(e),"^-|^&&|-$|&&$"))throw new Error("Cannot use range or set operator at boundary of interpolated pattern; move the operation into the pattern or the operator outside of it");let u=fe(K(e));return X(e)?`[${u}]`:M(u)}return X(o)?`[${o}]`:o}if(e instanceof RegExp){let u=Ze(e,t),c=ue(u.value,a);return u.usedModifier?c:`(?:${c})`}return i?`(?:${e})`:s?`(?:${o})`:o}function Ze(e,t){let n={i:null,m:null,s:null},r="\\n\\r\\u2028\\u2029",s=e.source;if(e.ignoreCase!==t.includes("i"))if(G)n.i=e.ignoreCase;else throw new Error("Pattern modifiers not supported, so flag i on the outer and interpolated regex must match");if(e.dotAll!==t.includes("s")&&(G?n.s=e.dotAll:s=C(s,"\\.",e.dotAll?"[^]":`[^${r}]`,g.DEFAULT)),e.multiline!==t.includes("m")&&(G?n.m=e.multiline:(s=C(s,"\\^",e.multiline?`(?<=^|[${r}])`:"(?<![^])",g.DEFAULT),s=C(s,"\\$",e.multiline?`(?=$|[${r}])`:"(?![^])",g.DEFAULT))),G){let a=Object.keys(n),i=a.filter(u=>n[u]===!0).join(""),o=a.filter(u=>n[u]===!1).join("");if(o&&(i+=`-${o}`),i)return{value:`(?${i}:${s})`,usedModifier:!0}}return{value:s}}return Re(Je);})(); | ||
//# sourceMappingURL=regex.min.js.map |
{ | ||
"name": "regex", | ||
"version": "5.0.0", | ||
"version": "5.0.1", | ||
"description": "Regex template tag with extended syntax, context-aware interpolation, and always-on best practices", | ||
@@ -5,0 +5,0 @@ "author": "Steven Levithan", |
<div align="center"> | ||
<a href="https://github.com/slevithan/regex#readme"> | ||
<picture> | ||
<source media="(prefers-color-scheme: dark)" srcset="https://cdn.jsdelivr.net/gh/slevithan/regex@4.1.0/media/regex-logo-dark.svg"> | ||
<img alt="regex logo" height="180" src="https://cdn.jsdelivr.net/gh/slevithan/regex@4.1.0/media/regex-logo.svg"> | ||
<source media="(prefers-color-scheme: dark)" srcset="https://cdn.jsdelivr.net/gh/slevithan/regex@5.0.1/media/regex-logo-dark.svg"> | ||
<img alt="regex logo" height="180" src="https://cdn.jsdelivr.net/gh/slevithan/regex@5.0.1/media/regex-logo.svg"> | ||
</picture> | ||
@@ -7,0 +7,0 @@ </a> |
@@ -13,3 +13,3 @@ import {emulationGroupMarker} from './subclass.js'; | ||
*/ | ||
export function atomic(expression, data) { | ||
function atomic(expression, data) { | ||
if (!/\(\?>/.test(expression)) { | ||
@@ -120,3 +120,3 @@ return expression; | ||
*/ | ||
export function possessive(expression) { | ||
function possessive(expression) { | ||
if (!(new RegExp(`${baseQuantifier}\\+`).test(expression))) { | ||
@@ -185,1 +185,6 @@ return expression; | ||
} | ||
export { | ||
atomic, | ||
possessive, | ||
}; |
@@ -20,3 +20,3 @@ import {doublePunctuatorChars} from './utils.js'; | ||
*/ | ||
export function backcompatPlugin(expression) { | ||
function backcompatPlugin(expression) { | ||
const unescapedLiteralHyphenMsg = 'Invalid unescaped "-" in character class'; | ||
@@ -57,1 +57,5 @@ let inCharClass = false; | ||
} | ||
export { | ||
backcompatPlugin, | ||
}; |
@@ -17,3 +17,3 @@ import {getEndContextForIncompleteExpression, noncapturingDelim, RegexContext} from './utils.js'; | ||
*/ | ||
export function flagNPreprocessor(value, runningContext) { | ||
function flagNPreprocessor(value, runningContext) { | ||
value = String(value); | ||
@@ -43,1 +43,5 @@ let expression = ''; | ||
} | ||
export { | ||
flagNPreprocessor, | ||
}; |
@@ -32,3 +32,3 @@ import {emulationGroupMarker} from './subclass.js'; | ||
*/ | ||
export function flagXPreprocessor(value, runningContext, options) { | ||
function flagXPreprocessor(value, runningContext, options) { | ||
value = String(value); | ||
@@ -43,4 +43,9 @@ let ignoringWs = false; | ||
let separatorNeeded = false; | ||
const update = (str, {prefix = true, postfix = false} = {}) => { | ||
str = (separatorNeeded && prefix ? '(?:)' : '') + str + (postfix ? '(?:)' : ''); | ||
const update = (str, options) => { | ||
const opts = { | ||
prefix: true, | ||
postfix: false, | ||
...options, | ||
}; | ||
str = (separatorNeeded && opts.prefix ? '(?:)' : '') + str + (opts.postfix ? '(?:)' : ''); | ||
separatorNeeded = false; | ||
@@ -158,3 +163,3 @@ return str; | ||
*/ | ||
export function clean(expression) { | ||
function clean(expression) { | ||
const sep = String.raw`\(\?:\)`; | ||
@@ -188,1 +193,6 @@ // No need for repeated separators | ||
} | ||
export { | ||
clean, | ||
flagXPreprocessor, | ||
}; |
@@ -1,2 +0,2 @@ | ||
export class Pattern { | ||
class Pattern { | ||
#value; | ||
@@ -30,3 +30,3 @@ /** @param {string} value */ | ||
*/ | ||
export function pattern(first, ...substitutions) { | ||
function pattern(first, ...substitutions) { | ||
if (Array.isArray(first?.raw)) { | ||
@@ -42,1 +42,6 @@ return new Pattern( | ||
} | ||
export { | ||
Pattern, | ||
pattern, | ||
}; |
@@ -8,3 +8,3 @@ import {atomic, possessive} from './atomic.js'; | ||
import {subroutines} from './subroutines.js'; | ||
import {adjustNumberedBackrefs, CharClassContext, containsCharClassUnion, countCaptures, enclosedTokenCharClassContexts, enclosedTokenRegexContexts, escapeV, flagVSupported, getBreakoutChar, getEndContextForIncompleteExpression, patternModsSupported, preprocess, RegexContext, sandboxLoneCharClassCaret, sandboxLoneDoublePunctuatorChar, sandboxUnsafeNulls} from './utils.js'; | ||
import {adjustNumberedBackrefs, CharClassContext, containsCharClassUnion, countCaptures, enclosedTokenCharClassContexts, enclosedTokenRegexContexts, envSupportsFlagGroups, envSupportsFlagV, escapeV, getBreakoutChar, getEndContextForIncompleteExpression, preprocess, RegexContext, sandboxLoneCharClassCaret, sandboxLoneDoublePunctuatorChar, sandboxUnsafeNulls} from './utils.js'; | ||
import {Context, hasUnescaped, replaceUnescaped} from 'regex-utilities'; | ||
@@ -129,3 +129,3 @@ | ||
*/ | ||
function rewrite(expression = '', options = {}) { | ||
function rewrite(expression = '', options) { | ||
const opts = getOptions(options); | ||
@@ -148,3 +148,3 @@ if (opts.subclass) { | ||
some options augmented for use. | ||
@param {RegexTagOptions} options | ||
@param {RegexTagOptions} [options] | ||
@returns {Required<RegexTagOptions>} | ||
@@ -165,3 +165,3 @@ */ | ||
} | ||
const useFlagV = opts.force.v || (opts.disable.v ? false : flagVSupported); | ||
const useFlagV = opts.force.v || (opts.disable.v ? false : envSupportsFlagV); | ||
opts.flags += useFlagV ? 'v' : 'u'; | ||
@@ -314,3 +314,3 @@ if (useFlagV) { | ||
if (re.ignoreCase !== outerFlags.includes('i')) { | ||
if (patternModsSupported) { | ||
if (envSupportsFlagGroups) { | ||
modFlagsObj.i = re.ignoreCase; | ||
@@ -322,3 +322,3 @@ } else { | ||
if (re.dotAll !== outerFlags.includes('s')) { | ||
if (patternModsSupported) { | ||
if (envSupportsFlagGroups) { | ||
modFlagsObj.s = re.dotAll; | ||
@@ -330,3 +330,3 @@ } else { | ||
if (re.multiline !== outerFlags.includes('m')) { | ||
if (patternModsSupported) { | ||
if (envSupportsFlagGroups) { | ||
modFlagsObj.m = re.multiline; | ||
@@ -338,3 +338,3 @@ } else { | ||
} | ||
if (patternModsSupported) { | ||
if (envSupportsFlagGroups) { | ||
const keys = Object.keys(modFlagsObj); | ||
@@ -341,0 +341,0 @@ let modifier = keys.filter(k => modFlagsObj[k] === true).join(''); |
@@ -9,11 +9,21 @@ import {Context, replaceUnescaped} from 'regex-utilities'; | ||
/** | ||
@class | ||
@param {string | RegExpSubclass} expression | ||
@param {string} [flags] | ||
@param {{useEmulationGroups: boolean;}} [options] | ||
Works the same as JavaScript's native `RegExp` constructor in all contexts, but automatically | ||
adjusts matches and subpattern indices (with flag `d`) to account for injected emulation groups. | ||
*/ | ||
class RegExpSubclass extends RegExp { | ||
// Avoid #private to allow for subclassing | ||
/** | ||
Avoid `#private` to allow for subclassing. | ||
@private | ||
@type {Array<boolean> | undefined} | ||
*/ | ||
_captureMap; | ||
/** | ||
@param {string | RegExpSubclass} expression | ||
@param {string} [flags] | ||
@param {{useEmulationGroups: boolean;}} [options] | ||
*/ | ||
constructor(expression, flags, options) { | ||
if (expression instanceof RegExp && options) { | ||
throw new Error('Cannot provide options when copying regexp'); | ||
} | ||
let captureMap; | ||
@@ -20,0 +30,0 @@ if (options?.useEmulationGroups) { |
@@ -10,3 +10,3 @@ import {emulationGroupMarker} from './subclass.js'; | ||
*/ | ||
export function subroutines(expression, data) { | ||
function subroutines(expression, data) { | ||
// NOTE: subroutines and definition groups fully support numbered backreferences and unnamed | ||
@@ -228,3 +228,3 @@ // captures (from interpolated regexes or from turning implicit flag n off), and all of the | ||
} else { | ||
const nestedNamedGroups = getNamedCapturingGroups(group.contents); | ||
const nestedNamedGroups = getNamedCapturingGroups(group.contents, {includeContents: false}); | ||
for (const name of nestedNamedGroups.keys()) { | ||
@@ -299,6 +299,6 @@ if (!namedGroups.get(name).isUnique) { | ||
@param {string} expression | ||
@param {{includeContents: boolean}} [options] | ||
@param {{includeContents: boolean}} options | ||
@returns {NamedCapturingGroupsMap} | ||
*/ | ||
function getNamedCapturingGroups(expression, {includeContents} = {}) { | ||
function getNamedCapturingGroups(expression, {includeContents}) { | ||
const namedGroups = new Map(); | ||
@@ -340,1 +340,5 @@ forEachUnescaped( | ||
} | ||
export { | ||
subroutines, | ||
}; |
import {Pattern, pattern} from './pattern.js'; | ||
import {Context, forEachUnescaped, replaceUnescaped} from 'regex-utilities'; | ||
export const RegexContext = { | ||
const RegexContext = { | ||
DEFAULT: 'DEFAULT', | ||
@@ -14,3 +14,3 @@ CHAR_CLASS: 'CHAR_CLASS', | ||
export const CharClassContext = { | ||
const CharClassContext = { | ||
DEFAULT: 'DEFAULT', | ||
@@ -24,3 +24,3 @@ ENCLOSED_P: 'ENCLOSED_P', | ||
export const enclosedTokenRegexContexts = new Set([ | ||
const enclosedTokenRegexContexts = new Set([ | ||
RegexContext.ENCLOSED_P, | ||
@@ -30,3 +30,3 @@ RegexContext.ENCLOSED_U, | ||
export const enclosedTokenCharClassContexts = new Set([ | ||
const enclosedTokenCharClassContexts = new Set([ | ||
CharClassContext.ENCLOSED_P, | ||
@@ -37,6 +37,6 @@ CharClassContext.ENCLOSED_Q, | ||
export const patternModsSupported = (() => { | ||
const envSupportsFlagGroups = (() => { | ||
try { | ||
new RegExp('(?i:)'); | ||
} catch (e) { | ||
} catch { | ||
return false; | ||
@@ -47,6 +47,6 @@ } | ||
export const flagVSupported = (() => { | ||
const envSupportsFlagV = (() => { | ||
try { | ||
new RegExp('', 'v'); | ||
} catch (e) { | ||
} catch { | ||
return false; | ||
@@ -57,6 +57,6 @@ } | ||
export const doublePunctuatorChars = '&!#$%*+,.:;<=>?@^`~'; | ||
export const namedCapturingDelim = String.raw`\(\?<(?![=!])(?<captureName>[^>]+)>`; | ||
export const capturingDelim = String.raw`\((?!\?)(?!(?<=\(\?\()DEFINE\))|${namedCapturingDelim}`; | ||
export const noncapturingDelim = String.raw`\(\?(?:[:=!>A-Za-z\-]|<[=!]|\(DEFINE\))`; | ||
const doublePunctuatorChars = '&!#$%*+,.:;<=>?@^`~'; | ||
const namedCapturingDelim = String.raw`\(\?<(?![=!])(?<captureName>[^>]+)>`; | ||
const capturingDelim = String.raw`\((?!\?)(?!(?<=\(\?\()DEFINE\))|${namedCapturingDelim}`; | ||
const noncapturingDelim = String.raw`\(\?(?:[:=!>A-Za-z\-]|<[=!]|\(DEFINE\))`; | ||
@@ -68,3 +68,3 @@ /** | ||
*/ | ||
export function adjustNumberedBackrefs(expression, precedingCaptures) { | ||
function adjustNumberedBackrefs(expression, precedingCaptures) { | ||
return replaceUnescaped( | ||
@@ -103,3 +103,3 @@ expression, | ||
// Assumes flag v and doesn't worry about syntax errors that are caught by it | ||
export function containsCharClassUnion(charClassPattern) { | ||
function containsCharClassUnion(charClassPattern) { | ||
// Return `true` if it contains: | ||
@@ -141,3 +141,3 @@ // - `\p` (lowercase only) and the name is a property of strings (case sensitive). | ||
*/ | ||
export function countCaptures(expression) { | ||
function countCaptures(expression) { | ||
let num = 0; | ||
@@ -154,3 +154,3 @@ forEachUnescaped(expression, capturingDelim, () => num++, Context.DEFAULT); | ||
*/ | ||
export function escapeV(str, context) { | ||
function escapeV(str, context) { | ||
if (context === Context.CHAR_CLASS) { | ||
@@ -165,3 +165,3 @@ // Escape all double punctuators (including ^, which is special on its own in the first | ||
// Look for characters that would change the meaning of subsequent tokens outside an interpolated value | ||
export function getBreakoutChar(expression, regexContext, charClassContext) { | ||
function getBreakoutChar(expression, regexContext, charClassContext) { | ||
const escapesRemoved = expression.replace(/\\./gsu, ''); | ||
@@ -226,8 +226,10 @@ // Trailing unescaped `\`; checking `.includes('\\')` would also work | ||
*/ | ||
export function getEndContextForIncompleteExpression(incompleteExpression, { | ||
regexContext = RegexContext.DEFAULT, | ||
charClassContext = CharClassContext.DEFAULT, | ||
charClassDepth = 0, | ||
lastPos = 0, | ||
} = {}) { | ||
function getEndContextForIncompleteExpression(incompleteExpression, runningContext) { | ||
let {regexContext, charClassContext, charClassDepth, lastPos} = { | ||
regexContext: RegexContext.DEFAULT, | ||
charClassContext: CharClassContext.DEFAULT, | ||
charClassDepth: 0, | ||
lastPos: 0, | ||
...runningContext, | ||
}; | ||
contextToken.lastIndex = lastPos; | ||
@@ -330,3 +332,3 @@ let match; | ||
*/ | ||
export function preprocess(template, substitutions, preprocessor, options) { | ||
function preprocess(template, substitutions, preprocessor, options) { | ||
let /** @type {RawTemplate} */ newTemplate = {raw: []}; | ||
@@ -358,3 +360,3 @@ let newSubstitutions = []; | ||
// if we happen to be at the first position. See `sandboxLoneDoublePunctuatorChar` for more details | ||
export function sandboxLoneCharClassCaret(str) { | ||
function sandboxLoneCharClassCaret(str) { | ||
return str.replace(/^\^/, '\\^^'); | ||
@@ -372,3 +374,3 @@ } | ||
// the second symbol wouldn't be sandboxed from the one following it. | ||
export function sandboxLoneDoublePunctuatorChar(str) { | ||
function sandboxLoneDoublePunctuatorChar(str) { | ||
return str.replace(new RegExp(`^([${doublePunctuatorChars}])(?!\\1)`), (m, _, pos) => { | ||
@@ -385,3 +387,3 @@ return `\\${m}${pos + 1 === str.length ? '' : m}`; | ||
*/ | ||
export function sandboxUnsafeNulls(str, context) { | ||
function sandboxUnsafeNulls(str, context) { | ||
// regex`[\0${0}]` and regex`[${pattern`\0`}0]` can't be guarded against via nested `[…]` | ||
@@ -400,4 +402,28 @@ // sandboxing in character classes if the interpolated value doesn't contain union (since it | ||
*/ | ||
export function spliceStr(str, pos, oldValue, newValue) { | ||
function spliceStr(str, pos, oldValue, newValue) { | ||
return str.slice(0, pos) + newValue + str.slice(pos + oldValue.length); | ||
} | ||
export { | ||
adjustNumberedBackrefs, | ||
capturingDelim, | ||
CharClassContext, | ||
containsCharClassUnion, | ||
countCaptures, | ||
doublePunctuatorChars, | ||
enclosedTokenCharClassContexts, | ||
enclosedTokenRegexContexts, | ||
envSupportsFlagGroups, | ||
envSupportsFlagV, | ||
escapeV, | ||
getBreakoutChar, | ||
getEndContextForIncompleteExpression, | ||
namedCapturingDelim, | ||
noncapturingDelim, | ||
preprocess, | ||
RegexContext, | ||
sandboxLoneCharClassCaret, | ||
sandboxLoneDoublePunctuatorChar, | ||
sandboxUnsafeNulls, | ||
spliceStr, | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
534647
4910
0