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

File Type Validator

Build a file type validation utility that checks if file names match specific allowed extensions or naming patterns.

Requirements

Create a function called isValidFile that takes a file name (string) and a pattern (string) and returns true if the file name matches the pattern, false otherwise.

The pattern should support:

  • Multiple alternative extensions using comma-separated values in curly braces
  • Wildcards for matching any characters
  • Literal dots and other special characters

The function should be case-sensitive by default.

Examples

  • Pattern *.{js,ts} should match index.js and app.ts but not style.css
  • Pattern test-*.{spec,test}.js should match test-user.spec.js and test-auth.test.js but not main.test.js
  • Pattern {readme,license}.{md,txt} should match readme.md, license.txt, and readme.txt but not changelog.md

Test Cases

  • isValidFile("component.jsx", "*.{js,jsx}") returns true @test
  • isValidFile("style.css", "*.{js,jsx}") returns false @test
  • isValidFile("config.json", "config.{json,yaml,yml}") returns true @test
  • isValidFile("test-utils.js", "{test,spec}-*.js") returns true @test
  • isValidFile("utils-test.js", "{test,spec}-*.js") returns false @test

Implementation

@generates

API

/**
 * Validates if a file name matches a given pattern with alternative extensions.
 *
 * @param {string} fileName - The file name to validate.
 * @param {string} pattern - The pattern with alternatives (e.g., "*.{js,ts}").
 * @returns {boolean} True if the file name matches the pattern, false otherwise.
 */
function isValidFile(fileName, pattern) {
  // IMPLEMENTATION HERE
}

module.exports = { isValidFile };

Dependencies { .dependencies }

glob-to-regexp { .dependency }

Provides pattern matching with support for alternative extensions using curly brace syntax.

@satisfied-by

Version

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