Configuring JSDoc with a configuration file (2024)

Table of Contents

  • Configuration file formats
  • Default configuration options
  • Configuring plugins
  • Specifying recursion depth
  • Specifying input files
  • Specifying the source type
  • Incorporating command-line options into the configuration file
  • Configuring tags and tag dictionaries
  • Configuring templates
  • Related Links

Configuration file formats

To customize JSDoc's behavior, you can provide a configuration file to JSDoc in one of the following formats:

  • A JSON file. In JSDoc 3.3.0 and later, this file may include comments.
  • A CommonJS module that exports a single configuration object. This format is supported in JSDoc

3.5.0 and later.

To run JSDoc with a configuration file, use the -c command-line option (for example, jsdoc -c /path/to/conf.json or jsdoc -c /path/to/conf.js).

The following examples show a simple configuration file that enables JSDoc's Markdown plugin. JSDoc's configuration options are explained in detail in the following sections.

{ "plugins": ["plugins/markdown"]}
'use strict';module.exports = { plugins: ['plugins/markdown']};

For a more comprehensive example of a JSON configuration file, see the file conf.json.EXAMPLE.

Default configuration options

If you do not specify a configuration file, JSDoc uses the following configuration options:

{ "plugins": [], "recurseDepth": 10, "source": { "includePattern": ".+\\.js(doc|x)?$", "excludePattern": "(^|\\/|\\\\)_" }, "sourceType": "module", "tags": { "allowUnknownTags": true, "dictionaries": ["jsdoc","closure"] }, "templates": { "cleverLinks": false, "monospaceLinks": false }}

This means:

  • No plugins are loaded (plugins).
  • If recursion is enabled with the -r command-line flag, JSDoc will search for files 10 levels deep (recurseDepth).
  • Only files ending in .js, .jsdoc, and .jsx will be processed (source.includePattern).
  • Any file starting with an underscore, or in a directory starting with an underscore, will be ignored (source.excludePattern).
  • JSDoc supports code that uses ES2015 modules (sourceType).
  • JSDoc allows you to use unrecognized tags (tags.allowUnknownTags).
  • Both standard JSDoc tags and Closure Compiler tags are enabled (tags.dictionaries).
  • Inline {@link} tags are rendered in plain text (templates.cleverLinks, templates.monospaceLinks).

These options and others are explained in the following sections.

Configuring plugins

To enable plugins, add their paths (relative to the JSDoc folder) into the plugins array.

For example, the following JSON configuration file will enable the Markdown plugin, which converts Markdown-formatted text to HTML, and the "summarize" plugin, which autogenerates a summary for each doclet:

{ "plugins": [ "plugins/markdown", "plugins/summarize" ]}

See the plugin reference for further information, and look in JSDoc's plugins directory for the plugins built into JSDoc.

You can configure the Markdown plugin by adding a markdown object to your configuration file. See Configuring the Markdown Plugin for details.

Specifying recursion depth

The recurseDepth option controls how many levels deep JSDoc will recursively search for source files and tutorials. This option is available in JSDoc 3.5.0 and later. This option is used only if you also specify the -r command-line flag, which tells JSDoc to recursively search for input files.

{ "recurseDepth": 10}

Specifying input files

The source set of options, in combination with paths given to JSDoc on the command line, determines the set of input files that JSDoc uses to generate documentation.

{ "source": { "include": [ /* array of paths to files to generate documentation for */ ], "exclude": [ /* array of paths to exclude */ ], "includePattern": ".+\\.js(doc|x)?$", "excludePattern": "(^|\\/|\\\\)_" }}
  • source.include: An optional array of paths that contain files for which JSDoc should generate documentation. The paths given to JSDoc on the command line are combined with these paths. You can use the -r command-line option to recurse into subdirectories.
  • source.exclude: An optional array of paths that JSDoc should ignore. In JSDoc 3.3.0 and later, this array may include subdirectories of the paths in source.include.
  • source.includePattern: An optional string, interpreted as a regular expression. If present, all filenames must match this regular expression to be processed by JSDoc. By default, this option is set to ".+\.js(doc|x)?$", meaning that only files with the extensions .js, .jsdoc, and .jsx will be processed.
  • source.excludePattern: An optional string, interpreted as a regular expression. If present, any file matching this regular expression will be ignored. By default, this option is set so that files beginning with an underscore (or anything under a directory beginning with an underscore) is ignored.

These options are interpreted in the following order:

  1. Start with all paths given on the command line and in source.include.
  2. For each file found in Step 1, if the regular expression source.includePattern is present, the filename must match it, or it is ignored.
  3. For each file left from Step 2, if the regular expression source.excludePattern is present, any filename matching this regular expression is ignored.
  4. For each file left from Step 3, if the file's path is in source.exclude, it is ignored.

All remaining files after these four steps are processed by JSDoc.

As an example, suppose you have the following file structure:

myProject/|- a.js|- b.js|- c.js|- _private| |- a.js|- lib/ |- a.js |- ignore.js |- d.txt

In addition, suppose your conf.json file looks like this example:

{ "source": { "include": ["myProject/a.js", "myProject/lib", "myProject/_private"], "exclude": ["myProject/lib/ignore.js"], "includePattern": ".+\\.js(doc|x)?$", "excludePattern": "(^|\\/|\\\\)_" }}

If you run jsdoc myProject/c.js -c /path/to/my/conf.json -r from the file containing the myProject folder, JSDoc will generate documentation for the following files:

  • myProject/a.js
  • myProject/c.js
  • myProject/lib/a.js

Here's why:

  1. Given source.include and the paths given on the command line, JSDoc starts off with these files:
    • myProject/c.js (from the command line)
    • myProject/a.js (from source.include)
    • myProject/lib/a.js, myProject/lib/ignore.js, myProject/lib/d.txt (from source.include and using the -r option)
    • myProject/_private/a.js (from source.include)
  2. JSDoc applies source.includePattern, leaving us with all of the above files except myProject/lib/d.txt, which does not end in .js, .jsdoc, or .jsx.
  3. JSDoc applies source.excludePattern, which removes myProject/_private/a.js.
  4. JSDoc applies source.exclude, which removes myProject/lib/ignore.js.

Specifying the source type

The sourceType option affects how JSDoc parses your JavaScript files. This option is available in JSDoc 3.5.0 and later. This option accepts the following values:

  • module (default): Use this value for most types of JavaScript files.
  • script: Use this value if JSDoc logs errors such as Delete of an unqualified identifier in strict mode when it parses your code.
{ "sourceType": "module"}

Incorporating command-line options into the configuration file

You can put many of JSDoc's command-line options into the configuration file instead of specifying them on the command line. To do this, add the long names of the relevant options into an opts section of the configuration file, with the value set to the option's value.

{ "opts": { "template": "templates/default", // same as -t templates/default "encoding": "utf8", // same as -e utf8 "destination": "./out/", // same as -d ./out/ "recurse": true, // same as -r "tutorials": "path/to/tutorials", // same as -u path/to/tutorials }}

By using the source.include and opts options, you can put almost all of the arguments to JSDoc in a configuration file, so that the command line reduces to:

jsdoc -c /path/to/conf.json

When options are specified on the command line and in the configuration file, the command line takes precedence.

The options in tags control which JSDoc tags are allowed and how each tag is interpreted.

{ "tags": { "allowUnknownTags": true, "dictionaries": ["jsdoc","closure"] }}

The tags.allowUnknownTags property affects how JSDoc handles unrecognized tags. If you set this option to false, and JSDoc finds a tag that it does not recognize (for example, @foo), JSDoc logs a warning. By default, this option is set to true. In JSDoc 3.4.1 and later, you can also set this property to an array of tag names that JSDoc should allow (for example, ["foo","bar"]).

The tags.dictionaries property controls which tags JSDoc recognizes, as well as how JSDoc interprets the tags that it recognizes. In JSDoc 3.3.0 and later, there are two built-in tag dictionaries:

By default, both dictionaries are enabled. Also, by default, the jsdoc dictionary is listed first; as a result, if the jsdoc dictionary handles a tag differently than the closure dictionary, the jsdoc version of the tag takes precedence.

If you are using JSDoc with a Closure Compiler project, and you want to avoid using tags that Closure Compiler does not recognize, change the tags.dictionaries setting to ["closure"]. You can also change this setting to ["closure","jsdoc"] if you want to allow core JSDoc tags, but you want to ensure that Closure Compiler-specific tags are interpreted as Closure Compiler would interpret them.

Configuring templates

The options in templates affect the appearance and content of generated documentation. Third-party templates may not implement all of these options. See Configuring JSDoc's Default Template for additional options that the default template supports.

{ "templates": { "cleverLinks": false, "monospaceLinks": false }}

If templates.monospaceLinks is true, all link text from the inline {@link} tag will be rendered in monospace.

If templates.cleverLinks is true, {@link asdf} will be rendered in normal font if asdf is a URL, and monospace otherwise. For example, {@link http://github.com} will render in plain text, but {@link MyNamespace.myFunction} will be in monospace.

If templates.cleverLinks is true, templates.monospaceLinks is ignored.

  • Command-line arguments to JSDoc
  • About JSDoc plugins
  • Using the Markdown plugin
Configuring JSDoc with a configuration file (2024)

FAQs

Configuring JSDoc with a configuration file? ›

To run JSDoc with a configuration file, use the -c command-line option (for example, jsdoc -c /path/to/conf. json or jsdoc -c /path/to/conf. js ). The following examples show a simple configuration file that enables JSDoc's Markdown plugin.

How to run JSDoc? ›

3 Answers
  1. Install Node.js which comes with npm.
  2. Open your a command line.
  3. Install JsDoc by typing the following command. npm install -g jsdoc.
  4. Run JsDoc / generate documentation. more info. jsdoc path/to/file.js.
  5. Configure jsdoc (Optional)
Nov 27, 2015

What is Template for in JSDoc? ›

JSDoc's default template provides several options that you can use to customize the appearance and content of generated documentation. To use these options, you must create a configuration file for JSDoc and set the appropriate options in the configuration file.

Does JSDoc work with TypeScript? ›

You can use most JSDoc type syntax and any TypeScript syntax, from the most basic like string to the most advanced, like conditional types.

What is JSDoc in Nodejs? ›

JSDoc is an open source API documentation generator for Javascript. It allows developers to document their code through comments.

How do I view a JSDoc file? ›

Press Ctrl+Shift+O for viewing all the methods and corresponding JSDoc opens up when you select a method there and hover over the method.

How do you document code in JavaScript? ›

Documenting Your JavaScript | JSDoc Crash Course - YouTube

Is JSDoc useful? ›

JSDoc 3 is an API documentation generator for JavaScript, similar to Javadoc or phpDocumentor. You add documentation comments directly to your source code, right alongside the code itself. I use JSDoc more than 4 years and found it extremely good and useful. Documentation is important to have in a project.

Do you need JSDoc for TypeScript? ›

According to Wikipedia: JSDoc is a markup language used to annotate JavaScript source code files. Using comments containing JSDoc, programmers can add documentation describing the application programming interface of the code they're creating. The TypeScript team have taken JSDoc support and run with it.

What is TypeScript language? ›

TypeScript is JavaScript with syntax for types. TypeScript is a strongly typed programming language that builds on JavaScript, giving you better tooling at any scale.

What is @param in TypeScript? ›

Params enable methods to receive a variable number of parameters. Basically, if you are using params (... variable name) in TypeScript, the argument passed to the method are changed by the compiler into an element in a temporary array and this array is then used in the receiving methods.

How do you write comments in TypeScript? ›

It is adapted for TypeScript files. Typescript comes with a lot of language annotations, which should not be duplicated in the comments.
...
To add a comment
  1. press Ctrl+Alt+C twice.
  2. or select 'Comment code' from your context menu.
  3. or insert /** above the line of code.
Mar 17, 2021

What is type alias in TypeScript? ›

In Typescript, Type aliases give a type a new name. They are similar to interfaces in that they can be used to name primitives and any other kinds that you'd have to define by hand otherwise. Aliasing doesn't truly create a new type; instead, it gives that type a new name.

How do I install NPM? ›

How to Install Node.js and NPM on Windows
  1. Step 1: Download Node.js Installer. In a web browser, navigate to https://nodejs.org/en/download/. ...
  2. Step 2: Install Node.js and NPM from Browser. Once the installer finishes downloading, launch it. ...
  3. Step 3: Verify Installation.
Oct 28, 2019

Who created JavaScript? ›

The first ever JavaScript was created by Brendan Eich at Netscape, and has since been updated to conform to ECMA-262 Edition 5 and later versions. This engine, code named SpiderMonkey, is implemented in C/C++.

How do you write a VS code document? ›

Download and install VS Code. Install and configure key VS Code extensions.
...
Writing documentation in VS Code: A handy beginner's guide
  1. issue trackers (like Jira)
  2. version control systems (like Git)
  3. plain text markup languages (like Markdown)
  4. a powerful Integrated Development Environment (IDE) (like VSCode).
Oct 3, 2021

What are JSDoc comments? ›

JSDoc comments are used for documentation lookup with Ctrl+Q in JavaScript and TypeScript, see JavaScript documentation look-up and TypeScript documentation look-up, as well as for type annotations and method return type hints in chained methods.

How many types of JavaScript are there? ›

In Javascript, there are five basic, or primitive, types of data. The five most basic types of data are strings, numbers, booleans, undefined, and null. We refer to these as primitive data types. A single variable can only store a single type of data.

How do you declare a class in JavaScript? ›

One way to define a class is using a class declaration. To declare a class, you use the class keyword with the name of the class ("Rectangle" here).

How do you write a JavaScript comment function? ›

Single line Javascript comments start with two forward slashes (//). All text after the two forward slashes until the end of a line makes up a comment, even when there are forward slashes in the commented text.

Is JSDoc dead? ›

JSDoc is not dead (far from it), people just don't frequently use automated docs generation tooling in the JS community.

Is type of object JavaScript? ›

There are 6 types of objects:
  • Object.
  • Date.
  • Array.
  • String.
  • Number.
  • Boolean.

What is Typedef in JS? ›

The @typedef tag is useful for documenting custom types, particularly if you wish to refer to them repeatedly. These types can then be used within other tags expecting a type, such as @type or @param. Use the @callback tag to document the type of callback functions.

Why is TS better than JS? ›

1. TypeScript is more reliable. In contrast to JavaScript, TypeScript code is more reliable and easier to refactor. This enables developers to evade errors and do rewrites much easier.

Which is faster TypeScript or JavaScript? ›

Situations Where TypeScript Takes the Cake

At the time of deployment, TypeScript can point out the compilation errors, thereby minimizing the errors during run-time. On the other hand, JavaScript is an interpreted language and can point out the errors only during the run-time.

Is TypeScript good for backend? ›

TypeScript doesn't seem to have a good reputation amongst backend developers. Probably because it's mostly known to be a set of declaration files to add some typing to JavaScript. Yet, a lot of logic that would require dozens of lines of Java code can be handled using just a few lines of TypeScript.

How do you pass as parameter in TypeScript? ›

Similar to JavaScript, to pass a function as a parameter in TypeScript, define a function expecting a parameter that will receive the callback function, then trigger the callback function inside the parent function.

What does () => void mean TypeScript? ›

Introduction to TypeScript void type

The void type denotes the absence of having any type at all. It is a little like the opposite of the any type. Typically, you use the void type as the return type of functions that do not return a value.

How do you use parameters in TypeScript? ›

In order to useParams you need to implement a generic for useParams. Building on my example above, I need to type the id . type QuizParams = { id: string; }; // In order to implement that, I'd apply my type to the hook when calling it. const { id } = useParams<QuizParams>();

How do you comment multiple lines in TypeScript? ›

Multi-Line comments in Typescript

This can be denoted by using /* */.

How do you write comment documentation? ›

Get Better at Writing Comments
  1. Make an appropriate use of the comments.
  2. Respect the documentation standard of your language and of your team.
  3. Write useful comments, avoid garbage comments.
  4. Be clear about the purpose of the code (and not only the behavior)
  5. Describe how to use it and explain the limits of your code.
Mar 11, 2020

What is TSX TypeScript? ›

tsx extension is used when we want to embed JSX elements inside the files while . ts is used for plain Typescript files and do not support adding JSX Elements.

What is the difference between type alias and interface? ›

“One difference is, that interfaces create a new name that is used everywhere. Type aliases don't create a new name — for instance, error messages won't use the alias name.”

How do I create alias in TypeScript? ›

How To Use Type Aliases in TypeScript
  1. Step 1 — Using String Literals. String literals allow us to use a string as a type. ...
  2. Step 2 — Using Type Alias. To implement the type alias, use the type keyword to create a new type .
Dec 17, 2020

Should I use type or interface TypeScript? ›

Interfaces are most recommended for defining new objects or methods or properties of an object where it will receive a specific component. Hence interface works better when using objects and method objects. Therefore it is our choice to choose between types or interface according to the program needs.

What is npm install command? ›

npm install downloads a package and it's dependencies. npm install can be run with or without arguments. When run without arguments, npm install downloads dependencies defined in a package. json file and generates a node_modules folder with the installed modules.

Where should I run npm install? ›

You should run it in your project root folder, or the folder above your node_modules folder as sometimes the structure can differentiate between projects. But in general: the root folder of your project, as long as it is one folder above your node_modules.

Where is npm installed? ›

npm install -g pm2 - pm2 will be installed globally. It will then typically be found in /usr/local/lib/node_modules (Use npm root -g to check where.) If you're using nvm, then your global modules may be in one of several places depending on the version of node you're using at the time.

Is JavaScript written in C? ›

The primary JavaScript implementations are written in C or C++ to offer better performances. However, others, such as the Rhino, are written in Java while other implementations are written in JavaScript. So JavaScript is based on multiple languages but not a single programming language.

Which software do you need to write JavaScript? ›

Most likely, you'll find your JavaScript editor of choice in Sublime Text, Visual Studio Code, or Brackets. But several other tools—Atom, BBEdit, Notepad++, Emacs, and Vim—all have something to recommend them. Depending on the task at hand, you might find any one of them handy to have around.

Is JavaScript a OOP language? ›

JavaScript is not a class-based object-oriented language. But it still has ways of using object oriented programming (OOP).

Is type of object JavaScript? ›

There are 6 types of objects:
  • Object.
  • Date.
  • Array.
  • String.
  • Number.
  • Boolean.

What is Typedef in JS? ›

The @typedef tag is useful for documenting custom types, particularly if you wish to refer to them repeatedly. These types can then be used within other tags expecting a type, such as @type or @param. Use the @callback tag to document the type of callback functions.

Why null is object in JavaScript? ›

The value null represents the intentional absence of any object value. It is one of JavaScript's primitive values and is treated as falsy for boolean operations.

How many types of JavaScript are there? ›

JavaScript has seven built-in types: null , undefined , boolean , number , string , object , and symbol . They can be identified by the typeof operator. Variables don't have types, but the values in them do.

Is an array an object JavaScript? ›

Arrays are a special type of objects. The typeof operator in JavaScript returns "object" for arrays. But, JavaScript arrays are best described as arrays.

Should typedef be public or private? ›

Any typedef used in the public interface of the class should be in the public section of the class. Rest should be private . Show activity on this post. If you declare as private , you will not be able to use them outside your class.

What is typedef example? ›

typedef is used to define new data type names to make a program more readable to the programmer. For example: | main() | main() { | { int money; | typedef int Pounds; money = 2; | Pounds money = 2 } | } These examples are EXACTLY the same to the compiler.

Should Typedefs be all caps? ›

#define constants should be in all CAPS. Function, typedef, and variable names, as well as struct, union, and enum tag names should be in lower case. Many macro "functions" are in all CAPS.

Top Articles
Latest Posts
Article information

Author: Foster Heidenreich CPA

Last Updated:

Views: 5598

Rating: 4.6 / 5 (56 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Foster Heidenreich CPA

Birthday: 1995-01-14

Address: 55021 Usha Garden, North Larisa, DE 19209

Phone: +6812240846623

Job: Corporate Healthcare Strategist

Hobby: Singing, Listening to music, Rafting, LARPing, Gardening, Quilting, Rappelling

Introduction: My name is Foster Heidenreich CPA, I am a delightful, quaint, glorious, quaint, faithful, enchanting, fine person who loves writing and wants to share my knowledge and understanding with you.