npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jsdoc-api

v9.3.1

Published

A programmatic interface for jsdoc

Downloads

632,648

Readme

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 <[email protected]>.

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