typedoc-better-json
Version:
Transforms typedoc's json output to a format that is better for creating custom documentation website
154 lines (144 loc) • 4.25 kB
TypeScript
import { RootContent } from 'mdast';
import { JSONOutput } from 'typedoc';
type SummaryNode = RootContent;
type Summary = SummaryNode[];
type BlockTag = Omit<JSONOutput.CommentTag, "content"> & {
summary?: Summary;
};
type Flags = JSONOutput.ReflectionFlags;
type TransformedDoc = {
meta: {
typedocBetterJsonVersion: string;
};
functions?: FunctionDoc[];
hooks?: FunctionDoc[];
components?: FunctionDoc[];
types?: InterfaceDoc[];
variables?: VariableDoc[];
enums?: EnumDoc[];
classes?: ClassDoc[];
};
type TokenInfo = {
name: string;
package?: string;
};
type TypeInfo = {
code: string;
tokens?: TokenInfo[];
};
type SomeDoc = FunctionDoc | InterfaceDoc | VariableDoc | EnumDoc | ClassDoc;
type SubTypeDeclarationDoc = {
kind: "subtype";
name: string;
type: TypeInfo;
summary?: Summary;
blockTags?: BlockTag[];
};
type TypeDeclarationDoc = SubTypeDeclarationDoc | FunctionDoc;
type TypeParameter = {
name: string;
extendsType?: TypeInfo;
defaultType?: TypeInfo;
};
type FunctionDoc = {
kind: "function";
name: string;
source?: string;
signatures?: FunctionSignature[];
flags?: Flags;
};
type AccessorDoc = {
kind: "accessor";
name: string;
source?: string;
summary?: Summary;
blockTags?: BlockTag[];
returns?: {
type?: TypeInfo;
summary?: Summary;
};
flags?: Flags;
};
type FunctionSignature = {
summary?: Summary;
parameters?: FunctionParameter[];
typeParameters?: TypeParameter[];
returns?: {
type?: TypeInfo;
summary?: Summary;
};
blockTags?: BlockTag[];
flags?: Flags;
inheritedFrom?: {
name: string;
};
};
type FunctionParameter = {
name: string;
type?: TypeInfo;
summary?: Summary;
blockTags?: BlockTag[];
flags?: Flags;
};
type InterfaceDoc = {
kind: "type";
name: string;
source?: string;
summary?: Summary;
blockTags?: BlockTag[];
type?: TypeInfo;
typeDeclaration?: TypeDeclarationDoc[];
typeParameters?: TypeParameter[];
extends?: TypeInfo[];
implements?: TypeInfo[];
};
type VariableDoc = {
kind: "variable";
name: string;
source?: string;
summary?: Summary;
blockTags?: BlockTag[];
typeDeclaration?: TypeDeclarationDoc[];
flags?: JSONOutput.ReflectionFlags;
type?: TypeInfo;
};
type EnumDoc = {
kind: "enum";
name: string;
source?: string;
summary?: Summary;
blockTags?: BlockTag[];
members: Array<{
name: string;
value: TypeInfo;
summary?: Summary;
blockTags?: BlockTag[];
}>;
};
type ClassDoc = {
kind: "class";
name: string;
source?: string;
constructor: FunctionDoc;
properties?: VariableDoc[];
methods?: FunctionDoc[];
accessors?: AccessorDoc[];
summary?: Summary;
blockTags?: BlockTag[];
implements?: TypeInfo[];
extends?: TypeInfo[];
typeParameters?: TypeParameter[];
};
/**
* Transform the typedoc's JSON output to a better format which is more suitable for creating custom website
* @param inputData - typedoc's JSON output parsed into a JS object via JSON.parse
*/
declare function transform(inputData: JSONOutput.ProjectReflection): TransformedDoc;
declare function getInterfaceSignature(doc: InterfaceDoc): TypeInfo;
declare function getClassSignature(classDoc: ClassDoc): TypeInfo;
declare function getEnumSignature(doc: EnumDoc): TypeInfo;
declare function getFunctionSignature(name: string, signature: FunctionSignature): TypeInfo;
declare function getParametersSignature(parameters: FunctionParameter[]): TypeInfo;
declare function getAccessorSignature(doc: AccessorDoc): TypeInfo;
declare function getTypeParamSignature(typeParameters: TypeParameter[]): TypeInfo;
export { AccessorDoc, BlockTag, ClassDoc, EnumDoc, Flags, FunctionDoc, FunctionParameter, FunctionSignature, InterfaceDoc, SomeDoc, SubTypeDeclarationDoc, Summary, SummaryNode, TokenInfo, TransformedDoc, TypeDeclarationDoc, TypeInfo, TypeParameter, VariableDoc, getAccessorSignature, getClassSignature, getEnumSignature, getFunctionSignature, getInterfaceSignature, getParametersSignature, getTypeParamSignature, transform };