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

build-docs

v2.2.0

Published

Library to extract inline comments out of your services

Downloads

863

Readme

build-docs

CircleCI

Library to extract inline comments out of your services

Installation

With npm:

npm install build-docs --save

With yarn:

yarn add build-docs

Usage

const buildDocs = require('build-docs');

const source = `
/*
 * Creates a user in the database
 *
 * This creates a user in the database. Here you can add a
 * full description.
 *
 * @param {string} name Name of the user
 * @secret apiKey This is a secret value that will be required
 * @throws {ValidationError} Must provide all required fields
 * @returns {Object} The created user object
 */`;

console.log(require('util').inspect(buildDocs(source, 'createUser'), { depth: null }));
// { name: 'createUser',
//   description: 'Creates a user in the database',
//   fullDescription: 'This creates a user in the database. Here you can add a full description.',
//   params:
//    [ { title: 'name',
//        description: 'Name of the user',
//        type: 'string' } ],
//   throws:
//    [ { type: 'ValidationError',
//        description: 'Must provide all required fields' } ],
//   secrets:
//    [ { key: 'apiKey',
//        description: 'This is a secret value that will be required' } ],
//   returns: { description: 'The created user object', type: 'object' } }

const doc = require('build-docs')(source, name)

  • source is a string of source code with comments to parse
  • name is the name of the action

The object returned is an object with the following properties:

  • name - the name of the action - docs
  • description - the description of the action - docs
  • fullDescription - a longer description of the action which can be multiline - docs
  • params - an array of the @param comment types - docs
  • secrets - an array of the @secret comment types - docs
  • throws - an array of the @throws comment types - docs
  • errors - an object of all the possible errors from this action - docs
  • returns - an object describing the return type - docs

const docs = require('build-docs').parseDirectory(directory)

There is also a function to make build-docs look inside a directory and parse docs out of all JS files in that directory. This uses the filename (minus the extension) for the name of the action.

  • directory is the folder

This returns an array of docs in the same format as described above.

name

The name is taken directly from the name you pass in

description

Description is written as the first line of text in your block comment

/*
 * Function description
 */

fullDescription

Full description is written as 2nd first line of text in your block comment

/*
 * Normal description
 *
 * This part becomes the full description
 * and it can be on multiple lines
 */

@param

We support the same syntax as jsdoc. We parse your format and output a valid JSON Schema for each @param.

Primitive types:

/*
 * @param {string} name Name of the user
 * @param {number} age Age of the user
 */

@secret

If your service requires secret values from your users, this is how you request and access them.

/*
 * @secret key Description of the secret
 */

@throws

We support the same syntax as jsdoc.

/*
 * @throws free form error description
 * @throws {ErrorType} free form error description
 * @throws {JustAnErrorType}
 */

errors

For the following docs:

/*
 * @throws {ErrorType} free form error description
 */

This will return an errors object like the following:

{
  ErrorType: function () {}
}

The function is a compiled lodash template: https://lodash.com/docs/4.17.4#template

@returns

We support the same syntax as jsdoc.

/*
 * @returns {string} Name of the user
 */

Credits

Dom Harrington