CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-jsdoc-to-markdown

Generates markdown API documentation from JSDoc-annotated source code with comprehensive customization options

Overall
score

97%

Overview
Eval results
Files

programmatic-api.mddocs/

Programmatic API

Core programmatic interface for generating markdown documentation from JSDoc-annotated source code. The API is provided through a singleton instance exported as the default export.

Capabilities

Render Method

Generates markdown documentation from JSDoc-annotated source code with comprehensive customization options.

/**
 * Returns markdown documentation from jsdoc-annotated source code
 * @param {RenderOptions} [options={}] - Configuration options
 * @returns {Promise<string>} The rendered markdown documentation
 */
async function render(options = {});

Usage Examples:

import jsdoc2md from 'jsdoc-to-markdown';

// Basic file processing
const docs = await jsdoc2md.render({ files: 'lib/*.js' });

// Process source code directly
const docs = await jsdoc2md.render({
  source: `
    /**
     * Adds two numbers together.
     * @param {number} a - First number
     * @param {number} b - Second number
     * @returns {number} Sum of a and b
     */
    function add(a, b) {
      return a + b;
    }
  `
});

// Custom template and formatting
const docs = await jsdoc2md.render({
  files: 'src/*.js',
  template: '{{>main}}',
  'heading-depth': 1,
  'example-lang': 'javascript',
  separators: true
});

// Use pre-fetched template data
const templateData = await jsdoc2md.getTemplateData({ files: 'src/*.js' });
const docs = await jsdoc2md.render({ data: templateData });

Get Template Data Method

Returns the template data (jsdoc-parse output) which is fed into the output template engine.

/**
 * Returns the template data (jsdoc-parse output) which is fed into the output template
 * @param {TemplateDataOptions} [options={}] - Configuration options
 * @returns {Promise<object[]>} The parsed template data
 */
async function getTemplateData(options = {});

Usage Examples:

import jsdoc2md from 'jsdoc-to-markdown';

// Get processed template data
const templateData = await jsdoc2md.getTemplateData({
  files: ['lib/module-a.js', 'lib/module-b.js']
});

// Use with custom processing
const templateData = await jsdoc2md.getTemplateData({ files: 'src/*.js' });
// Filter or modify templateData as needed
const filteredData = templateData.filter(item => !item.ignore);
const docs = await jsdoc2md.render({ data: filteredData });

Get JSDoc Data Method

Returns raw data direct from the underlying JSDoc parser, before any processing or transformation.

/**
 * Returns raw data direct from the underlying jsdoc3
 * @param {JsdocDataOptions} options - Configuration options (required)
 * @returns {Promise<object[]>} Raw JSDoc data
 */
async function getJsdocData(options);

Usage Examples:

import jsdoc2md from 'jsdoc-to-markdown';

// Get raw JSDoc data
const rawData = await jsdoc2md.getJsdocData({
  files: 'src/**/*.js'
});

// Process with custom JSDoc configuration
const rawData = await jsdoc2md.getJsdocData({
  configure: './jsdoc.conf.json'
});

// Disable caching for development
const rawData = await jsdoc2md.getJsdocData({
  files: 'src/*.js',
  'no-cache': true
});

Clear Cache Method

Clears the internal cache used for performance optimization. Cache is stored in the system's temporary directory and is automatically managed, but this method allows manual clearing when needed.

/**
 * Clears the cache stored in the system's temporary directory
 * @returns {Promise<void>}
 */
async function clear();

Usage Examples:

import jsdoc2md from 'jsdoc-to-markdown';

// Clear cache before processing
await jsdoc2md.clear();

// Clear cache for troubleshooting
try {
  const docs = await jsdoc2md.render({ files: 'src/*.js' });
} catch (error) {
  // Clear cache and retry
  await jsdoc2md.clear();
  const docs = await jsdoc2md.render({ files: 'src/*.js' });
}

Get Namepaths Method

Returns all JSDoc namepaths found in the supplied source code, organized by identifier kind.

/**
 * Returns all jsdoc namepaths found in the supplied source code
 * @param {NamepathOptions} options - Configuration options
 * @returns {Promise<object>} Namepaths organized by kind
 */
async function getNamepaths(options);

Usage Examples:

import jsdoc2md from 'jsdoc-to-markdown';

// Get all namepaths
const namepaths = await jsdoc2md.getNamepaths({
  files: 'src/*.js'
});

/* Returns object like:
{
  "module": ["module:utils", "module:helpers"],
  "class": ["MyClass", "DataProcessor"],
  "function": ["processData", "formatOutput"],
  "constant": ["DEFAULT_CONFIG", "VERSION"],
  "member": ["MyClass.prototype.value"],
  "namespace": ["Utils"],
  "constructor": ["MyClass"],
  "mixin": ["EventMixin"],
  "event": ["data:loaded"],
  "typedef": ["DataConfig", "ProcessResult"],
  "external": ["jQuery", "lodash"]
}
*/

// Use for documentation analysis
const namepaths = await jsdoc2md.getNamepaths({ files: 'lib/*.js' });
const functionCount = namepaths.function.length;
const classCount = namepaths.class.length;
console.log(`Found ${functionCount} functions and ${classCount} classes`);

Configuration Options

RenderOptions

Complete configuration interface for the render method, extending all template data and JSDoc options.

interface RenderOptions extends TemplateDataOptions {
  /** Raw template data to use instead of parsing files */
  data?: object[];
  /** Custom handlebars template for full control over output */
  template?: string;
  /** Initial heading depth (default: 2) */
  'heading-depth'?: number;
  /** Default language for @example blocks */
  'example-lang'?: string;
  /** Installed package containing helper/partial overrides */
  plugin?: string | string[];
  /** Handlebars helper files to override defaults */
  helper?: string | string[];
  /** Handlebars partial files to override defaults */
  partial?: string | string[];
  /** Format identifier names as code (wrap in backticks) */
  'name-format'?: boolean;
  /** Disable GitHub-flavored markdown */
  'no-gfm'?: boolean;
  /** Add horizontal rule breaks between identifiers */
  separators?: boolean;
  /** Module index format: none, grouped, table, dl */
  'module-index-format'?: string;
  /** Global index format: none, grouped, table, dl */
  'global-index-format'?: string;
  /** Parameter list format: list, table */
  'param-list-format'?: string;
  /** Property list format: list, table */
  'property-list-format'?: string;
  /** Member index format: grouped, list */
  'member-index-format'?: string;
  /** Render URL links in plain text, others in monospace */
  'clever-links'?: boolean;
  /** Render all links in monospace */
  'monospace-links'?: boolean;
  /** EOL character: posix, win32 */
  EOL?: string;
}

TemplateDataOptions

Options for getting template data, identical to JSDoc data options.

interface TemplateDataOptions extends JsdocDataOptions {}

JsdocDataOptions

Core options for JSDoc data processing.

interface JsdocDataOptions {
  /** Disable caching for this invocation */
  'no-cache'?: boolean;
  /** File paths or glob patterns to process */
  files?: string | string[];
  /** Source code string to process */
  source?: string;
  /** Path to JSDoc configuration file */
  configure?: string;
}

NamepathOptions

Options for namepath extraction, identical to template data options.

interface NamepathOptions extends TemplateDataOptions {}

Error Handling

All methods are async and may throw errors. Common error scenarios include:

  • File not found: When specified files don't exist
  • Invalid JSDoc: When source code contains malformed JSDoc comments
  • Template errors: When custom templates have syntax errors
  • Configuration errors: When JSDoc configuration files are invalid
import jsdoc2md from 'jsdoc-to-markdown';

try {
  const docs = await jsdoc2md.render({ files: 'src/*.js' });
} catch (error) {
  if (error.message.includes('ENOENT')) {
    console.error('Files not found');
  } else if (error.message.includes('jsdoc')) {
    console.error('JSDoc parsing error:', error.message);
  } else {
    console.error('Unexpected error:', error);
  }
}

Install with Tessl CLI

npx tessl i tessl/npm-jsdoc-to-markdown

docs

cli.md

index.md

programmatic-api.md

tile.json