CtrlK
CommunityDocumentationLog inGet started
Tessl Logo

tessl/npm-glob-to-regexp

tessl install tessl/npm-glob-to-regexp@0.4.0

Convert globs to regular expressions

Agent Success

Agent success rate when using this tile

100%

Improvement

Agent success rate improvement when using this tile compared to baseline

1.15x

Baseline

Agent success rate without this tile

87%

task.mdevals/scenario-6/

File Filter System

Build a file filtering system that can match file paths against user-provided patterns with flexible matching options.

Requirements

The system should provide a function createFilter(pattern, options) that:

  1. Accepts a glob-style pattern string (e.g., ".js", "test-.txt")
  2. Accepts an options object with the following properties:
    • caseSensitive (boolean, default: true): Whether matching should be case-sensitive
    • matchAnywhere (boolean, default: false): Whether to match the pattern anywhere in the string (not just exact matches)
  3. Returns a filter function that takes a string and returns true if it matches the pattern, false otherwise

The filter function should use the appropriate flags when converting the glob pattern to a regular expression:

  • When caseSensitive is false, matching should be case-insensitive
  • When matchAnywhere is true, the pattern should match anywhere in the input string
  • Both options can be combined

Test Cases

  • Given pattern "*.JS" with case-insensitive matching, it matches "file.js" @test
  • Given pattern "*.txt" with case-sensitive matching (default), it does not match "file.TXT" @test
  • Given pattern "test" with matchAnywhere enabled, it matches "my-test-file.js" @test
  • Given pattern "*.js" with both case-insensitive and matchAnywhere enabled, it matches "index.JS.backup" @test

Implementation

@generates

API

/**
 * Creates a filter function based on a glob pattern and options
 * @param {string} pattern - Glob pattern to match against
 * @param {Object} options - Matching options
 * @param {boolean} [options.caseSensitive=true] - Whether matching should be case-sensitive
 * @param {boolean} [options.matchAnywhere=false] - Whether to match pattern anywhere in the string
 * @returns {Function} Filter function that takes a string and returns boolean
 */
function createFilter(pattern, options) {
  // Implementation here
}

module.exports = { createFilter };

Dependencies { .dependencies }

glob-to-regexp { .dependency }

Provides glob pattern to regular expression conversion.

@satisfied-by

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/glob-to-regexp@0.4.x
tile.json