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

alt-text-generator

v1.0.2

Published

Automatically generate HTML tags for image elements that include descriptive ALT text

Readme

alt-text-generator

About

Alt Text Generator is an npm package that automatically generates concise and descriptive ALT text for images in a given folder, leveraging OpenAI's API. The generated ALT text is written to a Markdown file in the form of HTML <img> tags.

Basic Overview:

  1. Install the package:
npm i alt-text-generator
  1. Call the function:
generateAltText(inputPath, outputPath)
  1. Use the generated HTML tags with generated ALT Text automatically included:
<img src="./images/image1.jpg" alt="A red apple on a white table.">
<img src="./images/image2.png" alt="A black cat sitting on a windowsill.">

Features

• Supports .jpg, .jpeg, and .png image formats. • Automatically generates ALT text for each image using AI. • Outputs HTML <img> tags to a specified Markdown file. • Easy to configure and use.

Installation

Install the package via npm:

npm i alt-text-generator

Setup

  1. Create a .env File The .env file is used to securely store your OpenAI API key. If the .env file doesn't exist, create one in the root directory of your project and make sure to add it to your .gitignore file if applicable.

  2. Add your OpenAI API key to the .env file as follows:

OPENAI_API_KEY=<your-openai-api-key-here>

Replace <your-openai-api-key-here> with your actual OpenAI API key.

Usage

  1. Import the Module You can import the generateAltText function using ES modules or CommonJS:

ES Modules:

import { generateAltText } from "alt-text-generator";

CommonJS:

const { generateAltText } = require("alt-text-generator");
  1. Call the Function The generateAltText function takes two arguments:

• Path to the folder containing the target image files. • Path to the output Markdown file where the generated HTML tags will be written.

Example:

import { generateAltText } from "alt-text-generator";

const inputPath = "./images"; // Path to the folder with image files
const outputPath = "./output.html"; // Path to the output file (created if it doesn't exist)

generateAltText(inputPath, outputPath)

Expected Output: The output file will contain HTML <img> tags like this:

<img src="./images/image1.jpg" alt="A red apple on a white table.">
<img src="./images/image2.png" alt="A black cat sitting on a windowsill.">

Configuration

Input Folder:

The input folder should contain the image files (.jpg, .jpeg, .png) for which you want ALT text generated.

Output File:

Specify the file path where the HTML tags should be written. If the file does not exist, it will be created.

API Reference

generateAltText(inputPath: string, outputPath: string): Promise

| Parameter | Type | Description | | --------- | ------ | -------------------------------------------------------------- | | inputPath | string | Path to the folder containing the images. | | git diff | string | Path to the Markdown file where the HTML tags will be written. |

This function scans the input folder for valid images, generates ALT text using OpenAI's API, and writes HTML tags to the output file.

Requirements

• Node.js: v14 or higher

• npm: v6 or higher

• OpenAI API Key

Example File Structure

project-root/
│
├── .env # Contains your OpenAI API key
├── images/ # Folder containing image files
│ ├── image1.jpg
│ ├── image2.png
│
├── output.html # (Optional) Output file for generated HTML tags
└── index.js # Script importing and using the package