mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 08:03:30 +01:00
feat: show default values in docs (#10465)
This commit is contained in:
@@ -114,7 +114,7 @@ interface DocgenEventJson {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface DocgenParamJson {
|
interface DocgenParamJson {
|
||||||
default?: string;
|
default?: boolean | number | string;
|
||||||
description: string;
|
description: string;
|
||||||
name: string;
|
name: string;
|
||||||
nullable?: boolean;
|
nullable?: boolean;
|
||||||
@@ -155,7 +155,7 @@ interface DocgenMethodJson {
|
|||||||
interface DocgenPropertyJson {
|
interface DocgenPropertyJson {
|
||||||
abstract?: boolean;
|
abstract?: boolean;
|
||||||
access?: DocgenAccess;
|
access?: DocgenAccess;
|
||||||
default?: string;
|
default?: boolean | number | string;
|
||||||
deprecated?: DocgenDeprecated;
|
deprecated?: DocgenDeprecated;
|
||||||
description: string;
|
description: string;
|
||||||
meta: DocgenMetaJson;
|
meta: DocgenMetaJson;
|
||||||
@@ -1744,6 +1744,14 @@ export class ApiModelGenerator {
|
|||||||
return sourceLocation;
|
return sourceLocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _escapeSpecialChars(input: boolean | number | string) {
|
||||||
|
if (typeof input !== 'string') {
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
|
||||||
|
return input.replaceAll(/(?<char>[{}])/g, '\\$<char>');
|
||||||
|
}
|
||||||
|
|
||||||
private _fixLinkTags(input?: string): string | undefined {
|
private _fixLinkTags(input?: string): string | undefined {
|
||||||
return input
|
return input
|
||||||
?.replaceAll(linkRegEx, (_match, _p1, _p2, _p3, _p4, _p5, _offset, _string, groups) => {
|
?.replaceAll(linkRegEx, (_match, _p1, _p2, _p3, _p4, _p5, _offset, _string, groups) => {
|
||||||
@@ -1819,7 +1827,7 @@ export class ApiModelGenerator {
|
|||||||
isOptional: Boolean(prop.nullable),
|
isOptional: Boolean(prop.nullable),
|
||||||
isReadonly: Boolean(prop.readonly),
|
isReadonly: Boolean(prop.readonly),
|
||||||
docComment: this._tsDocParser.parseString(
|
docComment: this._tsDocParser.parseString(
|
||||||
`/**\n * ${this._fixLinkTags(prop.description) ?? ''}\n${
|
`/**\n * ${this._fixLinkTags(prop.description) ?? ''}${prop.default ? ` (default: ${this._escapeSpecialChars(prop.default)})` : ''}\n${
|
||||||
prop.see?.map((see) => ` * @see ${see}\n`).join('') ?? ''
|
prop.see?.map((see) => ` * @see ${see}\n`).join('') ?? ''
|
||||||
}${prop.readonly ? ' * @readonly\n' : ''} */`,
|
}${prop.readonly ? ' * @readonly\n' : ''} */`,
|
||||||
).docComment,
|
).docComment,
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ import {
|
|||||||
} from '@discordjs/api-extractor-model';
|
} from '@discordjs/api-extractor-model';
|
||||||
import { DocNodeKind, SelectorKind, StandardTags } from '@microsoft/tsdoc';
|
import { DocNodeKind, SelectorKind, StandardTags } from '@microsoft/tsdoc';
|
||||||
import type {
|
import type {
|
||||||
|
DocEscapedText,
|
||||||
DocNode,
|
DocNode,
|
||||||
DocNodeContainer,
|
DocNodeContainer,
|
||||||
DocDeclarationReference,
|
DocDeclarationReference,
|
||||||
@@ -298,6 +299,11 @@ function itemTsDoc(item: DocNode, apiItem: ApiItem) {
|
|||||||
kind: DocNodeKind.PlainText,
|
kind: DocNodeKind.PlainText,
|
||||||
text: (node as DocPlainText).text,
|
text: (node as DocPlainText).text,
|
||||||
};
|
};
|
||||||
|
case DocNodeKind.EscapedText:
|
||||||
|
return {
|
||||||
|
kind: DocNodeKind.PlainText,
|
||||||
|
text: (node as DocEscapedText).decodedText,
|
||||||
|
};
|
||||||
case DocNodeKind.Section:
|
case DocNodeKind.Section:
|
||||||
case DocNodeKind.Paragraph:
|
case DocNodeKind.Paragraph:
|
||||||
return (node as DocNodeContainer).nodes.map((node) => createNode(node));
|
return (node as DocNodeContainer).nodes.map((node) => createNode(node));
|
||||||
|
|||||||
Reference in New Issue
Block a user