642
return patternPos === patternLen; // pattern must be exhausted
643
}
645
>
const enum Arrow { Diag = 1, Left = 2, LeftLeft = 3 }
646
>
647
>
/**
648
>
* An array representing a fuzzy match.
649
>
*
650
>
* 0. the score
651
>
* 1. the offset at which matching started
652
>
* 2. `<match_pos_N>`
653
>
* 3. `<match_pos_1>`
654
>
* 4. `<match_pos_0>` etc
655
>
*/
656
>
export type FuzzyScore = [score: number, wordStart: number, ...matches: number[]];
657
>
658
>
export namespace FuzzyScore {
659
>
/**
660
>
* No matches and value `-100`
661
>
*/
662
>
export const Default: FuzzyScore = ([-100, 0]);
663
>
664
>
export function isDefault(score?: FuzzyScore): score is [-100, 0] {
665
return !score || (score.length === 2 && score[0] === -100 && score[1] === 0);
666
}
668
>
669
>
export abstract class FuzzyScoreOptions {
670
>
671
>
static default = { boostFullMatch: true, firstMatchCanBeWeak: false };
672
>
673
>
constructor(
674
readonly firstMatchCanBeWeak: boolean,
675
readonly boostFullMatch: boolean,
676
) { }
678
>
679
>
export interface FuzzyScorer {
680
>
(pattern: string, lowPattern: string, patternPos: number, word: string, lowWord: string, wordPos: number, options?: FuzzyScoreOptions): FuzzyScore | undefined;
681
>
}
682
>
683
>
export function fuzzyScore(pattern: string, patternLow: string, patternStart: number, word: string, wordLow: string, wordStart: number, options: FuzzyScoreOptions = FuzzyScoreOptions.default): FuzzyScore | undefined {
684
685
const patternLen = pattern.length > _maxLen ? _maxLen : pattern.length;