I want to use jsdoc comments from a javascript file inside an interactive component (like property definitions appearing on hover), but I can’t find a way to do that as jsdoc is primarily intended to export html files.
Is there a straightforward way to parse jsdoc comments from a file as structured data that I can then consume in my UI?
[…]as jsdoc is primarily intended to export html files.
Probably the most common use case but definitely not the only one.
I personally never use JSDoc itself to generate documentation. I use the -X option then jq to transform the parse tree.
Example: index.js
/**
* The answer to everything
* @return {number}
*/
function asnwer() {
return 42;
}
npx jsdoc -X index.js
[
{
"comment": "/**\n * The answer to everything\n * @return {number}\n */",
"meta": {
"range": [
56,
90
],
"filename": "index.js",
"lineno": 5,
"columnno": 0,
"path": "/workspaces/dev",
"code": {
"id": "astnode100000002",
"name": "asnwer",
"type": "FunctionDeclaration",
"paramnames": []
}
},
"description": "The answer to everything",
"returns": [
{
"type": {
"names": [
"number"
]
}
}
],
"name": "asnwer",
"longname": "asnwer",
"kind": "function",
"scope": "global",
"params": []
},
{
"kind": "package",
"longname": "package:undefined",
"files": [
"/workspaces/dev/index.js"
]
}
]