or run

npx @tessl/cli init
Log in

Version

Files

tile.json

task.mdevals/scenario-8/

Pattern Validator

Build a pattern validation utility that converts glob patterns into regular expressions and validates file paths against them.

Requirements

Create a module that provides functionality to:

  1. Convert glob patterns to regular expressions
  2. Validate whether file paths match the compiled patterns
  3. Support case-insensitive pattern matching
  4. Handle multiple patterns efficiently

The module should expose a function that takes a glob pattern (or array of patterns) and returns a validator object with a test method that checks if a given path matches the pattern.

Expected Behavior

Basic Pattern Conversion

  • Convert simple wildcard patterns to regex @test
// Example: Pattern "*.js" should match "file.js" but not "file.ts"
const validator = createValidator('*.js');
validator.test('file.js') === true;
validator.test('file.ts') === false;

Globstar Pattern Support

  • Handle recursive directory patterns with globstar @test
// Example: Pattern "**/*.js" should match files in any nested directory
const validator = createValidator('**/*.js');
validator.test('src/utils/helper.js') === true;
validator.test('lib/index.js') === true;
validator.test('readme.md') === false;

Case-Insensitive Matching

  • Support case-insensitive pattern matching when configured @test
// Example: With nocase option, "*.JS" should match "file.js"
const validator = createValidator('*.JS', { nocase: true });
validator.test('file.js') === true;
validator.test('file.JS') === true;

Implementation

@generates

API

/**
 * Creates a validator from one or more glob patterns
 * @param {string|string[]} patterns - Glob pattern(s) to compile
 * @param {object} options - Configuration options (e.g., { nocase: true })
 * @returns {object} Validator object with test method
 */
function createValidator(patterns, options) {
  // Returns { test: (path) => boolean }
}

module.exports = { createValidator };

Dependencies { .dependencies }

picomatch { .dependency }

Provides glob pattern compilation and matching support.

@satisfied-by