CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-glob-to-regexp

Convert globs to regular expressions

Overall
score

100%

Overview
Eval results
Files

task.mdevals/scenario-6/

File Name Validator

A utility for validating file names against specific patterns using simple wildcard matching.

Capabilities

Validates file names with single character wildcards

  • Given the pattern "log-?.txt", the filename "log-a.txt" is valid @test
  • Given the pattern "log-?.txt", the filename "log-1.txt" is valid @test
  • Given the pattern "log-?.txt", the filename "log-ab.txt" is invalid @test
  • Given the pattern "log-?.txt", the filename "log-.txt" is invalid @test

Validates file names with multiple single character wildcards

  • Given the pattern "data-??-??.csv", the filename "data-01-23.csv" is valid @test
  • Given the pattern "data-??-??.csv", the filename "data-ab-cd.csv" is valid @test
  • Given the pattern "data-??-??.csv", the filename "data-1-23.csv" is invalid @test

Validates file names with wildcards in different positions

  • Given the pattern "?.log", the filename "a.log" is valid @test
  • Given the pattern "test?.txt", the filename "test5.txt" is valid @test
  • Given the pattern "file-?-?.dat", the filename "file-x-y.dat" is valid @test

Implementation

@generates

API

/**
 * Validates a filename against a pattern with single-character wildcards.
 * The pattern uses '?' to match exactly one character.
 *
 * @param {string} filename - The filename to validate.
 * @param {string} pattern - The pattern to match against, using '?' for single-character wildcards.
 * @returns {boolean} True if the filename matches the pattern, false otherwise.
 */
function validateFilename(filename, pattern) {
  // IMPLEMENTATION HERE
}

module.exports = { validateFilename };

Dependencies { .dependencies }

glob-to-regexp { .dependency }

Converts glob patterns to regular expressions for pattern matching.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-glob-to-regexp

tile.json