or run

npx @tessl/cli init
Log in

Version

Files

tile.json

task.mdevals/scenario-5/

Path Matcher with Prefix Normalization

Build a file path matching utility that handles different path prefixes consistently. The utility should match file paths against glob patterns while automatically normalizing various path prefixes.

Requirements

Your implementation should:

  1. Create a matcher that accepts file paths with different prefixes (e.g., ./ or ~/) and matches them against glob patterns
  2. Strip these prefixes from paths before matching to ensure consistent pattern matching
  3. Support standard glob patterns like *.js, src/**/*.ts, etc.

Expected Behavior

When matching paths:

  • Paths starting with ./ should have the prefix removed before matching (e.g., ./index.js becomes index.js)
  • Paths starting with ~/ should have the prefix removed before matching (e.g., ~/src/file.js becomes src/file.js)
  • Paths without these prefixes are matched as-is
  • The glob patterns should work on the normalized paths

Implementation

Create a module that exports a function createPathMatcher(pattern) which returns a matcher function. The matcher function should accept a file path and return true if it matches the pattern, false otherwise.

@generates

API

/**
 * Creates a path matcher that normalizes path prefixes before matching
 * @param {string} pattern - The glob pattern to match against
 * @returns {Function} A matcher function that takes a path and returns boolean
 */
function createPathMatcher(pattern) {
  // IMPLEMENTATION HERE
}

module.exports = { createPathMatcher };

Test Cases

  • Matching *.js pattern matches ./index.js and ~/index.js as index.js @test
  • Matching src/**/*.ts pattern matches ./src/lib/util.ts and ~/src/lib/util.ts after normalization @test
  • Paths without prefixes like index.js are matched as-is @test

Dependencies { .dependencies }

picomatch { .dependency }

Provides glob pattern matching support.