A programmatic interface for jsdoc3 with a few features:
Asynchronous 'explain' and 'render documentation' methods (the two main jsdoc operations).
Input (source code) can supplied as a string or set of file names and/or globs.
Optional caching, dramatically speeding up future invocations with the same input.
Synopsis
To output an array of json objects, each representing a doclet, use .explain(). Pass in an array of file names and/or glob expressions. Use the cache: true flag for a faster, more efficient invocation (cached output from a prior invocation will be returned if the input has not changed).
import jsdoc from 'jsdoc-api'const data = await jsdoc.explain({ files: ['index.js', 'lib/*.js'], cache: true })console.log(data)
Typical output (truncated):
[ { comment: '/**\n' + ' * The [cache-point](https://github.com/75lb/cache-point) instance used when `cache: true` is specified on `.explain()`.\n' + ' * @type {external:cache-point}\n' + ' */', meta: { range: [ 491, 554 ], filename: 'index.js', lineno: 21, columnno: 6, path: '/Users/lloyd/Documents/jsdoc2md/jsdoc-api', code: { id: 'astnode100000027', name: 'cache', type: 'NewExpression', value: '' } }, description: 'The [cache-point](https://github.com/75lb/cache-point) instance used when `cache: true` is specified on `.explain()`.'
As an alternative to passing in file names/globs (above), you can pass in one or more source code strings.
import jsdoc from 'jsdoc-api'const data = await jsdoc.explain({ source: '/** example doclet */ \n var example = true' })console.log(data)
If you need to use a specific jsdoc version or fork, specify its path via JSDOC_PATH and jsdoc-api will use it instead of the default.
$ export JSDOC_PATH=./node_modules/.bin/jsdoc # An alternative jsdoc version you installed$ node my-jsdoc-api-script.js # Run your jsdoc-api app as usual