mwbot-ts - v1.2.7
    Preparing search index...

    Type Alias ModificationPredicate<T>

    ModificationPredicate: (
        value: T,
        index: number,
        array: T[],
        context: { content: string; touched: boolean },
    ) => string | null

    Type of the callback function used by Wikitext.modify and its shorthand variants. This function is called once for each expression of the specified type and determines whether the expression should be modified.

    Type Parameters

    • T

      The type of markup expressions being modified. This corresponds to the values of ModificationMap, such as Tag for "tags" or Parameter for "parameters".

    Type declaration

      • (
            value: T,
            index: number,
            array: T[],
            context: { content: string; touched: boolean },
        ): string | null
      • Parameters

        • value: T

          The current expression object under consideration for modification.

          Note: The object's startIndex and endIndex values (but not others) are updated in-place as modifications are applied.

        • index: number

          The position of this expression in the array of parsed expressions.

        • array: T[]

          The current array of all expressions of this type, as returned by the corresponding parsing method.

          Note: As with value, the startIndex and endIndex values of the objects in the array are dynamically updated.

        • context: { content: string; touched: boolean }

          Dynamic modification-related information.

          • content: string

            The current state of the full wikitext content. This string is updated after every successful modification (i.e., whenever the predicate returns a string). It reflects the content as it exists at the time this predicate is called for this expression. This is useful for context-sensitive changes, such as inspecting neighboring characters or avoiding redundant edits.

          • touched: boolean

            A boolean indicating whether this expression is a nested child of a previously modified expression. This typically occurs when markup structures are nested (e.g., a <b> inside a <div>), and the parent has already been replaced or modified. In such cases, the expression itself may be invalidated or contextually incorrect in the new content, and the predicate can use this flag to skip or handle it differently.

        Returns string | null

        A string to replace the current expression, or null to leave it unchanged. Returning null ensures that the original text is preserved.