What exactly is a doclet as defined in JSDoc documentation?

//Sample 1
/**
 * Here we have a simple function that returns a message
 * @param {String} msg The message to be returned
 * @returns {String} The message 
 */
function showMessage(msg) {
  return msg
}
//Sample 2
/**
 * This is a function that also returns a message
 * @function showMessage
 * @param {String} msg The message to be returned
 * @returns {String} The message 
 */

Looking at the examples provided above, can you determine which one qualifies as a doclet in JSDoc? Is it the comment associated directly with a function (sample 1) or the one assigned its own name showMessage for documentation purposes?

Answer №1

A doclet serves as a JSDoc entity that is accessible to plugins and templates. Many individuals interact with JSDoc annotations instead, such as:

so.js

/**
 * This serves as a JSDoc comment
 */

Showcasing the doclets:

# npx jsdoc -X so.js
[
    {
        "kind": "package",
        "longname": "package:undefined",
        "files": [
            "/workspace/dev/tmp/so.js"
        ]
    }
]

For instance:

/**
 * @return {boolean}
 */
function bar() {
  return true;
}

Doclets:

# npx jsdoc -X so.js 
[
    {
        "comment": "/**\n * @return {boolean}\n */",
        "meta": {
            "range": [
                29,
                62
            ],
            "filename": "so.js",
            "lineno": 4,
            "columnno": 0,
            "path": "/workspace/dev/tmp",
            "code": {
                "id": "astnode100000002",
                "name": "bar",
                "type": "FunctionDeclaration",
                "paramnames": []
            }
        },
        "returns": [
            {
                "type": {
                    "names": [
                        "boolean"
                    ]
                }
            }
        ],
        "name": "bar",
        "long name": "foo",
        "kind": "function",
        "scope": "global",
        "params": []
    },
    {
        "kind": "package",
        "longname": "package:undefined",
        "files": [
            "/workspace/dev/tmp/so.js"
        ]
    }
]

It is evident that JSDoc does not require you to explicitly state that bar is a function. A plethora of details can be inferred from the source code and these are captured within a doclet.

The JSDoc documentation refers to "virtual JSDoc comments" in certain sections. These correspond to isolated JSDoc blocks that are not immediately followed by JavaScript code. In fact, it's possible to generate a complete API documentation solely using virtual JSDoc comments without any tangible code.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it possible to output the value of history.go(-1) using a print function?

Currently, I'm working on enhancing a Vue application. My goal is to retrieve the value of the previously visited page using history.go(-1) and then use that value to assign certain values to a variable. This is what I have in mind: <script> ...

Error in NodeJS when trying to run ESM: "ReferenceError: exports is not defined

Having a tough time with this task. I'm attempting to execute ESM scripts on Node 14 (AWS Lambda) I am working on running this piece of code to convert 3D objects to THREE JSON. This involves using the command node -r esm fbx2three.js model.fbx. I ...

Troubleshooting: Issue with displaying PHP data on an AngularJS table using JSON through jQuery AJAX

I've been encountering an issue while trying to display data from a database on my HTML page using Angular and JSON. Despite the browser being able to read the database, it fails to show the data. Can anyone shed some light on why this might be happen ...

When combining stores, what sets Mobx.inject apart from Mobx.observer?

As I start integrating my store with mobx, a question arises in my mind. What sets apart the usage of observer(['store'],...) from inject('store')(observer(...))? Upon closer examination, it seems that inject is not reactive. So, what ...

Why is $(window).load() being executed twice?

When using $(window).load() to resize images in a thumbnail gallery and set up a slideshow, the code seems to be running twice. This can be observed by noticing that a div is being wrapped around another div twice when inspecting the HTML on page load. Af ...

Setting up the customized filename for precompiled Handlebars templates

When compiling Handlebars templates with the NPM package, is there a way to manually adjust the name/index that is generated? In my experience using Handlebars in various environments like Rails, NodeJS, and PHP, I've observed that the generated temp ...

Angular JS Form's Pristine feature is malfunctioning when attempting to reset

I implemented a login form on my website. After submitting the form, I clear it and set it to Pristine mode. However, the error message still persists. Below is the code for my form: <form name="loginForm" ng-submit="loginForm.$valid && login( ...

When using NodeJS with expressJS, remember that req.body can only retrieve one variable at a

I'm having trouble with my login and signup pages. The login page is working correctly, but the signup page is only transferring the password for some reason. App.JS: var express = require("express"); var app = express(); var bodyParser = require("bo ...

ReactJS displays a collection of items stored within its state

I encountered an issue while trying to display a list of items in my React app with the following error message: Objects are not valid as a React child (found: [object MessageEvent]). If you meant to render a collection of children, use an array instead. ...

Rotating a camera in ThreeJS for a quick orbit

I am using an orbital camera that orbits around a globe with markers for users to interact with. When a user clicks on a marker, the camera moves to that specific point. To animate this movement, I am utilizing TweenMax as shown below: TweenMax.to(curre ...

Nonlinear Scaling in D3.js Line Chart

My task is to generate a line chart where the y-axis domain ranges from 1.01 to 1000. The tick values change at the following intervals along the axis: 1.01 to 2, tick = 0.01 2 to 3, tick = 0.02 3 to 4, tick = 0.05 4 to 6, tick = 0.1 6 to 10, tick = 0.2 ...

What are the best strategies for enhancing the performance of the jQuery tag:contains() selector

My goal is to extract all elements from a webpage that contain a specific set of words. For example, if I have an array of random words: words = ["sky", "element", "dry", "smooth", "java", "running", "illness", "lake", "soothing", "cardio", "gymnastic"] ...

Using a Function as an Argument to Return an Unnamed Object

There seems to be a common trend in JavaScript code where a function is passed as a parameter, which in turn returns an anonymous object. myFunction(function() { return { foo: 'bar' }; }); What benefits or reasons are there for u ...

Deactivating Timeout Requests in Koa Server

I keep encountering a connection reset error. I strongly believe it's stemming from a lengthy REST request, causing it to timeout. { [Error: socket hang up] code: 'ECONNRESET' } Is there a method to deactivate request timeouts within Koa, ...

You will still find the information added with JQuery append() even after performing a hard refresh

After making an Ajax call using JQuery and appending the returned information to a div with div.append(), I encountered a strange issue. Despite trying multiple hard refreshes in various browsers, the appended information from the previous call remained vi ...

Is there a potential security flaw in jQuery when using $.get(code_url) to execute the returned code without relying on eval() or appending it to the DOM

As I was debugging my NodeJS application, I stumbled upon a surprising discovery: when using jQuery with a simple $.get(code_url) where code_url is a URL leading to server-side JavaScript code, the code gets executed. The expected behavior should be: $.g ...

Encountered an error: Uncaught TypeError - Unable to access property 'active' as it is undefined within React code

<script type="text/babel"> class Frame extends React.Component{ render(){ return ( <div> <h2 className="os-animation" dat ...

What is the best way to replace testcaferc.json browsers using the command line interface (CLI

Scenario: I am facing a situation where I aim to execute Testcafe in docker within a remote environment that necessitates running Testcafe through its command-line interface. I intend to utilize the .testcaferc file that I use for local testing to avoid m ...

Loading Animation with jQuery and Minimum Time Delay

Hello there, I am looking for a way to establish a minimum time duration for an onload function to ensure that a div is displayed for at least 2 seconds. Similar to setting a min-width or min-height, I want the div to be shown for a minimum of 2 seconds e ...

Retrieve the values from the second dropdown list based on the choices made in the first dropdown menu within a React application

Hi there. I am attempting to create a cascading dropdown menu using the data from api. For example, in the first dropdown, I have the following options: 1. Fruits 2. Roots 3. Flowers If I select Fruits, then Orange, Apple, and Strawberry should appear. ...