/** * URL Pattern Matching Utility (D-007) * * Centralized URL and domain pattern matching with support for: * - Regex patterns (full RegExp syntax) * - Glob patterns (* and ? wildcards) * - Simple substring matching (fallback) * - Pattern generalization (ID replacement) * - Variable extraction from URLs */ /** * Pattern match result with extracted values */ export interface PatternMatchResult { /** Whether the pattern matched */ matched: boolean; /** Extracted capture groups (if regex with groups) */ captures?: string[]; /** Named capture groups (if regex with named groups) */ namedCaptures?: Record; /** The pattern that matched */ pattern: string; /** Match type used */ matchType: 'regex' | 'glob' | 'substring'; } /** * URL variable extractor configuration */ export interface UrlVariableExtractor { /** Variable name */ name: string; /** Source to extract from */ source: 'path' | 'query' | 'subdomain' | 'hostname' | 'hash'; /** Regex pattern with capture group */ pattern: string; /** Capture group index (1-based, default: 1) */ group?: number; /** Optional transformation */ transform?: 'lowercase' | 'uppercase' | 'urlencode' | 'urldecode'; } /** * Pattern matching options */ export interface PatternMatchOptions { /** Case-insensitive matching (default: true) */ caseInsensitive?: boolean; /** Treat pattern as glob (convert * and ?) (default: auto-detect) */ glob?: boolean; /** Allow substring matching as fallback (default: true) */ allowSubstring?: boolean; /** Anchor pattern to full string (default: true for glob) */ anchor?: boolean; } /** * Compiled pattern for efficient reuse */ export interface CompiledPattern { /** Original pattern string */ original: string; /** Compiled RegExp */ regex: RegExp; /** Pattern type */ type: 'regex' | 'glob' | 'substring'; } /** * Compile a pattern for matching */ export declare function compilePattern(pattern: string, options?: PatternMatchOptions): CompiledPattern; /** * Clear the pattern cache */ export declare function clearPatternCache(): void; /** * Match a string against a pattern */ export declare function matchPattern(input: string, pattern: string, options?: PatternMatchOptions): PatternMatchResult; /** * Test if a string matches a pattern (boolean result) */ export declare function testPattern(input: string, pattern: string, options?: PatternMatchOptions): boolean; /** * Match a URL against a pattern */ export declare function matchUrl(url: string, pattern: string, options?: PatternMatchOptions): PatternMatchResult; /** * Match a domain against a pattern (with glob support) */ export declare function matchDomain(domain: string, pattern: string, options?: PatternMatchOptions): boolean; /** * Match against multiple patterns (returns first match) */ export declare function matchAnyPattern(input: string, patterns: string[], options?: PatternMatchOptions): PatternMatchResult | null; /** * Match against all patterns (returns all matches) */ export declare function matchAllPatterns(input: string, patterns: string[], options?: PatternMatchOptions): PatternMatchResult[]; /** * Extract a variable from a URL using an extractor config */ export declare function extractUrlVariable(url: string, extractor: UrlVariableExtractor): string | null; /** * Extract multiple variables from a URL */ export declare function extractUrlVariables(url: string, extractors: UrlVariableExtractor[]): Record; /** * Generalize a URL by replacing specific IDs with patterns */ export declare function generalizeUrl(url: string): string; /** * Create a regex pattern from a URL with variable segments */ export declare function createUrlPattern(url: string, variableSegments?: Record): string; /** * Check if a URL should be skipped based on skip patterns * * Supports both glob patterns (* wildcards) and regex patterns. */ export declare function shouldSkipUrl(url: string, skipPatterns: string[]): boolean; /** * Filter URLs that don't match any skip patterns */ export declare function filterUrls(urls: string[], skipPatterns: string[]): string[]; /** * Extract the root domain from a URL or hostname */ export declare function getRootDomain(urlOrHostname: string): string; /** * Check if a domain matches a list of domain patterns */ export declare function isDomainInList(domain: string, domainPatterns: string[]): boolean; /** * Validate that a string is a valid regex pattern */ export declare function isValidRegexPattern(pattern: string): boolean; /** * Escape a string for use in a regex pattern */ export declare function escapeRegexPattern(str: string): string; /** * Create an anchored literal pattern from a string */ export declare function createLiteralPattern(str: string): string; //# sourceMappingURL=url-pattern-matcher.d.ts.map