JSDoc reference function in object literal (CommonJS module.exports)

I am writing a CommonJS module and all my methods are defined as function definitions in the module. These methods are then defined in the object module.exports. All this is also written with es6.

However, with my annotations, the generated documentation refers only to the definition of the object and does not display the actual documentation for the methods.

// file named utils.js
const regular = require('regular');
const isEmpty = require('lodash.isempty);

/**
 * @memberof utils
 * @param {object} obj The value to check if it is an object or not
 * @returns {boolean}
 */
function isTrueObject(obj) {
    return !Array.isArray(obj) && typeof obj === 'object' && !isEmpty(obj) ;
}
/**
 * @memberof utils
 * @param {*} val
 * @returns {boolean}
 */
function isNumberLike(val) {
    return isNumber(val) || regular.number.test(val);
}

/**
 * @module utils
 */
module.exports = {
    isTrueObject,
    isNumberLike
};

If I save the property names module.exportsas is, no documents are generated, except for a blank page for utils:

empty documentation page

To get the correct documentation, I have to do the following:

// file named utils.js
const regular = require('regular');
const isEmpty = require('lodash.isempty);

/**
 * @memberof utils
 * @param {object} obj The value to check if it is an object or not
 * @returns {boolean}
 */
function isTrueObject(obj) {
    return !Array.isArray(obj) && typeof obj === 'object' && !isEmpty(obj) ;
}
/**
 * @memberof utils
 * @param {*} val
 * @returns {boolean}
 */
function isNumberLike(val) {
    return isNumber(val) || regular.number.test(val);
}

/**
 * @module utils
 */
module.exports = {
    /**
     * @function
     * @param {object} obj The value to check if it is an object or not
     * @returns {boolean}
     */
    isTrueObject,
    /**
     * @function
     * @param {*} val
     * @returns {boolean}
     */
    isNumberLike
};

, , . ?

correct documentation output

, , , :

/**
 * @module utils
 */
module.exports = {
    /** @see module:utils#isTrueObject */
    isTrueObject,
    /** @borrows isNumberLike as isNumberLike */
    isNumberLike
};

@see @borrow, :

only links

, , .

- , ?

+4
1

@module @memberof utils @static, :

// file named utils.js
/**
 * @module utils
 */
const regular = require('regular');
const isEmpty = require('lodash.isempty);

/**
 * @static
 * @param {object} obj The value to check if it is an object or not
 * @returns {boolean}
 */
function isTrueObject(obj) {
    return !Array.isArray(obj) && typeof obj === 'object' && !isEmpty(obj) ;
}
/**
 * @static
 * @param {*} val
 * @returns {boolean}
 */
function isNumberLike(val) {
    return isNumber(val) || regular.number.test(val);
}

module.exports = {
    isTrueObject,
    isNumberLike
};
0

Source: https://habr.com/ru/post/1622466/


All Articles