1 | /**
|
2 | * The namespace for string-specific algorithms.
|
3 | */
|
4 | export declare namespace StringExt {
|
5 | /**
|
6 | * Find the indices of characters in a source text.
|
7 | *
|
8 | * @param source - The source text which should be searched.
|
9 | *
|
10 | * @param query - The characters to locate in the source text.
|
11 | *
|
12 | * @param start - The index to start the search.
|
13 | *
|
14 | * @returns The matched indices, or `null` if there is no match.
|
15 | *
|
16 | * #### Complexity
|
17 | * Linear on `sourceText`.
|
18 | *
|
19 | * #### Notes
|
20 | * In order for there to be a match, all of the characters in `query`
|
21 | * **must** appear in `source` in the order given by `query`.
|
22 | *
|
23 | * Characters are matched using strict `===` equality.
|
24 | */
|
25 | function findIndices(source: string, query: string, start?: number): number[] | null;
|
26 | /**
|
27 | * The result of a string match function.
|
28 | */
|
29 | interface IMatchResult {
|
30 | /**
|
31 | * A score which indicates the strength of the match.
|
32 | *
|
33 | * The documentation of a given match function should specify
|
34 | * whether a lower or higher score is a stronger match.
|
35 | */
|
36 | score: number;
|
37 | /**
|
38 | * The indices of the matched characters in the source text.
|
39 | *
|
40 | * The indices will appear in increasing order.
|
41 | */
|
42 | indices: number[];
|
43 | }
|
44 | /**
|
45 | * A string matcher which uses a sum-of-squares algorithm.
|
46 | *
|
47 | * @param source - The source text which should be searched.
|
48 | *
|
49 | * @param query - The characters to locate in the source text.
|
50 | *
|
51 | * @param start - The index to start the search.
|
52 | *
|
53 | * @returns The match result, or `null` if there is no match.
|
54 | * A lower `score` represents a stronger match.
|
55 | *
|
56 | * #### Complexity
|
57 | * Linear on `sourceText`.
|
58 | *
|
59 | * #### Notes
|
60 | * This scoring algorithm uses a sum-of-squares approach to determine
|
61 | * the score. In order for there to be a match, all of the characters
|
62 | * in `query` **must** appear in `source` in order. The index of each
|
63 | * matching character is squared and added to the score. This means
|
64 | * that early and consecutive character matches are preferred, while
|
65 | * late matches are heavily penalized.
|
66 | */
|
67 | function matchSumOfSquares(source: string, query: string, start?: number): IMatchResult | null;
|
68 | /**
|
69 | * A string matcher which uses a sum-of-deltas algorithm.
|
70 | *
|
71 | * @param source - The source text which should be searched.
|
72 | *
|
73 | * @param query - The characters to locate in the source text.
|
74 | *
|
75 | * @param start - The index to start the search.
|
76 | *
|
77 | * @returns The match result, or `null` if there is no match.
|
78 | * A lower `score` represents a stronger match.
|
79 | *
|
80 | * #### Complexity
|
81 | * Linear on `sourceText`.
|
82 | *
|
83 | * #### Notes
|
84 | * This scoring algorithm uses a sum-of-deltas approach to determine
|
85 | * the score. In order for there to be a match, all of the characters
|
86 | * in `query` **must** appear in `source` in order. The delta between
|
87 | * the indices are summed to create the score. This means that groups
|
88 | * of matched characters are preferred, while fragmented matches are
|
89 | * penalized.
|
90 | */
|
91 | function matchSumOfDeltas(source: string, query: string, start?: number): IMatchResult | null;
|
92 | /**
|
93 | * Highlight the matched characters of a source text.
|
94 | *
|
95 | * @param source - The text which should be highlighted.
|
96 | *
|
97 | * @param indices - The indices of the matched characters. They must
|
98 | * appear in increasing order and must be in bounds of the source.
|
99 | *
|
100 | * @param fn - The function to apply to the matched chunks.
|
101 | *
|
102 | * @returns An array of unmatched and highlighted chunks.
|
103 | */
|
104 | function highlight<T>(source: string, indices: ReadonlyArray<number>, fn: (chunk: string) => T): Array<string | T>;
|
105 | /**
|
106 | * A 3-way string comparison function.
|
107 | *
|
108 | * @param a - The first string of interest.
|
109 | *
|
110 | * @param b - The second string of interest.
|
111 | *
|
112 | * @returns `-1` if `a < b`, else `1` if `a > b`, else `0`.
|
113 | */
|
114 | function cmp(a: string, b: string): number;
|
115 | }
|
116 | //# sourceMappingURL=string.d.ts.map |
\ | No newline at end of file |