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 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-docai

v1.1.13

Published

A tool to generate JSDoc documentation for React components using OpenAI

Readme

React Component Documenter

A powerful Node.js tool that extracts React components from your project and generates comprehensive JSDoc documentation using OpenAI. The tool is specifically designed to handle complex projects with multiple components per file and existing documentation.

Key Features

  • File-by-file processing to maintain accurate component positions
  • Position tracking that adjusts for documentation inserts/updates
  • AI-powered documentation that analyzes component code structure
  • Handles multiple components per file correctly
  • Detects and updates existing documentation when requested
  • Concurrent processing for faster documentation generation
  • Smart batching to respect OpenAI API rate limits

Installation

  1. Clone this repository
  2. Install the required dependencies:
npm install
  1. Set up your OpenAI API key (recommended for best results):
export OPENAI_API_KEY=your-api-key-here

Usage

Run the tool on your React project:

npm run start -- /path/to/your/project

The tool will:

  1. Scan your project for React components
  2. Generate appropriate JSDoc documentation for each component
  3. Update source files with the documentation, properly maintaining component positions

Command Line Options

Options:
  --output, -o          Output directory for extracted components
                                             [default: "extracted_components"]
  --verbose, -v         Enable verbose logging      [boolean] [default: false]
  --openai-key, -k      OpenAI API Key (or set OPENAI_API_KEY environment variable)
  --openai-model, -m    OpenAI model to use for documentation generation
                                      [string] [default: "gpt-3.5-turbo"]
  --rate-limit, -r      Maximum number of OpenAI API requests per minute
                                                          [number] [default: 10]
  --dry-run, -d         Generate docstrings but don't write to files
                                                     [boolean] [default: false]
  --skip-existing, -s   Skip components with existing comments
                                                     [boolean] [default: false]
  --update-existing, -u Update existing component comments
                                                     [boolean] [default: false]
  --batch-size, -b      Number of components to process concurrently
                                                           [number] [default: 5]
  --help, -h            Show help                                   [boolean]

Advanced Usage Examples

Dry Run Mode

Preview documentation without modifying files:

npm run start -- /path/to/your/project --dry-run

Update Existing Documentation

Replace existing JSDoc comments:

npm run start -- /path/to/your/project --update-existing

Skip Components with Existing Documentation

Only document components that don't already have JSDoc comments:

npm run start -- /path/to/your/project --skip-existing

Control Batch Size

Adjust the number of components processed concurrently:

npm run start -- /path/to/your/project --batch-size 10

Limit API Requests

For stricter API limits:

npm run start -- /path/to/your/project --rate-limit 5

How It Works

  1. Component Extraction

    • Parses JavaScript/TypeScript files with Babel
    • Identifies React components (function, class, arrow function, styled)
    • Detects existing documentation blocks
    • Records exact position of each component in source files
  2. Documentation Generation

    • Groups components by file
    • Processes components in concurrent batches
    • Uses OpenAI to analyze component structure
    • Generates comprehensive JSDoc comments with prop types
  3. File Updating

    • Processes files in order, one at a time
    • For each file, sorts components by position
    • Updates components from bottom to top to maintain positions
    • Tracks position adjustments after each insert/update
    • Updates or inserts documentation as specified

Example Generated Documentation

/**
 * ProductCard Component
 * 
 * @description Displays a product with its image, title, price, and rating
 * 
 * @component FunctionComponent
 * @param {Object} props - Component properties
 * @param {Object} props.product - Product information
 * @param {string} props.product.id - Unique identifier for the product
 * @param {string} props.product.title - Product title
 * @param {number} props.product.price - Product price
 * @param {string} props.product.image - URL to product image
 * @param {number} props.product.rating - Product rating (1-5)
 * @param {Function} props.onAddToCart - Callback when Add to Cart is clicked
 * @param {boolean} [props.featured=false] - Whether to show as featured product
 * 
 * @returns {React.ReactElement} A card displaying the product information
 * 
 * @example
 * <ProductCard 
 *   product={{
 *     id: "1",
 *     title: "Smartphone",
 *     price: 699,
 *     image: "/images/smartphone.jpg",
 *     rating: 4.5
 *   }}
 *   onAddToCart={() => handleAddToCart("1")}
 *   featured={true}
 * />
 */
function ProductCard({ product, onAddToCart, featured = false }) {
  // Component implementation...
}

Dependencies

  • @babel/parser - For parsing JavaScript/TypeScript files
  • @babel/traverse - For traversing the AST to find components
  • @babel/types - For type checking in AST nodes
  • minimatch - For .gitignore pattern matching
  • openai - For AI-powered documentation generation
  • yargs - For command-line argument parsing