tessl install tessl/npm-glob-to-regexp@0.4.0Convert 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%
Build a utility that matches file paths against pattern rules using flexible glob-style patterns.
Your utility should accept a list of file paths and a set of pattern rules, then determine which files match which rules. Each rule consists of a pattern and an action (either "include" or "exclude").
The pattern matching should support:
Process rules in order, with later rules overriding earlier ones for the same file.
Your implementation should export a function that accepts:
pattern: a glob-style pattern stringaction: either "include" or "exclude"Return an object with two arrays:
included: file paths that should be included (final action is "include")excluded: file paths that should be excluded (final action is "exclude")Given these file paths:
[
"src/index.js",
"src/utils/helper.js",
"src/components/Button.tsx",
"src/components/Input.tsx",
"test/unit/helper.test.js",
"test/integration/api.test.js",
"docs/README.md"
]And these rules:
[
{ pattern: "src/**/*.{js,tsx}", action: "include" },
{ pattern: "test/**/*.js", action: "include" },
{ pattern: "**/helper.*", action: "exclude" }
]Should return:
{
included: [
"src/index.js",
"src/components/Button.tsx",
"src/components/Input.tsx",
"test/integration/api.test.js"
],
excluded: [
"src/utils/helper.js",
"test/unit/helper.test.js"
]
}Note: The helper files are excluded by the last rule even though they matched earlier include rules. Files not matching any rule (like "docs/README.md") are neither included nor excluded.
Given paths ["a/b.js", "a/c/d.js"] and rule {pattern: "a/*.js", action: "include"}, only "a/b.js" is included because the pattern should match single directory level only @test
Given paths ["x/file.ts", "x/y/file.tsx"] and rule {pattern: "x/**/*.{ts,tsx}", action: "include"}, both paths are included because the pattern should match multiple levels and either extension @test
Given path "src/test.js" with rules [{pattern: "**/.js", action: "include"}, {pattern: "src/", action: "exclude"}], the file is excluded because later rules override earlier ones @test
@generates
/**
* Filters file paths based on glob pattern rules.
*
* @param {string[]} filePaths - Array of file path strings to filter
* @param {Array<{pattern: string, action: 'include'|'exclude'}>} rules - Pattern rules to apply
* @returns {{included: string[], excluded: string[]}} Object with included and excluded file paths
*/
function matchFiles(filePaths, rules) {
// Implementation here
}
module.exports = { matchFiles };Provides pattern matching capabilities for converting glob patterns to regular expressions.
@satisfied-by