or run

tessl search
Log in

Version

Files

tile.json

task.mdevals/scenario-8/

Path Filter Utility

A utility that filters file paths based on whether they contain specific patterns anywhere in the path, supporting both literal substring matching and glob patterns.

Capabilities

Filter paths by substring patterns

  • Given paths ["src/components/Header.js", "lib/utils/helpers.js", "test/Header.test.js"] and pattern "Header", returns ["src/components/Header.js", "test/Header.test.js"] @test
  • Given paths ["config/prod.env", "config/dev.env", "src/index.js"] and pattern ".env", returns ["config/prod.env", "config/dev.env"] @test
  • Given paths ["docs/api/users.md", "src/api/auth.js", "test/users.test.js"] and pattern "api", returns ["docs/api/users.md", "src/api/auth.js"] @test

Filter paths with glob patterns

  • Given paths ["src/pages/home.tsx", "src/components/Button.tsx", "lib/utils.js"] and pattern "*.tsx", returns ["src/pages/home.tsx", "src/components/Button.tsx"] @test
  • Given paths ["app/models/user.rb", "app/views/index.html", "app/controllers/api.rb"] and pattern "app/**", returns all three paths @test

Handle empty results

  • Given paths ["src/index.js", "lib/helper.js"] and pattern "test", returns empty array [] @test

Implementation

@generates

API

/**
 * Filters an array of file paths, returning only those that contain
 * the specified pattern anywhere in the path.
 *
 * Supports both literal substring matching and glob patterns.
 *
 * @param {string[]} paths - Array of file paths to filter
 * @param {string} pattern - Pattern to search for (literal or glob)
 * @returns {string[]} Array of paths containing the pattern
 */
function filterPaths(paths, pattern) {
  // IMPLEMENTATION HERE
}

module.exports = { filterPaths };

Dependencies { .dependencies }

micromatch { .dependency }

Provides glob pattern matching and substring detection capabilities.