MCPcopy Create free account
hub / github.com/TanStack/cli / findClosestAddOn

Function findClosestAddOn

packages/create/src/add-ons.ts:68–89  ·  view source on GitHub ↗
(
  input: string,
  addOns: Array<AddOn>,
)

Source from the content-addressed store, hash-verified

66}
67
68function findClosestAddOn(
69 input: string,
70 addOns: Array<AddOn>,
71): string | undefined {
72 const inputLower = input.toLowerCase()
73 let bestMatch: string | undefined
74 let bestDistance = Infinity
75
76 for (const addOn of addOns) {
77 const d = levenshtein(inputLower, addOn.id.toLowerCase())
78 if (d < bestDistance) {
79 bestDistance = d
80 bestMatch = addOn.id
81 }
82 }
83
84 // Only suggest if the distance is reasonable (less than half the input length)
85 if (bestMatch && bestDistance <= Math.max(Math.floor(input.length / 2), 2)) {
86 return bestMatch
87 }
88 return undefined
89}
90
91function levenshtein(a: string, b: string): number {
92 const m = a.length

Callers 1

finalizeAddOnsFunction · 0.70

Calls 1

levenshteinFunction · 0.70

Tested by

no test coverage detected