问题
I'm currently building a webshop with node.js and I wanted to include a documentation of pretty much all of my commented javascript code. I can easilly create a documentation with JSDoc and create a pretty html documentation, but that's not what I want to have.
I want to create a navigation in my website where the documentation is integrated in my spa. So I have done some research and found some npm modules like jsdoc-x which creates JSON based of the JSDoc comments, but it is rather cryptic and hard to create a proper documentation. Using jsdoc -X ./path/to/js/files > name.json creates a JSON representation of the commented code as well, but again very cryptic and not very practical.
I'm looking for something like this:
/**
* This is a function.
*
* @param {string} bar A parameter
* @returns {string} A string
*/
function foo(bar) {
// do something...
return bar;
}
/**
* This is another function.
*
* @param {string} foo A parameter
*/
function bar(foo) {
// do something...
}
should create something like this:
{
"documentation": [
{
"function-name": "foo(bar)"
"description": "This is a function.",
"params": [
{
"param": "bar",
"description": "A parameter",
"type": "string"
}
],
"returns": {
"description": "A string",
"type": "string"
}
},
{
"function-name": "bar(foo)"
"description": "This is another function.",
"params": [
{
"param": "foo",
"description": "A parameter",
"type": "string"
}
]
}
]
}
Like this I could create a link called "documentaion" which lists all function and their documentations inside my spa.
来源:https://stackoverflow.com/questions/53970559/jsdoc-output-as-json-for-spa-integration