Skip to content

Commit a81320c

Browse files
committed
refactor: move components utils to lib/components
1 parent f1447bc commit a81320c

30 files changed

Lines changed: 61 additions & 51 deletions
File renamed without changes.

lib/declaration-signature-to-html.ts renamed to lib/components/declaration-signature-to-html.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { AllExtractedDeclaration } from "@jsdocs-io/extractor";
2+
import { codeToHtml } from "../shiki/shiki.bundle";
3+
import { domPurify } from "../utils/dom-purify";
24
import type { DeclarationUrlFn } from "./declaration-url";
3-
import { domPurify } from "./dom-purify";
4-
import { codeToHtml } from "./shiki.bundle";
55

66
const reservedKeywords = new Set([
77
"any",
@@ -75,10 +75,10 @@ const reservedKeywords = new Set([
7575
"yield",
7676
]);
7777

78-
export const declarationSignatureToHtml = async (
78+
export async function declarationSignatureToHtml(
7979
declaration: AllExtractedDeclaration,
8080
declarationUrl: DeclarationUrlFn,
81-
): Promise<string> => {
81+
): Promise<string> {
8282
const { signature, isWrapped } = prepareSignature(declaration);
8383
const html = await codeToHtml(signature, {
8484
// Render to highlighted HTML if the signature is not too long,
@@ -130,9 +130,9 @@ export const declarationSignatureToHtml = async (
130130
],
131131
});
132132
return domPurify.sanitize(html);
133-
};
133+
}
134134

135-
const prepareSignature = (declaration: AllExtractedDeclaration) => {
135+
function prepareSignature(declaration: AllExtractedDeclaration) {
136136
const { kind, signature } = declaration;
137137
switch (kind) {
138138
case "variable":
@@ -170,4 +170,4 @@ const prepareSignature = (declaration: AllExtractedDeclaration) => {
170170
};
171171
}
172172
}
173-
};
173+
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,17 @@ const knownTypes = [
3737
["typeof", "https://www.typescriptlang.org/docs/handbook/2/typeof-types.html"],
3838
] as const;
3939

40-
export const makeDeclarationUrl = (declarations: ExtractedDeclaration[]) => {
40+
export function makeDeclarationUrl(declarations: ExtractedDeclaration[]) {
4141
const nameToUrl = new Map<string, string>(knownTypes);
4242
addDeclarations(declarations, nameToUrl);
4343
return (name: string): string | undefined => nameToUrl.get(name);
44-
};
44+
}
4545

46-
const addDeclarations = (declarations: ExtractedDeclaration[], nameToUrl: Map<string, string>) => {
46+
function addDeclarations(declarations: ExtractedDeclaration[], nameToUrl: Map<string, string>) {
4747
for (const declaration of declarations) {
4848
if (declaration.kind === "namespace") {
4949
addDeclarations(declaration.declarations, nameToUrl);
5050
}
5151
nameToUrl.set(declaration.name, `#${shortId(declaration.id)}`);
5252
}
53-
};
53+
}
File renamed without changes.
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { trimNewlines } from "trim-newlines";
2-
import { domPurify } from "./dom-purify";
3-
import { bundledLanguages, codeToHtml } from "./shiki.bundle";
2+
import { bundledLanguages, codeToHtml } from "../shiki/shiki.bundle";
3+
import { domPurify } from "../utils/dom-purify";
44

55
const languages = new Set(Object.keys(bundledLanguages));
66

7-
export const fencedCodeToHtml = async (code: string, language: string): Promise<string> => {
7+
export async function fencedCodeToHtml(code: string, language: string): Promise<string> {
88
// Trim newlines to prevent rendering empty space surrounding content
99
// but preserve other whitespace that may be used for alignment.
1010
const trimmedCode = trimNewlines(code);
@@ -23,4 +23,4 @@ export const fencedCodeToHtml = async (code: string, language: string): Promise<
2323
},
2424
});
2525
return domPurify.sanitize(html);
26-
};
26+
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { marked } from "marked";
2-
import { domPurify } from "./dom-purify";
2+
import { domPurify } from "../utils/dom-purify";
33

4-
export const mdToHtml = async (md: string): Promise<string> => {
4+
export async function mdToHtml(md: string): Promise<string> {
55
/* oxlint-disable no-misleading-character-class */
66
const withoutZeroWidth = md.replace(/^[\u200B\u200C\u200D\u200E\u200F\uFEFF]/, "");
77
const unsafeMd = await marked.parseInline(withoutZeroWidth);
88
return domPurify.sanitize(unsafeMd);
9-
};
9+
}
File renamed without changes.
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
import type { DocDeclarationReference } from "@microsoft/tsdoc";
22

3-
export const resolveDeclarationReference = (ref: DocDeclarationReference) => {
3+
export interface ResolvedDeclarationReference {
4+
pkgName: string | undefined;
5+
declarationId: string;
6+
}
7+
8+
export function resolveDeclarationReference(
9+
ref: DocDeclarationReference,
10+
): ResolvedDeclarationReference {
411
const { packageName, memberReferences } = ref;
512
const declarationId = memberReferences
613
.map((ref) => ref.memberIdentifier?.identifier)
714
.filter(Boolean)
815
.join(".");
916
return { pkgName: packageName, declarationId };
10-
};
17+
}

0 commit comments

Comments
 (0)