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

@radically-straightforward/documentation

v1.0.4

Published

📚 Extract documentation from TypeScript source files to Markdown

Downloads

711

Readme

Radically Straightforward · Documentation

📚 Extract documentation from TypeScript source files to Markdown

Installation

$ npm install --save-dev @radically-straightforward/documentation

Usage

Document your TypeScript code with comments of the form /** ... */ containing Markdown (not JSDoc) above exported function declarations, variable declarations, class declarations, and TypeScript types alias declarations, for example:

index.mts

/**
 * Example of `FunctionDeclaration`.
 *
 * **`exampleOfParameter`:** Example of some documentation about a parameter.
 *
 * **Return:** Example of some documentation about the return value.
 */
export default async function exampleOfFunctionDeclaration(
  exampleOfParameter: string,
): Promise<string> {
  // ...
}

/**
 * Example of `VariableDeclaration`.
 */
export const exampleOfVariableDeclaration: string =
  "exampleOfVariableDeclaration";

/**
 * Example of `ClassDeclaration`.
 */
export class ExampleOfClassDeclaration {
  /**
   * Example of `ClassMethod`.
   */
  exampleOfClassMethod(): void {
    // ...
  }

  /**
   * Example of `ClassProperty`.
   */
  exampleOfClassProperty: string = "exampleOfClassProperty";
}

/**
 * Example of `TSTypeAliasDeclaration`.
 */
export type ExampleOfTSTypeAliasDeclaration = string;

// Example of last line for command.

Note: Include type annotations in function declarations, variable declarations, and class declarations. There are tools, for example, Visual Studio Code, which can display tooltips including types even when there are no type annotations because they infer the types based on the values in declarations, but this tool doesn’t do that.

In your documentation, include directives, for example:

README.md

# Example of \`@radically-straightforward/documentation\`

## Extract TypeScript Documentation

<!-- DOCUMENTATION: ./index.mts -->

## Run Command

<!-- DOCUMENTATION: $ tail -n 1 ./index.mts -->

Note: Besides pointing at TypeScript files a directive may also contain a command line. This is useful, for example, to include the command-line help explaining command-line parameters: <!-- DOCUMENTATION: $ ./example-tool --help -->.

Run this tool to extract the comments from the TypeScript files and include them in the documentation:

$ npx documentation [inputs...]

Note: If you don’t provide inputs, by default documentation runs on ./README.md.

Note: Don’t modify by hand the parts of the documentation that were generated by this tool or you would risk having your modifications overwritten the next time you run the tool.

You must rerun this tool when the TypeScript files are modified. We suggest including this as part of the build process, for example:

package.json

{
  "scripts": {
    "prepare": "... && documentation"
  }
}

Related Work

TSDoc

TSDoc is based on JSDoc tags, for example, @param, @returns, and so forth. In this tool we avoid JSDoc markup and use only Markdown, because:

  1. JSDoc is yet another markup language to learn.
  2. Sometimes JSDoc and Markdown interact unpredictably.
  3. Most of the benefit of JSDoc is in informing types, which is subsumed by TypeScript.

TypeDoc

TypeDoc, in conjunction with typedoc-plugin-markdown, does something very similar to this tool, but it relies on JSDoc tags and we found the formatting that it produces to be a bit clunky—we prefer to keep the TypeScript syntax which is well-known. Also, we added a directive to run command lines, which are helpful, for example, when documenting command-line tools.