How to document NodeJS native (V8) modules?

I developed my own NodeJS module (using NAN assistants). Now I am wondering what is the best way to document it.

Methods for exporting modules exist only in C ++ source code, however I want to export Javascript documentation.

+4
source share
3 answers

Finally, I chose a not-so-elegant solution. I created a separate JavaScript file that only has methods that are exported by my native API.

This file is as follows:

/** @namespace AwesomeLibrary
 * 
 * @description API overview
 */

AwesomeLibrary = {
  /**
   * @param {string} param Input parameter
   * @return combobulates {@link param}
   */
  combobulate: function (param) {}  
}

JsDoc JavaScript , . , .

, , () . JsDoc, .

0

EDIT: , , , :

JSDoc doclet SOMETHING, ( JSHint ):

var nativeStuff = require('some/native/stuff');

/**
 * My Cool Class
 * @class
 */
nativeStuff.MyCoolClass;

/**
 * My Cool Method
 * @function
 * @param {String} [name] The argument
 */
nativeStuff.MyCoolClass.prototype.CoolMethod;

/**
 * Some Other Value
 * @type {String}
 */
nativeStuff.someStringValue;

module.exports = nativeStuff;

IDE ( , WebStorm) - . , , ( @function @class @type), .


, , , .

, require() , :

var nativeStuff = require('some/native/stuff');

// If your module only has one thing
/**
 * My Cool Class
 * @class MyCoolClass
 */
module.exports = nativeStuff;

// If it has several things
module.exports = {
    /**
     * My cool class
     * @class
     */
    MyCoolClass: nativeStuff.MyCoolClass,

    /**
     * My Other Cool Member
     */
    OtherCoolMember: nativeStuff.OtherCoolMember
};

, , , .

, , native JS, ( ) :

var nativeStuff = require('some/native/stuff');

/**
 * My Cool Class
 */
class MyCoolClass {

    constructor() {
        this._nativeObj = new nativeStuff.MyCoolClass();
    }

    /**
     * Some Cool Method
     * @param {String} [name] My name
     */
    coolMethod(name) {
        return this._nativeObj(name);
    }
}

module.exports = MyCoolClass;

( , JS, ES6 :)

@typedef, , doclet typedef , , , typedef , .

+1

I had to create a simple documentation generator for scanning comments in Javadoc-style source code: https://github.com/aspectron/gendoc

Here is part of such documentation, which is as follows:

/**
@module crypto
**/

/**
@class Hash
Hash generator
@function Hash(algorithm)
@param algorithm {String}
Constructor. Initiaize hash generator with specified algorithm, see #getHashes
Throws exception on unknown algorithm
**/
v8pp::class_<hash_generator> hash_class(bindings.isolate(), v8pp::v8_args_ctor);
hash_class
    /**
    @function reset([algorithm])
    @param [algorithm] {String}
    @return {Hash}
    Reset hash generator to initial state optionaly changing generator algorithm.
    Throws exception on unknown algorithm.
    **/
    .set("reset", &hash_generator::reset_v8)
...
0
source

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


All Articles