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

URL Path Validator

A utility that validates and filters URL paths based on configurable pattern matching rules.

@generates

Overview

Build a URL path validator that can check if URL paths match specific patterns. The validator needs to support two different matching modes: exact path matching and substring matching.

Requirements

Pattern Matching Modes

The validator must support two distinct matching behaviors:

  1. Exact Path Matching: The pattern must match the entire path string from beginning to end
  2. Substring Matching: The pattern can match any portion of the path string

Core Functionality

Implement a validator that can:

  • Validate URL paths against wildcard patterns
  • Support both exact matching and substring matching modes
  • Handle common path patterns like file extensions and path segments

Implementation Tasks

Task 1: Exact Path Validator

Create a function createExactMatcher(pattern) that:

  • Accepts a wildcard pattern string
  • Returns a validation function that checks if a path exactly matches the pattern
  • The pattern must match the complete path from start to finish

Examples:

  • Pattern "*.json" should match "config.json" but not "config.json.bak" or "data/config.json"

  • Pattern "api/*" should match "api/users" but not "v1/api/users" or "api/users/123"

  • It validates exact path matches using wildcards @test

Task 2: Substring Path Validator

Create a function createSubstringMatcher(pattern) that:

  • Accepts a wildcard pattern string
  • Returns a validation function that checks if a path contains the pattern anywhere
  • The pattern can match any portion of the path

Examples:

  • Pattern "*.json" should match "config.json", "config.json.bak", and "data/config.json"

  • Pattern "api" should match "api/users", "v1/api/users", and "legacy-api"

  • It validates substring matches using wildcards @test

Task 3: URL Path Filter

Create a function filterPaths(paths, pattern, mode) that:

  • Accepts an array of URL paths

  • Accepts a wildcard pattern

  • Accepts a mode parameter: "exact" or "substring"

  • Returns an array containing only paths that match according to the specified mode

  • It filters paths based on exact matching mode @test

  • It filters paths based on substring matching mode @test

API

/**
 * Creates a matcher function for exact path matching
 * @param {string} pattern - Wildcard pattern to match
 * @returns {function(string): boolean} Matcher function
 */
function createExactMatcher(pattern) {
  // Implementation
}

/**
 * Creates a matcher function for substring matching
 * @param {string} pattern - Wildcard pattern to match
 * @returns {function(string): boolean} Matcher function
 */
function createSubstringMatcher(pattern) {
  // Implementation
}

/**
 * Filters paths based on pattern and matching mode
 * @param {string[]} paths - Array of URL paths
 * @param {string} pattern - Wildcard pattern to match
 * @param {string} mode - Matching mode: "exact" or "substring"
 * @returns {string[]} Filtered array of matching paths
 */
function filterPaths(paths, pattern, mode) {
  // Implementation
}

module.exports = {
  createExactMatcher,
  createSubstringMatcher,
  filterPaths
};

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