or run

tessl search
Log in

Version

Files

tile.json

task.mdevals/scenario-5/

Cross-Platform File Filter

Build a file filtering utility that works consistently across Windows and Unix-like systems by normalizing path separators before matching.

Capabilities

Path normalization and filtering

Your utility should normalize paths to use forward slashes before matching them against glob patterns, ensuring consistent behavior regardless of the platform where paths originated.

  • Given an array ["src\\components\\App.js", "src/utils/helper.js", "tests\\unit\\app.test.js"] and pattern "src/**/*.js", returns the two files under src (normalized paths) @test
  • Given an array ["docs\\README.md", "src/index.ts"] and pattern "**/*.md", returns only the markdown file with normalized path @test
  • Given an array ["C:\\projects\\app.js", "home/user/script.js"] and pattern "**/*.js", returns both files with normalized forward slashes @test

Basename-only matching

Support matching files by basename only, ignoring their directory structure.

  • Given an array ["src/components/Button.tsx", "tests/Button.tsx", "docs/Button.md"] and pattern "Button.tsx" with basename matching, returns both .tsx files @test
  • Given an array ["a/b/c/test.js", "x/y/test.js", "test.js"] and pattern "test.js" with basename matching, returns all three files @test

Implementation

@generates

API

/**
 * Filters an array of file paths against a glob pattern with cross-platform path normalization.
 *
 * @param {string[]} paths - Array of file paths (may use backslashes or forward slashes)
 * @param {string} pattern - Glob pattern to match against
 * @param {Object} [options] - Optional configuration
 * @param {boolean} [options.basename] - If true, match against basename only
 * @returns {string[]} - Filtered array of paths with normalized separators (forward slashes)
 */
function filterPaths(paths, pattern, options = {}) {
  // IMPLEMENTATION HERE
}

module.exports = { filterPaths };

Dependencies { .dependencies }

micromatch { .dependency }

Provides glob pattern matching with cross-platform path normalization support.