Skip to content

How to document a CommonJS module (exports)

Lloyd Brookes edited this page Oct 13, 2016 · 3 revisions

1. Say your module exports variable, class or function identifiers:

/**
 * @module example
 */

/**
* @type {number}
*/
var one = 1

/**
 * A method
 */
function two () {}

exports.one = one
exports.two = two

2. As the two inner declarations have documentation, they are shown in the output (not the exports expressions, as they are not documented):

example

example~one : number

Kind: inner property of example

example~two()

A method

Kind: inner method of example

3. To correctly represent those inner declarations as the exported values, we need to set @alias tags:

/**
 * @module example
 */

/**
* @type {number}
* @alias module:example.one
*/
var one = 1

/**
 * @type {number}
 * @alias module:example.two
 */
var two = 2

exports.one = one
exports.two = two

4. Using the @static tag has the exact same effect, and looks cleaner:

/**
 * @module example
 */

/**
* @type {number}
* @static
*/
var one = 1

/**
 * @type {number}
 * @static
 */
var two = 2

exports.one = one
exports.two = two

5. Now the output looks more realistic:

example

example.one : number

Kind: static property of example

example.two : number

Kind: static property of example

Clone this wiki locally