MCPcopy Create free account
hub / github.com/codeaashu/claude-code / wordAlignedLCP

Function wordAlignedLCP

src/utils/powershell/staticPrefix.ts:294–316  ·  view source on GitHub ↗

* Word-aligned longest common prefix. Doesn't chop mid-word. * Case-insensitive comparison (PowerShell: Git === git), emits first * string's casing. * ["npm run test", "npm run lint"] → "npm run" * ["Git status", "git log"] → "Git" (first-seen casing) * ["Get-Process"] → "Get-Process"

(strings: string[])

Source from the content-addressed store, hash-verified

292 * ["Get-Process"] → "Get-Process"
293 */
294function wordAlignedLCP(strings: string[]): string {
295 if (strings.length === 0) return ''
296 if (strings.length === 1) return strings[0]!
297
298 const firstWords = strings[0]!.split(' ')
299 let commonWordCount = firstWords.length
300
301 for (let i = 1; i < strings.length; i++) {
302 const words = strings[i]!.split(' ')
303 let matchCount = 0
304 while (
305 matchCount < commonWordCount &&
306 matchCount < words.length &&
307 words[matchCount]!.toLowerCase() === firstWords[matchCount]!.toLowerCase()
308 ) {
309 matchCount++
310 }
311 commonWordCount = matchCount
312 if (commonWordCount === 0) break
313 }
314
315 return firstWords.slice(0, commonWordCount).join(' ')
316}
317

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected