documentation.js

repository·master·Indexed 26 days ago

https://github.com/documentationjs/documentation

A documentation generator for modern JavaScript that infers parameters, types, and membership from JSDoc annotations. It supports ES5, ES2017, JSX, Vue, and Flow, with output options in HTML, JSON, and Markdown. The tool provides a CLI for building, linting, and serving documentation, as well as a Node.js API for integration into build systems.

Tokens
11.2K
Snippets
32
Records
66
Agent score
83%

What's inside documentation.js

  1. Use the default theme in documentationjs

    master
    The default theme is bundled automatically with the documentation package. It uses Underscore.js templates and includes highlight.js for syntax highlighting and basscss as a CSS framework. You do not need to perform any additional installation to use it; it is the standard output format for documentationjs.
  2. Understand Parser Streams

    master
    Parser streams process input content to extract JSDoc comments. The javascript stream is a specialized parser that also extracts the Abstract Syntax Tree (AST) from JavaScript source code. This AST allows documentation to infer structural information about the source code, such as variable names, to enhance the generated documentation.
  3. Write JSDoc comments for functions

    master

    documentation generates documentation from comments within your code using the JSDoc format.

    Important: JSDoc comments must begin with /** (two asterisks). Standard single-line comments (//) or block comments (/*) will be ignored by documentation.`

    /**
     * This function adds one to its input.
     * @param {number} input any number
     * @returns {number} that number, plus one.
     */
    function addOne(input) {
      return input + 1;
    }
  4. Document destructuring parameters

    master

    When using ES6 destructuring in function parameters (e.g., function({ x, y })), the parent object is unnamed in the code. To document these properties, you must explicitly name the parent object in your JSDoc and use a hierarchical naming convention (prefixing property names with the parent name).

    /**
     * This method has hierarchical params
     * @param {Object} animals different kinds of animals
     * @param {String} animals.fishes number of kinds of fish
     */
    function fishesAndFoxes({ fishes, foxes }) {
      return fishes + foxes;
    }
  5. Configure documentation.js with a YAML file

    master

    Configuration is optional, but using a documentation.yml file allows you to organize the order of top-level documentation and insert narrative Markdown sections between autogenerated API documentation. Use the --config command-line option to specify your configuration file.

    $ documentation build --config documentation.yml ...
  6. Use documentation.js as a Node library

    master

    You can integrate documentation.js into your own Node.js applications or build tools (like Gulp or Grunt integrations).

    Core Concepts

    • Entry Points: The library accepts an array of entry points. An entry point can be a filename (string) or an object containing source (the code string) and file (the filename) members.
    • Two-Step Process:
      1. Parsing: Use documentation.build() (asynchronous) or documentation.buildSync() (synchronous) to parse the source code into a documentation object.
      2. Generating Output: Use the documentation.formats object to convert the parsed documentation into specific formats like md, json, or html.
  7. Customize the default HTML theme

    master

    To customize the existing default theme, follow these steps:

    1. Copy the contents of the default_theme folder into a new folder in your project (e.g., as a separate git repository).
    2. In the new folder's index.js, replace the require('../') calls on lines 8 and 9 with require('documentation').
    3. Use the --theme CLI flag to point to your new theme folder.

    Example package.json script: "documentation build index.js -f html -o docs --theme node_modules/docjs-theme"

    "documentation build index.js -f html -o docs --theme node_modules/docjs-theme"