CtrlK
CommunityDocumentationLog inGet started
Tessl Logo

tessl/npm-escape-string-regexp

Escape RegExp special characters in strings for safe use in regular expressions

Overall
score

100%

Evaluation100%

1.00x

Agent success when using this tile

Overview
Eval results
Files

task.mdevals/scenario-7/

String Pattern Matcher

Build a utility that creates safe regular expression patterns from user-provided search strings. The utility must validate inputs properly to prevent runtime errors.

Capabilities

Input validation for pattern creation

The pattern matcher must validate all inputs before processing them.

  • Passing a string "hello" returns a valid pattern that can be used in RegExp @test
  • Passing null to the pattern creator throws a TypeError @test
  • Passing undefined to the pattern creator throws a TypeError @test
  • Passing a number 123 to the pattern creator throws a TypeError @test
  • Passing an object {} to the pattern creator throws a TypeError @test

Pattern matching functionality

Once validated, the utility creates patterns that match the input string literally.

  • Creating a pattern from "test" successfully matches the string "test" in a larger text @test
  • Creating a pattern from "$100" successfully matches "$100" without treating $ as a regex metacharacter @test

Implementation

@generates

API

/**
 * Creates a safe regex pattern from a user-provided string.
 * Validates that the input is a string and throws TypeError for invalid inputs.
 *
 * @param {string} searchString - The string to convert into a safe pattern
 * @returns {string} A string that can be safely used in a RegExp constructor
 * @throws {TypeError} When the input is not a string
 */
function createSafePattern(searchString) {
  // IMPLEMENTATION HERE
}

module.exports = { createSafePattern };

Dependencies { .dependencies }

escape-string-regexp { .dependency }

Provides functionality for escaping special characters in strings for safe use in regular expressions.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-escape-string-regexp@5.0.0

tile.json