MCPcopy Index your code
hub / github.com/forloopcodes/contextplus / findPathPattern

Function findPathPattern

src/core/clustering.ts:177–198  ·  view source on GitHub ↗
(paths: string[])

Source from the content-addressed store, hash-verified

175}
176
177export function findPathPattern(paths: string[]): string | null {
178 if (paths.length <= 1) return null;
179
180 const parts = paths.map((p) => p.split("/"));
181 let commonPrefix = "";
182 const minLen = Math.min(...parts.map((p) => p.length));
183 for (let i = 0; i < minLen - 1; i++) {
184 if (parts.every((p) => p[i] === parts[0][i])) {
185 commonPrefix += parts[0][i] + "/";
186 } else {
187 break;
188 }
189 }
190
191 const suffixes = paths.map((p) => p.split("/").pop()!);
192 const allSameSuffix = suffixes.every((s) => s === suffixes[0]);
193
194 if (commonPrefix && allSameSuffix) return `${commonPrefix}${suffixes[0]}`;
195 if (commonPrefix) return `${commonPrefix}*`;
196 if (allSameSuffix) return `*/${suffixes[0]}`;
197 return null;
198}

Callers 3

buildHierarchyFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected