or run

tessl search
Log in

Version

Files

tile.json

task.mdevals/scenario-6/

File Filter System

Build a file filtering system that processes lists of file paths using glob patterns with support for multiple patterns, including both inclusion and exclusion rules.

Requirements

Your system should implement a function that filters arrays of file paths based on multiple glob patterns. The function should:

  1. Accept an array of file paths as strings
  2. Accept multiple glob patterns (both positive and negative)
  3. Return only the paths that match the inclusion patterns and don't match the exclusion patterns
  4. Handle patterns in the correct order (later patterns can override earlier ones)
  5. Support standard glob wildcards like * and **

Test Cases

  • Given paths ['src/app.js', 'src/test.js', 'dist/app.js', 'README.md'] and patterns ['**/*.js'], returns all JavaScript files @test
  • Given paths ['src/app.js', 'src/test.js', 'src/utils.js'] and patterns ['**/*.js', '!**/*test.js'], returns only non-test JavaScript files @test
  • Given paths ['a.js', 'b.css', 'c.html', 'd.js'] and patterns ['*.js', '*.css'], returns files matching either pattern @test
  • Given paths ['src/foo.js', 'test/foo.js', 'src/bar.js'] and patterns ['src/**/*.js'], returns only source JavaScript files @test

Implementation

@generates

API

/**
 * Filters an array of file paths using multiple glob patterns.
 * Patterns starting with '!' are treated as exclusion patterns.
 *
 * @param {string[]} paths - Array of file paths to filter
 * @param {string[]} patterns - Array of glob patterns (supports negation with '!')
 * @returns {string[]} Array of paths that match the patterns
 */
function filterPaths(paths, patterns) {
  // Implementation here
}

module.exports = { filterPaths };

Dependencies { .dependencies }

micromatch { .dependency }

Provides glob pattern matching capabilities for filtering file paths.