(paths: string[])
| 175 | } |
| 176 | |
| 177 | export 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 | } |
no outgoing calls
no test coverage detected