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

@structured-types/api-readme

v3.46.12

Published

API documentation extractor for Readme.md files

Downloads

9

Readme

Table of contents

Overview

Markdown documentation generator/enhancer for javascript, typescript and react typescript projects. Can be used to generate API sections in your README.md files.

Installation

yarn add @structured-types/api-readme --dev

Markdown

API docs section

In your README.md (or another markdown file) file, you will insert a <api-readme /> tag to generate the API section:

<api-readme />

Table of contents

In your README.md (or another markdown file) file, you can insert a # Table of contents header and it will be automatically filled with an extracted table of contents

Configuration

The configuration file options are documented in @structured-types/api-docs DocumentOptions

You can configure api-readme either directly in your markdown file with inline configuration or with an external file.

Inline configuration

  • files: a comma-separated list of the files to include in the documentation
<api-readme files="./src/index.ts"/>
<api-readme id="my-section"/>
  • extract: a comma-separated list of API names to extract. By default, all the exports will be documented.
<api-readme extract="parse, ParseOptions" files="./src/index.ts"/>
  • visible: a comma-separated list of the properties to be visible. By default, all the extracted properties will be visible.
<api-readme visible="ParseOptions" files="./src/index.ts"/>
  • collapsed: a comma-separated list of type names, that should not be expanded. For example, some internal React objects can be kept just as a string and will not be detailed in the documentation, instead of listing their internal properties.
<api-readme collapsed="React.ReactNode"/>
  • extensions: a comma-separated list of plugins (or extensions). For example, for a react library, you can specify to include only react components, but not any additional types or utilities.
<api-readme extensions="react"/>
  • sections: a comma-separated list of the sections to generate props | description | examples | title | location | all. By default, all sections are generated.
<api-readme sections="description,props"/>
  • columns: a comma-separated list of the columns in the property tables name | type | parents | value | description | all. By default, all columns will be visible.
<api-readme columns="name,type,value,description"/>
  • collectHelpers: boolean, to specify whether to document also helper props (parents, inherited, etc) or just the main extracted exports. By default, the helper props will be excluded from your documentation.
<api-readme files="./src/index.ts" collectHelpers=true/>
  • skipInherited: boolean, to specify whether to skip properties that are "inherited", or "composed". For example, type OwnProps = { x: number } & React.LineProps will only output the x property and skip the inherited React library properties.
<api-readme files="./src/index.ts" skipInherited=true/>
  • maxDepth: number, how deep to parse child props. By default, this is set to 6.
<api-readme files="./src/index.ts" maxDepth=10/>

Configuration file

The configuration file options are documented in @structured-types/api-docs

Multiple elements

You can have multiple elements configured within the same configuration file.

For example, you have two components to document LineChart and RadarChart:

You can custom specify the element ids in README.md

<api-readme id="linechart">

...

<api-readme id="radarchart">

In your configuration file, you can specify distinct options for each element. The per-element options will be merged with the global options.

Javascript

module.exports = {
  sections: ['props'],
  elements: {
    linechart: {
      files: ['./src/charts/line/Chart.tsx'],
      visible: ['LineChart'],
    },
    radarchart: {
      files: ['./src/charts/radar/Chart.tsx'],
      visible: ['RadarChart'],

    }
  }
};

JSON

module.exports = {
  "sections": ["props"],
  "elements": {
    "linechart": {
      "files": ["./src/charts/line/Chart.tsx"],
      "visible": ["LineChart"]
    },
    "radarchart": {
      "files": ["./src/charts/radar/Chart.tsx"],
      "visible": ["RadarChart"]
    }
  }
};

YAML:

sections:
  - props
elements:
  linechart:
    files:
      - ./src/charts/line/Chart.tsx
    visible:
      - LineChart
  radarchart:
    files:
      - ./src/charts/radar/Chart.tsx
    visible:
      - RadarChart

Launch

You can launch directly from the command-line ie yarn run api-readme or from your package.json file by adding a script to launch the command line documentation tool.

...
  "scripts": {
    "docs": "api-readme",
    ...
  },
...

Command-line options

  • -t or --toc: boolean (default: true). Whether to generate a table of contents in your markdown file. You will need to create the section title such as # Table of contents and api-readme will generate the content within this section.
yarn(npm) run api-readme -t=false
  • -f or --file: string (default: MARKDOWN.md). The name of the markdown file to be processed. Make sure you have inserted a <api-readme /> tag within this file.
yarn(npm) run api-readme -f=./src/test.md
yarn(npm) run api-readme -f=./src/test.md
  • -l or --log: boolean (default: true). Display/or not the running logs.
yarn(npm) run api-readme -l=false