or run

tessl search
Log in

Version

Files

tile.json

task.mdevals/scenario-9/

Pattern Analyzer

Build a utility that analyzes glob patterns and provides insights about their structure and characteristics.

Requirements

Implement a function analyzePattern that takes a glob pattern string and returns an object containing information about the pattern's structure. The function should:

  1. Identify whether the pattern contains globstar (**) segments
  2. Determine if the pattern is negated (starts with !)
  3. Extract the individual path segments from the pattern
  4. Return all this information in a structured object

The returned object should have the following properties:

  • hasGlobstar (boolean): true if the pattern contains **
  • isNegated (boolean): true if the pattern starts with !
  • segments (array): array of path segments from the pattern

Additionally, implement a function batchAnalyze that takes an array of glob patterns and returns an array of analysis objects for each pattern.

Test Cases

  • Given pattern "src/**/*.js", the analyzer returns an object with hasGlobstar: true, isNegated: false, and segments including the pattern parts @test
  • Given pattern "!node_modules/**", the analyzer returns an object with hasGlobstar: true, isNegated: true, and appropriate segments @test
  • Given pattern "lib/utils/*.js", the analyzer returns an object with hasGlobstar: false, isNegated: false, and the correct segments @test
  • Given an array of multiple patterns, the batch analyzer returns an array of analysis objects for each pattern @test

Implementation

@generates

API

/**
 * Analyzes a glob pattern and returns structural information
 * @param {string} pattern - The glob pattern to analyze
 * @returns {object} Analysis object with hasGlobstar, isNegated, and segments properties
 */
function analyzePattern(pattern) {
  // Implementation here
}

/**
 * Analyzes multiple glob patterns
 * @param {string[]} patterns - Array of glob patterns to analyze
 * @returns {object[]} Array of analysis objects
 */
function batchAnalyze(patterns) {
  // Implementation here
}

module.exports = {
  analyzePattern,
  batchAnalyze
};

Dependencies { .dependencies }

micromatch { .dependency }

Provides glob pattern scanning and analysis capabilities.