Skip to content

Commit 23e8614

Browse files
committed
Add documentation helper methods
1 parent 12a7600 commit 23e8614

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/models/documentation.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,23 @@ export class Documentation implements SerializableNode {
44
constructor(
55
public description: string | undefined,
66
public defaultValue: unknown | undefined = undefined,
7-
public visibility: 'public' | 'private' | 'internal' = 'public',
7+
public visibility: 'public' | 'private' | 'internal' | undefined,
88
public tags: DocumentationTag[] = [],
99
) {}
1010

11+
hasTag(name: string): boolean {
12+
return this.tags.some((tag) => tag.name === name);
13+
}
14+
15+
getTagValue(name: string): string | undefined {
16+
return this.tags.find((tag) => tag.name === name)?.name;
17+
}
18+
1119
toObject(): Record<string, unknown> {
1220
return {
1321
description: this.description,
1422
defaultValue: this.defaultValue,
15-
visibility: this.visibility === 'public' ? undefined : this.visibility,
23+
visibility: this.visibility,
1624
tags: this.tags.length > 0 ? this.tags : undefined,
1725
};
1826
}

src/models/export.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,14 @@ export class ExportNode implements SerializableNode {
1111
/**
1212
* Whether the export is public.
1313
* Exports are considered public if they are not explicitly marked as private or internal.
14+
*
15+
* @param requireExplicitAnnotation Whether the export must have an explicit visibility annotation to be considered public.
1416
*/
15-
get isPublic() {
17+
isPublic(requireExplicitAnnotation = false): boolean {
18+
if (requireExplicitAnnotation) {
19+
return this.documentation?.visibility === 'public';
20+
}
21+
1622
return (
1723
this.documentation?.visibility !== 'private' && this.documentation?.visibility !== 'internal'
1824
);

0 commit comments

Comments
 (0)