Class StringMatchSort

A class that allows to build and run a sorting algorithm on a list of strings.

Hierarchy

Constructors

  • Instantiates a StringMatchSort object.

    Parameters

    • Optional defaultTransformations: StringTransformationFunction[]

      Transformation functions to apply to all strings. If a rank function is not successful, it will try again with the transformations applied both to the search term and to the value. It will first try only with the first transformations, then with the first and second together, and so on. The more transformations necessary, the greater the resulting rank number will be.

    Returns StringMatchSort

Properties

defaultTransformations: null | StringTransformationFunction[] = null
indexedStringTransform: IndexedStringTransform

Methods

  • Chains a new rank function to the sorting algorithm.

    Parameters

    • exactRankFunction: MatchRankFunction<string>

      The rank function to chain.

    • Optional transformations: StringTransformationFunction[]

      Transformation functions to apply to the rank function. If not provided, the default transformations will be used.

    Returns StringMatchSort

    See

    MatchSort.chain

  • Instantiates a RankSort object for the given search term.

    Parameters

    • search: string

      The search term.

    Returns RankSort<string>

    The RankSort object.

  • Generates a MatchSort object that applies the sorting algorithm to a two-dimensional array, where the best ranking item in each list is used in the final algorithm. This can be used to sort lists of items with multiple searchable keywords.

    Returns MatchSort<string[]>

    The generated MatchSort object.

  • Generates a MatchSort object that applies the sorting algorithm to the given property of the values.

    Type Parameters

    • P extends string

    • O extends {
          [key in string]: string
      }

    Parameters

    • property: P

      The key of the property that holds the value to sort by.

    Returns MatchSort<O>

    The generated MatchSort object.

  • Sets the filter function.

    Parameters

    • filter: BooleanMatchFunction<string>

      The filter function.

    • Optional transformations: StringTransformationFunction[]

      Transformation functions to apply to the filter function. If not provided, the default transformations will be used. The filter function will apply all transformations at once to both the search term and the value before filtering.

    Returns StringMatchSort

    The StringMatchSort object.

  • Runs the sorting algorithm on the given values.

    Parameters

    • search: string

      The search term.

    • values: string[]

      The values to sort.

    Returns string[]

    The sorted values.

    Remarks

    The result is cached, so that if the search term starts with the previous search term, the previous result is used as the input to the sort function. This applies as long as the given values array is the same object.

  • Instantiates a StringMatchSort object from a single rank function.

    Parameters

    • matchRankFunction: MatchRankFunction<string>

      The rank function.

    • Optional transformations: StringTransformationFunction[]

      Transformation functions to apply to the rank function.

    Returns StringMatchSort

    The StringMatchSort object.

Generated using TypeDoc