:construction: UNDER CONSTRUCTION: This document is a work in progress, however unlike most of the documents under construction, this one is actually usable enough for the moment.
[toc]
I recommend installing JSDoc from NPM.
To install the latest version of JSDoc globally (which may require sudo):
npm install -g jsdoc
To install the latest version of JSDoc locally and save it in your package’s package.json file:
npm install --save-dev jsdoc
There’s also another tool called jsdoc-to-markdown that can generate API documentation from a JavaScript file that is using JSDoc, but I’m not goin to get into that right now.
JSDoc supports two kinds of tags:
@). Each block tag mus be followed by a line break, with the exception of the last block tag in a JSDoc comment.<a>) in HTML.}), you must escape ith with a leading backslas (\). You do not need to use a line break after inline tags.Most JSDoc tags are block tags.
In the following examples, @param is a block tag, and {@link} is an inline tag.
You can use inline tags with a description (like in the first example below), or within a block tag (like in the second example below).
When you use multiple block tags in a JSDoc comment, they must be separated by line breaks.
/**
* Set the shoe's color. Use {@link Shoe#setSize} to set the shoe size.
*
* @param {string} color - The shoe's color.
*/
Shoe.prototype.setColor = function(color) { /* ... */ };
/**
* Set the shoe's color. Use {@link Shoe#setSize} to set the shoe size.
*
* @param {SHOE_COLORS} color - The shoe's color. Must be an enumerated
* value of {@link SHOE_COLORS}
*/
Shoe.prototype.setColor = function(color) { /* ... */ };
/**
* Set the color and type of the shoelaces.
*
* @param {LACE_COLORS} color - The shoelace color.
* @param {LACE_TYPES} type - The type of shoelace.
*/
Shoe.prototype.setLaceType = function(color, type) { /* ... */ };
@abstractsynonms:
@virtual
This member must be implemented (or overridden) by the inheritor.
@accessSpecifies the access level of this member (private, package-private, public, or protected).
@aliasTreat a member as if it had a different name.
@argSee @param
@argumentSee @param
@asyncIndicate that a function is asynchronous.
@augmentsSee @extends
@authorIdentify the author of an item.
@borrowsThis object uses something from another object.
@callbackDocument a callback function.
@classsynonyms:
@constructor
This function is intended to be called with the new keyword.
See also
@hideconstructor (in the @constructor context)@interface (in the @class context)@extends for class inheritance.@implements for interface implementation.@classdescUse the following text to describe the entire class.
@constsynonyms:
@constant
Document an object as a constant (const).
@constantSee @const
@constructorSee @class
@constructsThis function member will be the constructor for the previous class.
@copyrightDocuments some copyright information.
@defaultsynonyms:
@defaultvalue
==Documents the default value.==
@defaultvalueSee @default
@depricatedDocuments that something is no longer the preferred way. (When you use this, provide an alternative whenever possible)
@descsynonyms:
@description
Describe a symbol.
See also @summary
@descriptionSee @desc
@emitsSee @fires
@enumDescribe a collection of related properties. Typically, in UML, this collection would be part of an object with the enumeration stereotype.
classDiagram
class Access {
<<enumeration>>
package
private
protected
public
}
@eventDocument an event.
@exampleProvide an example of how to use a documented item.
@exceptionSee @throws
@exportsIdentify the member that is exported by a JavaScript module.
@externalsynonyms:
@host
Identifies an external class, namespace, or module.
:reminder_ribbon: TODO: Is
@externalthe proper syntax for#include,import, orrequire?
@extendssynonyms:
@augments
Indicates that a symbol inherits from, and adds to, a parent symbol.
See also
classimplements@filesynonyms:
@fileoverview,@overview
Describe a file. Typically, I just use it to say what the file’s name is.
@fileoverviewSee @file
@firessynonyms:
@emits
Describe the events this method may fire.
@funcsynonyms:
@function,@method
Describe a function or method.
See also
@param@property
@var@functionSee @func
@generatorIndicate that a function is a generator function.
See also @yields
@globalDocument a global object.
@hideconstructorIndicate that the constructor should not be displayed.
See also @constructor
@hostSee @external
@ignoreOmit a symbol from the documentation.
@implementsThis symbol implments an interface.
See also
@extends@interface@inheritdocIndicate that a symbole should inherit its parent’s documentation.
@innerDocument an inner object.
@instanceDocument an instance member.
See also @static
@interfaceThis symbol is an interface that others can implement.
See also
@class@implements@kindWhat kind of symbol is this?
:reminder_ribbon: TODO: Doesn’t UML have a defintion of “kind”?
@lendsDocument properties on an object literal as if they belong to a symbol with a given name.
@licenseIdentify the license that applies to this code.
:reminder_ribbon: TODO: List some common options.
@listensLit the events that a symbol listens for.
See also @event.
@memberSee @var
@methodSee @func
@memberofThis symbol belongs to the parent symbol.
:reminder_ribbon: TODO: Could this be related to
@namespace?
@mixesThis object mixes in all the members from another object.
@mixinDocuments a @mixin object. (More common in Ruby than JavaScript.)
@moduleDocument a JavaScript module.
@nameDocument a the name of an object.
@namespaceDocument a namespace object.
@overrideIndicates that a symbol overrides its parent.
@overviewSee @file
@packageThis symbol is menat to be package-private.
:information_source:: In Java, this symbol indicates a
packagename.
See also
@access@public@protected@private@paramsynonyms:
@arg,@argument
Dcoumetn the parameter to a function.
See also @function
@privateThis symbol is meant to be `private.
See also:
@access@package@public@protected@propSee @property
@propertyDocument a property of an object.
@protectedThis symbol is meant to be protected.
See also:
@access@package@public@private@publicThis symbol is meant to be public.
See also:
@access@package@private@protected@readonlyThis symbol is meant to be read-only.
See also: @const
@requiresThis file requires a Javascript module.
@returnSee @returns
@returnssynonyms:
@return
Document the return value of a function.
@seeRefer to some other documentation for more information.
@sinceWhen was this feature added. (Use semantic versioning!)
See also @version
@staticDocument a static member.
See also:
@instance@member@summaryA shorter version of the full description.
See also @desc
@thisWhat does the this keyword refer to here?
@throwssynonym:
@exception
Describe what errors could be thrown.
@todoDocument task to be completed.
@tutorialInsert a link to ain included tutorial file.
@typeDocument the type of an object
@typedefDocument a custom type.
@variationDistinguish different objects with the same name.
@versionDocument the version number of an item. (Use semantic versioning!)
:reminder_ribbon: TODO: Say something about semver.
See also @since
@varsynonyms:
@member
Documents a member.
See also
@func@member@instance@static@virtualSee @abstract
@yieldSee @yields
@yieldDocument the vaule yielded by a generator function.
See also:
@generator@returns{@link}synonyms:
{@linkcode},{@linkplain}
Link to another item in the documentation.
{@linkcode}See {@link}
{@linkplain}See {@link}
{@tutorial}Link to a tutorial.
See also @tutorial
Just about any project now-a-days uses what is caled semantic versioning to list what version of their project is (@version) and since when specific functions were part of a project (@since).
The quick rundown is that the numbers for the version are made of three parts.
Given a version number MAJOR.MINOR.PATCH, increment the:
MAJOR version when you make incompatible API changesMINOR version when you add functionality in a backwards compatible mannor.PATCH version when you make backwards compatible bug fixes.Additional labels for pre-release and build metadata are available as extension to the MAJOR.MINOR.PATCH format.
X.Y.Z where X, Y, and Z are non-negative integers, and MUST NOT contain leading zeros. X is the major version, Y is the minor version, and Z is the patch version. Each elements must increase numerically. (e.g. 1.9.0 → 1.10.0 → 1.11.0)0.Y.Z) is for initial development. Anything MAY cange at the time. The Public API SHOULD NOT be considered stable.x.y.Z | x > 0) MUST be incremented if only backward compatible bug fixes are introduced. A bug fix is defined as an internal change that fixes incorrect behavior.x.Y.z | x > 0) MUST be incremented if new, backwards compatible functionality is introduced to the public API. It MUST be incremented if any public API functionality is marked as deprecated. It MAY be incremented if substantial new functionality or improvements are introduced within the private code. It MAY include patch level changes. Patch version MUST be reset to 0 when minor version is incremented.X.y.z | X > 0) MUST be incremented if any backwards incompatible changes are introduced to the public API. It MAY also include minor and patch level changes. Patch and minor version MUST be reset to 0 when major version in incremented.pre-release version MAY be denoted by appending a hypen and a series of dot separated identifiers immediately following the patch version. Identifiers MUST comprise only ASCII alphanumeric and hyphen [0-9A-Za-z-]. Identifiers MUST NOT be empty. Numberic identifiers MUST NOT include leading zeros. Pre-release versions have a lower precedence than the associated normal version. A pre-release version indicates that the version is unstable and might not satisfy the intended compatibility requirements as denoted by its associated normal version. (Examples: 1.0.0-alpha, 1.0.0-alpha.1, 1.0.0-0.3.7, 1.0.0-x.7.z.92.) (You should probably keep it simple and mark it alpha.)build metadata MAY be denoted by appending a plus sing (+) and a series of dot separated identifiers immediately following the patch or pre-release version. Identifiers MUST compirse only ASCII alphanumerics and hypen [0-9A-Za-z-]. Identifiers MUST NOT be empty. Build metadata MUST be ignored when determining version precedence. Thus two versions that differ only in the build meta data, have the same precedence. (Examples: 1.0.0-alpha+001, 1.0.0+20130313144700, 1.0.0-beta+exp.sha.5114f85.)1.0.0 < 2.0.0 < 2.1.0 < 2.1.1). When major, minor, and patch are equal, a pre-release version has lower precedence than a normal version. (Example: 1.0.0-alpha < 1.0.0.) Precedence for two pre-release versions with the same major, minor, and patch version MUST be determined by comparing each dot separated identifier from left to right until a difference is found as follows: identifiers consisting of only digits are compared numerically and identifiers with letters or hyphens are compared lexically in ASCII sort order. Numeric identifiers always have lower precedence than non-numeric identifiers. A larger set of pre-release fields has a higher precedence than a smaller set, if all of the preceding identifiers are equal. Example: 1.0.0-alpha < 1.0.0-alpha.1 < 1.0.0-alpha.beta < 1.0.0-beta < 1.0.0-beta.2 < 1.0.0-beta.11 < 1.0.0-rc.1 < 1.0.0.)#Documentation #NodeJS