nameScore

tcmts.cli.pages.nameScore · #knrhf3hl · term · runs anywhere

How well path matches a name the finder is asked for (lower, lower case): the last part exactly (100), the start of it (80), anywhere in the path (60), its letters in order (under 40, less the longer the path), or not at all (0).

export function nameScore(lower: string, path: string): number {
  const last = path.slice(path.lastIndexOf(".") + 1).toLowerCase();
  const full = path.toLowerCase();
  if (last === lower) return 100;
  if (last.startsWith(lower)) return 80;
  if (full.includes(lower)) return 60;
  let i = 0;
  for (const ch of full) if (ch === lower[i]) i++;
  return i === lower.length ? 40 - (full.length - lower.length) / 100 : 0;
}

used by