-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
toc.ts
55 lines (51 loc) · 1.77 KB
/
toc.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* eslint-disable @typescript-eslint/no-unused-vars */
import type {
ApiItem,
ApiModel,
ApiPackage
} from '@microsoft/api-extractor-model'
import { ApiItemKind } from '@microsoft/api-extractor-model'
import { getSafePathFromDisplayName } from '../utils'
import { GenerateStyle } from '../config'
/**
* Resolve the markdown content reference
*
* @remarks
* This reference resolver is used by the {@link tocProcessor | processor} to generate a reference specifically for API docs of markdown content with TOC.
*
* @param style - generate style, See the {@link GenerateStyle}
* @param item - a {@link https://rushstack.io/pages/api/api-extractor-model.apiitem/ | item}
* @param model - a {@link https://rushstack.io/pages/api/api-extractor-model.apimodel/ | model}
* @param pkg - a {@link https://rushstack.io/pages/api/api-extractor-model.apipackage/ | package}
* @param customTags - TSDoc custom tags. This parameter is set to an array of custom tag names defined in `--tsdoc-config`.
*
* @returns resolved the reference string
*
* @public
*/
export function resolve(
style: GenerateStyle,
item: ApiItem,
model: ApiModel,
pkg: ApiPackage,
customTags?: string[] // eslint-disable-line @typescript-eslint/no-unused-vars
): string {
let baseName = ''
for (const hierarchyItem of item.getHierarchy()) {
const qualifiedName = getSafePathFromDisplayName(hierarchyItem.displayName)
switch (hierarchyItem.kind) {
case ApiItemKind.Enum:
case ApiItemKind.Function:
case ApiItemKind.Variable:
case ApiItemKind.TypeAlias:
case ApiItemKind.Class:
case ApiItemKind.Interface:
baseName = `#${qualifiedName}`
break
default:
break
}
}
return baseName
}
/* eslint-enable @typescript-eslint/no-unused-vars */