Skip to content

Commit

Permalink
getImportDescription
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart committed Aug 6, 2023
1 parent c850eee commit 3d42cae
Showing 1 changed file with 28 additions and 12 deletions.
40 changes: 28 additions & 12 deletions src/Markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,26 @@ const getExamples = (es: ReadonlyArray<string>): string =>
.map((code) => paragraph(bold("Example")) + paragraph(fence("ts", code)))
.join("\n\n")

const getLocationDescription = (projectName: string, module: Domain.Module): string => {
const getImportDescription = (
projectName: string,
module: Domain.Module,
method: string
): string => {
const namespace = module.path.slice(1).join("/").replace(/\.ts$/, "")
return paragraph(
`Part of the \`${module.name}\` module, imported from \`${projectName}/${namespace}\`.`

return (
paragraph(
`To import and use \`${method}\` from the "${module.name}" module:`
) +
paragraph(
fence(
"ts",
`import * as ${module.name} from "${projectName}/${namespace}"
// Can be accessed like this
${module.name}.${method}`
)
)
)
}

Expand Down Expand Up @@ -248,9 +264,9 @@ export const printModule = (module: Domain.Module, order: number): string => {
).join("\n")

const tableOfContents = (content: string) =>
"<h2 class=\"text-delta\">Table of contents</h2>\n\n"
+ toc(content).content
+ "\n\n"
"<h2 class=\"text-delta\">Table of contents</h2>\n\n" +
toc(content).content +
"\n\n"

return prettify(
[
Expand All @@ -277,13 +293,13 @@ export const printPrintableForAI = (
[
h1(printable.name),
getDescription(printable.description),
getLocationDescription(projectName, module),
getImportDescription(projectName, module, printable.name),
getExamples(printable.examples),
printable._tag === "Function" ?
getSignatures(printable.signatures) :
printable._tag === "Constant" ?
getSignature(printable.signature) :
""
printable._tag === "Function"
? getSignatures(printable.signatures)
: printable._tag === "Constant"
? getSignature(printable.signature)
: ""
].join("\n")
)

Expand Down

0 comments on commit 3d42cae

Please sign in to comment.