@getpaseo/protocol 0.4.0 → 0.5.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -28,6 +28,8 @@ export interface FuzzyPolicy {
28
28
  }
29
29
  export declare function fuzzyPolicyForToken(token: string): FuzzyPolicy | null;
30
30
  export declare function scoreMatch(query: string, text: string, options?: MatchOptions): MatchScore | null;
31
+ /** Match a query against a complete displayed path, including its separators. */
32
+ export declare function scorePathMatch(query: string, path: string): MatchScore | null;
31
33
  export interface MatchRange {
32
34
  start: number;
33
35
  length: number;
@@ -174,6 +174,34 @@ export function scoreMatch(query, text, options = {}) {
174
174
  const fuzzy = options.fuzzy;
175
175
  return fuzzy ? scoreFuzzyMatch(q, t, fuzzy) : null;
176
176
  }
177
+ function compactText(value) {
178
+ let compact = "";
179
+ const offsets = [];
180
+ for (let index = 0; index < value.length; index += 1) {
181
+ if (!/[a-z0-9]/i.test(value[index]))
182
+ continue;
183
+ compact += value[index].toLowerCase();
184
+ offsets.push(index);
185
+ }
186
+ return { value: compact, offsets };
187
+ }
188
+ /** Match a query against a complete displayed path, including its separators. */
189
+ export function scorePathMatch(query, path) {
190
+ const direct = scoreMatch(query, path);
191
+ if (direct)
192
+ return direct;
193
+ const compactQuery = compactText(query);
194
+ const compactPath = compactText(path);
195
+ if (!compactQuery.value || !compactPath.value)
196
+ return null;
197
+ const compactScore = scoreMatch(compactQuery.value, compactPath.value);
198
+ if (!compactScore)
199
+ return null;
200
+ return {
201
+ ...compactScore,
202
+ offset: compactPath.offsets[compactScore.offset] ?? compactScore.offset,
203
+ };
204
+ }
177
205
  function mergeAdjacentRanges(indices) {
178
206
  const ranges = [];
179
207
  for (const index of indices) {