CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-linkify-it

Links recognition library with FULL unicode support for detecting high-quality link patterns in plain text

Overall
score

97%

Overview
Eval results
Files

task.mdevals/scenario-8/

Custom Link Pattern Validator

Build a link validator that can detect custom link patterns in text using configurable validation rules. The validator should support custom schemas with validation functions that can perform multi-stage checks on potential matches.

Requirements

Your implementation should provide:

  1. Custom Schema Registration: Register custom link schemas (e.g., repo:, ticket:) with validation rules
  2. Validation Functions: Support validation functions that receive the text, position, and can check multiple conditions
  3. Link Detection: Detect all valid links in text that match registered schemas
  4. Match Details: Return match information including position (index, lastIndex) and the matched text

Implementation

@generates

API

/**
 * Creates a link validator with custom schema support
 */
class LinkValidator {
  /**
   * Add a custom schema with validation rules
   * @param {string} schema - The schema prefix (e.g., 'repo:')
   * @param {object} definition - Schema definition with validate function or regex
   */
  addSchema(schema, definition) {
    // IMPLEMENTATION HERE
  }

  /**
   * Test if text contains any valid links
   * @param {string} text - Text to check for links
   * @returns {boolean} True if valid links are found
   */
  test(text) {
    // IMPLEMENTATION HERE
  }

  /**
   * Find all valid links in text
   * @param {string} text - Text to search
   * @returns {Array|null} Array of match objects with schema, index, lastIndex, raw, url properties
   */
  match(text) {
    // IMPLEMENTATION HERE
  }
}

module.exports = { LinkValidator };

Test Cases

  • Adding a custom repo: schema with a regex validator that matches owner/name pattern should correctly detect repo:user/project in text @test
  • Adding a custom ticket: schema with a function validator that checks for numeric IDs should accept ticket:123 but reject ticket:abc @test
  • The match method should return an array of match objects with correct index and lastIndex positions for multiple custom schema matches in text @test
  • A function validator that performs multi-stage checks (e.g., verifying format then checking length constraints) should correctly validate complex patterns @test

Dependencies { .dependencies }

linkify-it { .dependency }

Provides link detection and validation capabilities with custom schema support.

Install with Tessl CLI

npx tessl i tessl/npm-linkify-it

tile.json