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-9/

File Path Matcher

Build a simple file path matching utility that filters lists of file paths based on wildcard patterns.

Requirements

Create a module that exports a function matchPaths which takes an array of file path strings and a pattern string, then returns an array of paths that match the pattern.

The pattern matching should support:

  • The * wildcard which matches zero or more characters
  • Exact string matching for non-wildcard characters
  • Patterns should match the entire path (not just substrings)

Behavior

The function should:

  • Accept an array of strings as the first parameter (file paths)
  • Accept a pattern string as the second parameter
  • Return a new array containing only the paths that match the pattern
  • Preserve the original order of matching paths
  • Return an empty array if no paths match

Examples

matchPaths(['app.js', 'test.js', 'README.md'], '*.js')
// Returns: ['app.js', 'test.js']

matchPaths(['src/index.js', 'src/utils.js', 'lib/helper.js'], 'src/*.js')
// Returns: ['src/index.js', 'src/utils.js']

matchPaths(['file.txt', 'file.txt.bak', 'data.txt'], '*.txt')
// Returns: ['file.txt', 'data.txt']

matchPaths(['config.json', 'package.json'], 'test-*')
// Returns: []

Implementation

@generates

API

/**
 * Filters an array of file paths based on a wildcard pattern
 * @param {string[]} paths - Array of file path strings to filter
 * @param {string} pattern - Pattern string with * wildcard support
 * @returns {string[]} Array of paths that match the pattern
 */
function matchPaths(paths, pattern) {
  // Implementation here
}

module.exports = { matchPaths };

Test Cases

  • It matches files with a specific extension @test
const result = matchPaths(['app.js', 'test.js', 'README.md'], '*.js');
// Expected: ['app.js', 'test.js']
  • It matches files in a specific directory @test
const result = matchPaths(['src/index.js', 'lib/helper.js', 'src/utils.js'], 'src/*.js');
// Expected: ['src/index.js', 'src/utils.js']
  • It returns empty array when no matches found @test
const result = matchPaths(['config.json', 'package.json'], 'test-*');
// Expected: []
  • It matches with wildcard at the start @test
const result = matchPaths(['test-one.js', 'test-two.js', 'main.js'], 'test-*');
// Expected: ['test-one.js', 'test-two.js']

Dependencies { .dependencies }

glob-to-regexp { .dependency }

Converts glob patterns to regular expressions for pattern matching.

Version

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