Documentation.js is a comprehensive JavaScript documentation generator that transforms JSDoc-annotated source code into human-readable documentation in multiple formats. It supports modern JavaScript features including ES5, ES2017, JSX, Vue components, and Flow type annotations, with intelligent inference of parameters, types, and code relationships to minimize manual documentation effort.
npm install -g documentation or npm install documentationdocumentationimport { build, lint, expandInputs, formats, util } from "documentation";For CommonJS:
const { build, lint, expandInputs, formats, util } = require("documentation");import { build, formats } from "documentation";
// Build documentation from source files
const comments = await build(['index.js'], {
access: ['public', 'protected'],
shallow: false
});
// Generate HTML documentation
const htmlDocs = await formats.html(comments, {
theme: 'default',
name: 'My Project',
version: '1.0.0'
});
// Generate Markdown documentation
const markdownDocs = await formats.md(comments, {});
// Generate JSON documentation
const jsonDocs = await formats.json(comments);# Generate markdown docs
documentation build index.js -f md
# Generate HTML docs with GitHub links
documentation build src/** -f html --github -o docs
# Lint JSDoc syntax
documentation lint util.js
# Update README with API docs
documentation readme index.js --section=APIDocumentation.js is built around several key components:
build, lint, expandInputs) for documentation generation and validationPrimary API for building documentation from source code with comprehensive configuration options and intelligent inference.
function build(
indexes: string[] | string,
args: BuildOptions
): Promise<Comment[]>;
interface BuildOptions {
external?: string[];
shallow?: boolean;
order?: (string | object)[];
access?: string[];
hljs?: HljsOptions;
inferPrivate?: string;
extension?: string | string[];
theme?: string;
name?: string;
version?: string;
description?: string;
homepage?: string;
favicon?: string;
github?: boolean;
documentExported?: boolean;
config?: string;
markdownToc?: boolean;
markdownTocMaxDepth?: number;
parseExtension?: string[];
requireExtension?: string[];
babel?: string;
noPackage?: boolean;
resolve?: string;
watch?: boolean;
output?: string;
format?: string;
}
interface HljsOptions {
highlightAuto?: boolean;
languages?: string[];
}Validation system for JSDoc syntax and structure with detailed error reporting.
function lint(
indexes: string[] | string,
args: LintOptions
): Promise<string>;
interface LintOptions {
external?: string[];
shallow?: boolean;
inferPrivate?: string;
extension?: string | string[];
}File dependency resolution and input expansion for comprehensive documentation coverage.
function expandInputs(
indexes: string[] | string,
config: Config
): Promise<string[]>;Multiple output format generators for different documentation needs and platforms.
interface Formats {
html(comments: Comment[], config: HtmlConfig): Promise<string | void>;
md(comments: Comment[], config: MarkdownConfig): Promise<string>;
remark(comments: Comment[], config: RemarkConfig): Promise<string>;
json(comments: Comment[]): Promise<string>;
}
interface HtmlConfig {
theme?: string;
name?: string;
version?: string;
github?: boolean;
}
interface MarkdownConfig {
markdownToc?: boolean;
documentExported?: boolean;
}
interface RemarkConfig {
markdownToc?: boolean;
documentExported?: boolean;
}Helper utilities for custom documentation processing and theme development.
interface Util {
createFormatters(getHref: (href: string) => string): Formatters;
LinkerStack: typeof LinkerStack;
}
interface Formatters {
parameter(param: Parameter, short?: boolean): string;
markdown(ast: object): string;
type(type: Type): string;
autolink(text: string): string;
parameters(section: Comment, short?: boolean): string;
}
class LinkerStack {
constructor(config: Config);
namespaceResolver(comments: Comment[], resolver: Function): LinkerStack;
link(namepath: string): string | undefined;
}Command-line interface for documentation generation, linting, and README integration.
# Build documentation
documentation build [input..] [options]
# Lint documentation
documentation lint [input..] [options]
# Update README
documentation readme [input..] [options]interface Comment {
description?: Description;
tags?: Tag[];
loc?: Location;
context?: Context;
augments?: Augment[];
implements?: Implement[];
params?: Parameter[];
properties?: Property[];
returns?: Return[];
throws?: Throw[];
examples?: Example[];
members?: Members;
path?: Path[];
namespace?: string;
name?: string;
kind?: string;
memberof?: string;
scope?: string;
access?: string;
type?: Type;
}
interface Description {
type: string;
children: DescriptionChild[];
}
interface Tag {
title: string;
description?: Description;
type?: Type;
name?: string;
}
interface Type {
type: string;
name?: string;
expression?: Type;
applications?: Type[];
elements?: Type[];
fields?: Field[];
}
interface Parameter {
title: string;
name: string;
description?: Description;
type?: Type;
default?: any;
optional?: boolean;
variable?: boolean;
}
interface Property {
title: string;
name: string;
description?: Description;
type?: Type;
optional?: boolean;
}
interface Return {
title: string;
description?: Description;
type?: Type;
}
interface Example {
description?: Description;
caption?: string;
}
interface Location {
start: Position;
end: Position;
}
interface Position {
line: number;
column: number;
}
interface Context {
sortKey: string;
file: string;
ast: object;
code: string;
loc: Location;
}