【问题标题】:How to document functions within a module using jsdoc?如何使用 jsdoc 记录模块内的函数?
【发布时间】:2017-11-05 19:52:57
【问题描述】:
/**
* Displays the list of autolab commands along with their functions.
* @module lib/help
*/
var Table = require('cli-table');
var chalk = require('chalk');
var helpjson = {
    'init'              : 'Initializes local repository and authenticates',
    'exit'              : 'Wipes off the credentials from the system',
    'git create'        : 'Creates a repository on Gitlab',
    'git delete'        : 'Deletes the specified repository from Gitlab',
    'git changeserver'  : 'To change the host of Gitlab',
    'git changelang'    : 'To change the language of the code submission',
    'git push'          : 'Adds, commits, pushes the code',
    'submit'            : 'To submit the code to JavaAutolab and fetch the results',
    'help'              : 'Print help manual'
};
module.exports = function() {
    /**
    * Displays the list of autolab commands along with their functions.
    * @function
    * @param {null}
    */
    console.log('\n' + chalk.blue('Usage:') + ' autolab [OPTIONS]');
    var table = new Table({
        head: ['Options:', ''],
        colWidths: [20,70]
    });
    for (var key in helpjson)
    table.push(
        [key,helpjson[key]]
        );
    console.log(table.toString());
};

我试过了,但是 html 页面只显示 lib/help,然后是一个空白页面。我还想使用@exports 来提及模块导出的内容。还有一种方法可以在 JSDoc 中记录对象的用途和概述。

【问题讨论】:

    标签: documentation jsdoc jsdoc3


    【解决方案1】:

    JSDoc 注释块应该在您的 function 声明之前...

        /**
        * Displays the list of autolab commands along with their functions.
        * @module lib/help
        */
        var Table = require('cli-table');
        var chalk = require('chalk');
        var helpjson = {
            'init': 'Initializes local repository and authenticates',
            'exit': 'Wipes off the credentials from the system',
            'git create': 'Creates a repository on Gitlab',
            'git delete': 'Deletes the specified repository from Gitlab',
            'git changeserver': 'To change the host of Gitlab',
            'git changelang': 'To change the language of the code submission',
            'git push': 'Adds, commits, pushes the code',
            'submit': 'To submit the code to JavaAutolab and fetch the results',
            'help': 'Print help manual'
        };
        /**
        * Displays the list of autolab commands along with their functions.
        * @function
        * @param {null}
        */
        module.exports = function () {
            console.log('\n' + chalk.blue('Usage:') + ' autolab [OPTIONS]');
            var table = new Table({
                head: ['Options:', ''],
                colWidths: [20, 70]
            });
            for (var key in helpjson)
                table.push(
                    [key, helpjson[key]]
                    );
            console.log(table.toString());
        };
    

    还有一种方法可以在 JSDoc 中记录对象的用途和概述

    @file 标签提供文件的描述。在文件开头的 JSDoc 注释中使用标记。

    通过阅读更多文档尝试熟悉JSDoc

    【讨论】:

      猜你喜欢
      • 2012-04-27
      • 2013-05-30
      • 1970-01-01
      • 2015-11-27
      • 2016-06-03
      • 2020-02-09
      • 2015-07-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多