Class MatchSort<T>

A class that allows to build and run a sorting algorithm on a list of items with type T.

Type Parameters

  • T

Hierarchy

Constructors

Properties

filter: BooleanMatchFunction<T> = ...
matchRankFunctionList: MatchRankFunction<T>[]
searchFunction: SearchFunction<T> = ...
searchListIndex: SearchListIndex<T>

Methods

  • Chains a new rank function to the sorting algorithm. If a chained rank function returns a rank of 0 or true, the next rank functions in the chain will be ignored. Otherwise, the resulting number will be added to the rank. If the rank function returns false, a value of 1 will be added. The final sort function will order the values by the rank, with the lowest number first.

    Parameters

    • rankFunction: MatchRankFunction<T>

      The rank function to chain.

    Returns MatchSort<T>

  • Parameters

    • search: string

    Returns RankFunction<T>[]

  • Instantiates a RankSort object for the given search term.

    Parameters

    • search: string

      The search term.

    Returns RankSort<T>

    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<T[]>

    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]: T
      }

    Parameters

    • property: P

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

    Returns MatchSort<O>

    The generated MatchSort object.

  • Allows to set all the rank functions at once. This will override any previously chained rank functions.

    Parameters

    • matchRankFunctionList: MatchRankFunction<T>[]

      The rank functions to set.

    Returns MatchSort<T>

  • Runs the sorting algorithm on the given values.

    Parameters

    • search: string

      The search term.

    • values: T[]

      The values to sort.

    Returns T[]

    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.

Generated using TypeDoc