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-5/

File Pattern Matcher

Build a utility that matches file paths against pattern rules using flexible glob-style patterns.

Requirements

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:

  • Multi-level directory traversal wildcards
  • Multiple file extension alternatives
  • Standard filename wildcards

Process rules in order, with later rules overriding earlier ones for the same file.

Input Format

Your implementation should export a function that accepts:

  1. An array of file path strings
  2. An array of rule objects, each with:
    • pattern: a glob-style pattern string
    • action: either "include" or "exclude"

Output Format

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")

Example

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.

Test Cases

  • 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

Implementation

@generates

API

/**
 * 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 };

Dependencies { .dependencies }

glob-to-regexp { .dependency }

Provides pattern matching capabilities for converting glob patterns to regular expressions.

@satisfied-by

Version

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