UNPKG

typedoc-plugin-markdown

Version:

A plugin for TypeDoc that enables TypeScript API documentation to be generated in Markdown.

47 lines (46 loc) 1.76 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.signatureTitle = void 0; const typedoc_1 = require("typedoc"); const member_symbol_1 = require("./member-symbol"); const type_1 = require("./type"); function signatureTitle(accessor, standalone = true) { var _a, _b; const md = []; if (standalone) { md.push(`${member_symbol_1.memberSymbol.call(this)} `); } if (this.parent && ((_a = this.parent.flags) === null || _a === void 0 ? void 0 : _a.length) > 0) { md.push(this.parent.flags.map((flag) => `\`${flag}\``).join(' ') + ' '); } if (accessor) { md.push(`\`${accessor}\` **${this.name}**`); } else if (this.name !== '__call' && this.name !== '__type') { md.push(`**${this.name}**`); } if (this.typeParameters) { md.push(`<${this.typeParameters .map((typeParameter) => `\`${typeParameter.name}\``) .join(', ')}\\>`); } md.push(`(${getParameters(this.parameters)})`); if (this.type && !((_b = this.parent) === null || _b === void 0 ? void 0 : _b.kindOf(typedoc_1.ReflectionKind.Constructor))) { md.push(`: ${type_1.type.call(this.type, 'object')}`); } return md.join('') + (standalone ? '\n' : ''); } exports.signatureTitle = signatureTitle; const getParameters = (parameters = [], backticks = true) => { return parameters .map((param) => { const paramsmd = []; if (param.flags.isRest) { paramsmd.push('...'); } const paramItem = `${param.name}${param.flags.isOptional || param.defaultValue ? '?' : ''}`; paramsmd.push(backticks ? `\`${paramItem}\`` : paramItem); return paramsmd.join(''); }) .join(', '); };