JSDoc output as JSON for spa integration

£可爱£侵袭症+ 提交于 2021-01-29 07:23:30

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!