Options
All
  • Public
  • Public/Protected
  • All
Menu

Module StringExt

The namespace for string-specific algorithms.

Index

Functions

findIndices

  • findIndices(source: string, query: string, start?: number): number[] | null
  • Find the indices of characters in a source text.

    Parameters

    • source: string

      The source text which should be searched.

    • query: string

      The characters to locate in the source text.

    • Default value start: number = 0

      The index to start the search.

    Returns number[] | null

    The matched indices, or null if there is no match.

    Complexity

    Linear on sourceText.

    Notes

    In order for there to be a match, all of the characters in query must appear in source in the order given by query.

    Characters are matched using strict === equality.

highlight

  • highlight<T>(source: string, indices: ReadonlyArray<number>, fn: function): Array<string | T>
  • Highlight the matched characters of a source text.

    Type parameters

    • T

    Parameters

    • source: string

      The text which should be highlighted.

    • indices: ReadonlyArray<number>

      The indices of the matched characters. They must appear in increasing order and must be in bounds of the source.

    • fn: function

      The function to apply to the matched chunks.

        • (chunk: string): T
        • Parameters

          • chunk: string

          Returns T

    Returns Array<string | T>

    An array of unmatched and highlighted chunks.

matchSumOfDeltas

  • matchSumOfDeltas(source: string, query: string, start?: number): IMatchResult | null
  • A string matcher which uses a sum-of-deltas algorithm.

    Parameters

    • source: string

      The source text which should be searched.

    • query: string

      The characters to locate in the source text.

    • Default value start: number = 0

      The index to start the search.

    Returns IMatchResult | null

    The match result, or null if there is no match. A lower score represents a stronger match.

    Complexity

    Linear on sourceText.

    Notes

    This scoring algorithm uses a sum-of-deltas approach to determine the score. In order for there to be a match, all of the characters in query must appear in source in order. The delta between the indices are summed to create the score. This means that groups of matched characters are preferred, while fragmented matches are penalized.

matchSumOfSquares

  • matchSumOfSquares(source: string, query: string, start?: number): IMatchResult | null
  • A string matcher which uses a sum-of-squares algorithm.

    Parameters

    • source: string

      The source text which should be searched.

    • query: string

      The characters to locate in the source text.

    • Default value start: number = 0

      The index to start the search.

    Returns IMatchResult | null

    The match result, or null if there is no match. A lower score represents a stronger match.

    Complexity

    Linear on sourceText.

    Notes

    This scoring algorithm uses a sum-of-squares approach to determine the score. In order for there to be a match, all of the characters in query must appear in source in order. The index of each matching character is squared and added to the score. This means that early and consecutive character matches are preferred, while late matches are heavily penalized.

Generated using TypeDoc