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

Function renderInterfaceMembers

server/utils/docs/render.ts:372–414  ·  view source on GitHub ↗

* Render interface members (properties, methods).

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

Source from the content-addressed store, hash-verified

370 * Render interface members (properties, methods).
371 */
372function renderInterfaceMembers(def: NonNullable<DenoDocNode['interfaceDef']>): string {
373 const lines: string[] = []
374 const { properties, methods } = def
375
376 if (properties && properties.length > 0) {
377 lines.push(`<div class="docs-members">`)
378 lines.push(`<h4>Properties</h4>`)
379 lines.push(`<dl>`)
380 for (const prop of properties) {
381 const type = formatType(prop.tsType)
382 const opt = prop.optional ? '?' : ''
383 const ro = prop.readonly ? 'readonly ' : ''
384 lines.push(
385 `<dt><code>${escapeHtml(ro)}${escapeHtml(prop.name)}${opt}: ${escapeHtml(type)}</code></dt>`,
386 )
387 if (prop.jsDoc?.doc) {
388 lines.push(`<dd>${escapeHtml(prop.jsDoc.doc.split('\n')[0] ?? '')}</dd>`)
389 }
390 }
391 lines.push(`</dl>`)
392 lines.push(`</div>`)
393 }
394
395 if (methods && methods.length > 0) {
396 lines.push(`<div class="docs-members">`)
397 lines.push(`<h4>Methods</h4>`)
398 lines.push(`<dl>`)
399 for (const method of methods) {
400 const params = method.params?.map(p => formatParam(p)).join(', ') || ''
401 const ret = formatType(method.returnType) || 'void'
402 lines.push(
403 `<dt><code>${escapeHtml(method.name)}(${escapeHtml(params)}): ${escapeHtml(ret)}</code></dt>`,
404 )
405 if (method.jsDoc?.doc) {
406 lines.push(`<dd>${escapeHtml(method.jsDoc.doc.split('\n')[0] ?? '')}</dd>`)
407 }
408 }
409 lines.push(`</dl>`)
410 lines.push(`</div>`)
411 }
412
413 return lines.join('\n')
414}
415
416/**
417 * Render enum members.

Callers 1

renderMergedSymbolFunction · 0.85

Calls 3

formatTypeFunction · 0.90
escapeHtmlFunction · 0.90
formatParamFunction · 0.90

Tested by

no test coverage detected