MCPcopy
hub / github.com/npmx-dev/npmx.dev / mergeOverloads

Function mergeOverloads

server/utils/docs/processing.ts:65–100  ·  view source on GitHub ↗
(nodes: DenoDocNode[])

Source from the content-addressed store, hash-verified

63 * (e.g., React's `h` has 23 overloads). This groups them together.
64 */
65export function mergeOverloads(nodes: DenoDocNode[]): MergedSymbol[] {
66 const byKey = new Map<string, DenoDocNode[]>()
67
68 for (const node of nodes) {
69 const cleanName = cleanSymbolName(node.name)
70 const key = `${node.kind}:${cleanName}`
71 const existing = byKey.get(key)
72 if (existing) {
73 existing.push(node)
74 } else {
75 byKey.set(key, [node])
76 }
77 }
78
79 const result: MergedSymbol[] = []
80
81 for (const [, groupedNodes] of byKey) {
82 const first = groupedNodes[0]
83 if (!first) continue // Should never happen, but defensive programming etc
84
85 // Use JSDoc from the best-documented overload
86 const withDoc = groupedNodes.find(n => n.jsDoc?.doc) ?? first
87
88 result.push({
89 name: cleanSymbolName(first.name),
90 kind: first.kind,
91 nodes: groupedNodes,
92 jsDoc: withDoc.jsDoc,
93 })
94 }
95
96 // Sort alphabetically
97 result.sort((a, b) => a.name.localeCompare(b.name))
98
99 return result
100}
101
102/**
103 * Group merged symbols by their kind (function, class, etc.)

Callers 1

generateDocsWithDenoFunction · 0.90

Calls 3

cleanSymbolNameFunction · 0.90
getMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected