MCPcopy Index your code
hub / github.com/npmx-dev/npmx.dev / renderClassMembers

Function renderClassMembers

server/utils/docs/render.ts:301–367  ·  view source on GitHub ↗

* Render class members (constructor, properties, methods).

(def: NonNullable<DenoDocNode['classDef']>)

Source from the content-addressed store, hash-verified

299 * Render class members (constructor, properties, methods).
300 */
301function renderClassMembers(def: NonNullable<DenoDocNode['classDef']>): string {
302 const lines: string[] = []
303 const { constructors, properties, methods } = def
304
305 if (constructors && constructors.length > 0) {
306 lines.push(`<div class="docs-members">`)
307 lines.push(`<h4>Constructor</h4>`)
308 for (const ctor of constructors) {
309 const params = ctor.params?.map(p => formatParam(p)).join(', ') || ''
310 lines.push(`<pre><code>constructor(${escapeHtml(params)})</code></pre>`)
311 }
312 lines.push(`</div>`)
313 }
314
315 if (properties && properties.length > 0) {
316 const propertyItems: DefinitionListItem[] = properties.map(prop => {
317 const modifiers: string[] = []
318 if (prop.isStatic) modifiers.push('static')
319 if (prop.readonly) modifiers.push('readonly')
320 const modStr = modifiers.length > 0 ? `${modifiers.join(' ')} ` : ''
321 const type = formatType(prop.tsType)
322 const opt = prop.optional ? '?' : ''
323 const typeStr = type ? `: ${type}` : ''
324
325 return {
326 signature: `${modStr}${prop.name}${opt}${typeStr}`,
327 description: prop.jsDoc?.doc,
328 }
329 })
330
331 lines.push(renderMemberList('Properties', propertyItems))
332 }
333
334 const getters = methods?.filter(m => m.kind === 'getter') || []
335 const regularMethods = methods?.filter(m => m.kind !== 'getter') || []
336
337 if (getters.length > 0) {
338 const getterItems: DefinitionListItem[] = getters.map(getter => {
339 const ret = formatType(getter.functionDef?.returnType) || 'unknown'
340 const staticStr = getter.isStatic ? 'static ' : ''
341
342 return {
343 signature: `${staticStr}get ${getter.name}: ${ret}`,
344 description: getter.jsDoc?.doc,
345 }
346 })
347
348 lines.push(renderMemberList('Getters', getterItems))
349 }
350
351 if (regularMethods.length > 0) {
352 const methodItems: DefinitionListItem[] = regularMethods.map(method => {
353 const params = method.functionDef?.params?.map(p => formatParam(p)).join(', ') || ''
354 const ret = formatType(method.functionDef?.returnType) || 'void'
355 const staticStr = method.isStatic ? 'static ' : ''
356
357 return {
358 signature: `${staticStr}${method.name}(${params}): ${ret}`,

Callers 1

renderMergedSymbolFunction · 0.85

Calls 4

formatParamFunction · 0.90
escapeHtmlFunction · 0.90
formatTypeFunction · 0.90
renderMemberListFunction · 0.85

Tested by

no test coverage detected