CtrlK
CommunityDocumentationLog inGet started
Tessl Logo

tessl/npm-glob-to-regexp

tessl install tessl/npm-glob-to-regexp@0.4.0

Convert globs to regular expressions

Agent Success

Agent success rate when using this tile

100%

Improvement

Agent success rate improvement when using this tile compared to baseline

1.15x

Baseline

Agent success rate without this tile

87%

task.mdevals/scenario-4/

File Path Pattern Matcher

Build a utility that converts file path patterns with special characters into regular expressions that can be used for matching.

Users need to filter file paths in a large codebase based on patterns that contain various special characters (dots, dollar signs, parentheses, etc.). These characters should be matched literally, not interpreted as regex metacharacters.

Requirements

Implement a module that converts file path patterns into regular expressions with the following behavior:

  • Convert simple patterns with wildcards (*) into regular expressions
  • Handle patterns containing special characters that should match literally (e.g., dots in file extensions, dollar signs in variable names, parentheses in directory names)
  • By default, patterns should match the entire path from start to end
  • The resulting regular expression should be usable for testing against actual file paths

Test Cases

  • Pattern "*.min.js" matches path "app.min.js" exactly @test
  • Pattern "src/$.js" matches path "src/$.js" exactly @test
  • Pattern "lib/util(v2).js" matches path "lib/util(v2).js" exactly @test
  • Pattern "data/*.csv" matches path "data/report.csv" exactly @test

Implementation

@generates

API

/**
 * Converts a file path pattern to a regular expression
 * @param {string} pattern - The file path pattern to convert
 * @returns {RegExp} A regular expression that matches the pattern
 */
function patternToRegex(pattern) {
  // Implementation here
}

module.exports = { patternToRegex };

Dependencies { .dependencies }

glob-to-regexp { .dependency }

Converts glob patterns to regular expressions with proper escaping of special characters.

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/glob-to-regexp@0.4.x
tile.json