[go: up one dir, main page]

jsdoc-api

9.3.4 • Public • Published

view on npm npm module downloads Gihub repo dependents Gihub package dependents Node.js CI js-standard-style

Upgraders, please check the release notes.

jsdoc-api

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()`.',
        type: { names: [ 'external:cache-point' ] },
        name: 'cache',
        longname: 'module:jsdoc-api~cache',
        kind: 'constant',
        scope: 'inner',
        memberof: 'module:jsdoc-api',
        params: []
    },
    // etc
    // etc
]

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)

Output:

[
  {
    comment: '/** example doclet */',
    meta: {
      range: [ 28, 42 ],
      filename: '934b1fbe2810.js',
      lineno: 2,
      columnno: 5,
      path: '/var/folders/bt/jgn73jf50vsb5gj92dk00v3r0000gn/T/jsdoc-api-W854dk',
      code: { id: 'astnode100000003', name: 'example', type: 'Literal', value: true }
    },
    description: 'example doclet',
    name: 'example',
    longname: 'example',
    kind: 'member',
    scope: 'global',
    params: []
  },
  { kind: 'package', longname: 'package:undefined', files: [ '/var/folders/bt/jgn73jf50vsb5gj92dk00v3r0000gn/T/jsdoc-api-W854dk/934b1fbe2810.js' ] }
]

Finally, use the render() method to invocate jsdoc directly, generating your documentation.

import jsdoc from 'jsdoc-api'

await jsdoc.render({ files: ['index.js', 'lib/something.js'], destination: 'jsdoc-output' })

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

See the API documentation for further details. See the example folder for code examples.


© 2015-24 Lloyd Brookes <75pound@gmail.com>.

Tested by test-runner. Documented by jsdoc-to-markdown.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
9.0.0-10next
9.3.424,086latest

Version History

VersionDownloads (Last 7 Days)Published
9.3.424,086
9.3.3784
9.3.21
9.3.18,961
9.3.00
9.2.00
9.1.00
9.0.20
9.0.10
9.0.00
9.0.0-10
8.1.113,465
8.1.0697
8.0.036,860
7.2.033,235
7.1.14,326
7.1.02,075
7.0.12,928
7.0.04
6.0.03,559
5.0.428,864
5.0.34,070
5.0.225
5.0.121
4.0.34,237
4.0.23
4.0.15
4.0.01
3.0.05,649
2.0.660
2.0.50
2.0.40
2.0.33
2.0.20
2.0.10
2.0.00
1.2.4543
1.2.32
1.2.25
1.2.11
1.2.01
1.1.00
1.0.50
1.0.40
1.0.30
1.0.20
1.0.10
1.0.01
0.4.11
0.4.02
0.3.02
0.2.24
0.2.14
0.2.04
0.1.14
0.1.04
0.0.00

Package Sidebar

Install

npm i jsdoc-api

Weekly Downloads

174,497

Version

9.3.4

License

MIT

Unpacked Size

28.2 kB

Total Files

9

Last publish

Collaborators

  • 75lb