Skip to content

Commit 0e31974

Browse files
committed
feat(jsdocs): allow group filter
1 parent d49593e commit 0e31974

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ The declared section will be automatically updated!
5252
### Supported Args
5353

5454
- `src`: Path to the source file. The default is `./src/index` and can be omitted.
55-
- `headingLevel`: Nested level for markdown group headings (default is `2` => `##`) - Note: Each export uses `headingLevel+1`.
55+
- `headingLevel`: Nested level for markdown group headings (default is `2` => `##`). Note: Each function uses `headingLevel+1` for title in nested levels.
56+
- `group`: Only render function exportes anotated with `@group name`. By default there is no group filter. Value can be an string or array of strings.
5657

5758
## Development
5859

src/generators/jsdocs.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@ export default defineGenerator({
1414
return {
1515
contents: renderSchema(schema, {
1616
headingLevel: Number.parseInt(args.headingLevel) || 2,
17+
group: args.group,
1718
}),
1819
};
1920
},
2021
});
2122

22-
function renderSchema(schema: Schema, opts: { headingLevel: number }) {
23+
function renderSchema(
24+
schema: Schema,
25+
opts: { headingLevel: number; group?: string | string[] },
26+
) {
2327
const sections = Object.create(null) as Record<string, [string, string[]][]>;
2428

2529
for (const [name, meta] of Object.entries(schema.properties || {})) {
@@ -41,6 +45,20 @@ function renderSchema(schema: Schema, opts: { headingLevel: number }) {
4145
continue;
4246
}
4347

48+
// Find group
49+
const group = tags.find((t) => t.tag === "@group")?.contents || "";
50+
51+
// Filter by group if specified
52+
if (
53+
opts.group &&
54+
(typeof opts.group === "string"
55+
? group !== opts.group
56+
: !opts.group.includes(group))
57+
) {
58+
continue;
59+
}
60+
61+
// Generate signature for function arguments
4462
const jsSig = `${name}(${(meta.args || [])
4563
.map((arg) => {
4664
let str = arg.name;
@@ -75,7 +93,6 @@ function renderSchema(schema: Schema, opts: { headingLevel: number }) {
7593

7694
lines.push("");
7795

78-
const group = tags.find((t) => t.tag === "@group")?.contents || "";
7996
sections[group] = sections[group] || [];
8097
sections[group].push([name, lines]);
8198
}

0 commit comments

Comments
 (0)