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

jsdoctor

v1.0.0

Published

A smart jsdoc documentation generator

Downloads

3

Readme

JSDoctor

A smart jsdoc generator

Why should I heal my code?

Well, it's not like your code is sick or broken or anything of the sort. It's just that documenting it might be a real pain and it is something we want to waste as little time on as possible. Wouldn't it be better if we had a magical tool, that can:

  • infer data types
  • write jsdoc comments
  • update jsdoc comments
  • perform more behind the scenes jsdoc operations

JSDoctor is definitely not there yet, but the idea is to continue developing and improving it. So far it is capible of basic type inferences and basic documentation. So if you would like to write as less as possible, JSDoctor is a great solution for you even at this stage of development!

Install

Install with npm:

$ npm install --save jsdoctor

OR

$ npm install -g jsdoctor

Usage

Programmatically

const jsdoctor = require('jsdoctor');

jsdoctor('./lib/path/**/*.js').then(result => {
  console.log(result.status); // success
});

Cli

$ jsdoctor "./lib/path/**/*.js" -w

API


Programmatically

jsdoctor(path, [options])

Params:

  • path - Either a filepath or a glob
  • options (optional) - An object that may include the following properties:

| Option | Deafult | Description | | ------ | ------- | ----------- | | overrideComments | false | Whether JSDoctor should override existing comments or leave them be | | watch | false | Whether JSDoctor should launch in watch mode (persistent) |

Note: The overrideComments option is very unrecommended as you can accidentally write over existing documentation you want to keep

Returns:

JSDoctor returns a promise but the value within that promise depends on the options provided. Usually:

jsdoctor(path).then(result => {
  console.log(result.status); // Either "success" or "failure"
  if (result.status === "failure") {
    console.log(result.error); // If doctoring was unsuccessful, the result will contain an error
  }
});

If the watch option is provided:

jsdoctor(path,  {watch: true}).then(monitor => {
  console.log(monitor.files); // The monitored files
  monitor.killPatient(); // Stops files monitorig
  monitor.watchPatient(); // Start files monitoring again
});

Cli

jsdoctor <path> [options]

  • path - Either a filepath or a glob
  • options (optional) - Additional flags that change the functionality in the following ways:

| Option | Short | Description | | ------ | ------- | ----------- | | --overrideComments | -o | Whether JSDoctor should override existing comments or leave them be | | --watch | -w | Whether JSDoctor should launch in watch mode (persistent) |

Note: The overrideComments flag is very unrecommended as you can accidentally write over existing documentation you want to keep

Examples

Class

From this:

class Point {

  constructor(x, y) {
      this.coordinates = {x, y};
  }

  toString() {
    return "(1,2)";
  }
}

To this:

/**
 * A Point implementation
 */
class Point {

  /**
    * Creates a Point
    * @constructor
    * @param {*} x
    * @param {*} y
    */
  constructor(x, y) {
      this.coordinates = {x, y};
  }

  /**
   * @returns {string}
   */
  toString() {
    return "(1,2)";
  }
}

Function

From this:

function diff(a, b = 1, opposite = false) {
    if (!a) throw new Error("The first argument wasn't provided");
    if (opposite) return b - a;
    return a - b;
}

To this:

/**
 * @param {*} a
 * @param {number} b
 * @param {boolean} opposite
 * @returns {*}
 * @throws {Error} The first argument wasn't provided
 */
function diff(a, b = 1, opposite = false) {
    if (!a) throw new Error("The first argument wasn't provided");
    if (opposite) return b - a;
    return a - b;
}

Property

From this:

get X() {
    return this.coordinates.x;
}

set X(x) {
    this.coordinates.x = x;
}

To this:

/**
  * Get the value of the X property
  * @type {*}
  */
get X() {
    return this.coordinates.x;
}

/**
  * Set the value of the X property
  * @type {*}
  */
set X(x) {
    this.coordinates.x = x;
}

Bugs

Please look at the CONTRIBUTING.md Issues section and if you are certain the package has a bug or something of the sort, please file it here https://github.com/yashag/jsdoctor/issues

Contributing

All contributions are very welcome and encouraged! Please look at the CONTRIBUTING.md

TODO

There is still a lot of work, so every helping hand and suggestion is welcome! :) The following assignments are among the most important for future releases:

  • fix test failure when the result folder is empty
  • improve the watch option test (replace setTimeout)
  • replace file rewriting with file modification when inserting comments
  • Improve type infence
  • Add more options (like tags filtering)
  • Add more tests (and possibly coverage statistics)
  • Support more jsdoc tags

Credits

The following libraries had a major influence on the project and I would like to thank their contributors:

License

Copyright © 2017 Yasha Gootkin

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.