JSDOC: Is it possible to link to a module property?
Asked Answered
A

2

6

I'd like know if it's possible to link from one module to another module`s property/method.

What I've tried so far but wasn't working:

/**
 * {@link module:modules/modulName#id}
 */

My modules follow this pattern:

/**
 * @module modules/modulName
 */
define(function() {

    'use strict';

    /**
     * @alias module:modules/modulName
     */
    var module = {
        /** Initialisation */
        init: function() {}
    };

    return module;

});

Is there a way to achieve what I want?

Alike answered 27/8, 2015 at 13:12 Comment(0)
C
4

Ok so from what I managed to do on my own

/**
 * @module namespace/moduleName
 */

/**
 * @name module:namespace/moduleName#propName
 * @type {Object}
 */
const propName= {}

Then in another file you can reference with:

/*
 * @see module:namespace/moduleName#propName
 */

You can use @link or even @type if you have @typedef with that name.

Tested this with PHPStorm and it works as it should. No idea for auto generated API's with JSDOC.

Chlamydospore answered 17/7, 2017 at 8:56 Comment(0)
S
1

For this, I declare the property I want to reference as @memberof its own module (yes, it is in the same module where the @link tag is).

Then, I just do: {@link module:moduleName.property|textOfTheLink}


Example:

i18n.js module

/**
 * @category Lib
 * @subcategory i18n
 * @module i18n
 */

/**
 * Memoized translate method.
 *
 * @memberof module:i18n          <----- THIS
 * @type {MemoizedFunction}
 * @function translate
 * @param {i18n.Scope} scope - The translation scope.
 * @param {i18n.TranslateOptions} [options] - Translate options.
 * @version 1.0.0
 * @since 1.0.0
 * @example
 * return <Text>{translate("home.title")}</Text>;
 */
export const translate = memoize(
  (scope, options = undefined) => i18n.t(scope, options),
  (scope, options = undefined) =>
    options ? scope + JSON.stringify(options) : scope
);

/**
 * Shorthand version of the {@link module:i18n.translate|translate} method.  <----- COMBINED WITH THIS :)
 *
 * @function t
 * @example
 * const translatedError = t(`errors.codes.${errorCode}`, {
 *   defaults: [{ message: t("errors.codes.default") }],
 * });
 */
export const t = translate;
Subject answered 6/2, 2022 at 3:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.