Customizable parts of the API.
The Sorter class is the main customizable element of this module.
The Sorter goes through each Transform, transforms it to a simpler form, and
in the process assigns a weight to each character. When comparing two strings,
they are transformed first, then evaluated character-by-character while taking
into consideration the weights assigned by the Transform
instances.
Initializes a new instance of Sorter
.
transforms
transformsfn(str: string): Transform[]
:weights: number[]
opts
transformCache: object
: LRUCache optionscompareCache: object
: MKC options
Transforms the string using #transforms
, assigning a weight to each character.
Cache-enabled.
Compares two strings. Cache-enabled.
Returns a singleton instance of Sorter. Used by kanasort
and
kanasort.compare
.
An LRU cache of transformed strings. Can be set after calling the constructor to override. Set to null to disable.
A multi-key LRU cache of comparisons. Can be set after calling the constructor to override. Set to null to disable.
(Re-)initializes the transform cache. Use if you just want to modify the
options passed to the lru-cache
constructor.
WeightedCharacterTransform
is the base class of all transforms used by this
module. It processes each character of a string and assigns a weight to it. A
lesser weight goes before a greater weight.
An instance is constructed for each string.
Returns an instruction that instructs how to transform the specified TransformedCharacter
instance:
null
orundefined
: No transformation should be done to the character.- Array: [str: string, weight: number]: The character should be transformed to
str
withweight
weight. - Array: [null]: The character should be discarded.