or run

npx @tessl/cli init
Log in

Version

Files

tile.json

task.mdevals/scenario-7/

Pattern Validator

Build a pattern validation utility that converts regex source strings into regular expressions and validates input against those patterns.

Requirements

Your task is to implement a pattern validator module that:

  1. Accepts a regex source string and converts it to a working regular expression
  2. Supports case-insensitive matching through configuration
  3. Validates input strings against the compiled regular expression
  4. Returns validation results with match information

Functionality

The module should provide a function that:

  • Takes a regex source pattern string (e.g., "^test.*", "[0-9]+")
  • Takes optional configuration to enable case-insensitive matching
  • Returns a validator object with a test method
  • The test method should accept an input string and return whether it matches

Examples

// Case-sensitive matching
const validator1 = createValidator("^hello");
validator1.test("hello world"); // should return true
validator1.test("Hello world"); // should return false

// Case-insensitive matching
const validator2 = createValidator("^hello", { caseInsensitive: true });
validator2.test("hello world"); // should return true
validator2.test("Hello world"); // should return true

// Pattern validation
const validator3 = createValidator("[0-9]+");
validator3.test("123"); // should return true
validator3.test("abc"); // should return false

Test Cases

  • When given the pattern "^test.*" (case-sensitive), it matches strings starting with "test" but not "Test" @test
  • When given the pattern "[a-z]+" with case-insensitive option, it matches both "hello" and "HELLO" @test
  • When given the pattern "\\d{3}", it matches exactly three digits like "123" @test

Implementation

@generates

API

/**
 * Creates a pattern validator from a regex source string
 * @param {string} pattern - The regex source pattern
 * @param {object} options - Configuration options
 * @param {boolean} options.caseInsensitive - Enable case-insensitive matching
 * @returns {object} Validator object with test method
 */
function createValidator(pattern, options) {
  // Implementation here
}

module.exports = { createValidator };

Dependencies { .dependencies }

picomatch { .dependency }

Provides regex creation and pattern matching support.