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

file2text

v0.2.0

Published

Extract plain text or AI-generated Markdown from documents, images, and URLs

Readme

file2text

An open-source CLI and TypeScript library for extracting text or converting local files and HTTP(S) URLs to Markdown.

NPM Dependency Publish

NPM

Installation

npm install -g file2text
file2text --help

You can also run it with npx file2text <file>.

CLI

file2text report.pdf
file2text ./document.docx -o document.txt
file2text 'https://example.com/report.pdf' -o report.txt
file2text 'file:///path/to/document.txt'
file2text scan.png --format markdown --model google/gemini-2.5-flash -o scan.md

Features

  1. 📄 Documents: Extract DOCX, XLSX, PPTX, and PDF locally; formats are detected from contents. Other inputs are read as UTF-8, including empty files.
  2. 🖼️ OCR: Recognize images locally in Traditional Chinese, Simplified Chinese, and English; required language data is managed automatically. Scanned PDFs require a multimodal model.
  3. 🤖 AI Markdown: A configured MEDIA_AI_MODEL or --model enables AI conversion by default. Failures are reported on stderr and fall back to local text. Use --format text for local extraction or --format markdown to try AI even without a configured model.
  4. 📤 Output: Print to stdout with a newline, or use --output to write unchanged text. Missing directories are created and existing files overwritten. Unrecoverable errors exit nonzero; successful fallbacks exit successfully.
  5. ⚠️ Limits: No stdin or local extraction of legacy DOC/XLS/PPT, audio, video, or other binary formats. AI sends files to the provider, may incur costs, and depends on model limits.

Quote paths containing spaces; prefix a path beginning with - with ./.

Configuration

The CLI loads .env from the current working directory. Existing environment variables take precedence. Set these variables in the environment or in .env:

| Variable | Purpose | | -------------------- | ------------------------------------------------------------------------------------ | | MEDIA_AI_MODEL | Default Markdown model in AI Gateway provider/model format; --model overrides it | | AI_GATEWAY_API_KEY | Vercel AI Gateway key for Markdown conversion; not needed for local text extraction |

🌐 Proxy: The CLI honors standard HTTP(S) proxy environment variables.

Library API

import { file2text, file2markdown, image2text, textualizeFile } from 'file2text';

const text = await file2text('./report.pdf');
const remote = await file2text(new URL('https://example.com/report.pdf'));
const ocr = await image2text(imageBuffer);
const markdown = await file2markdown(pdfBuffer, 'google/gemini-2.5-flash');
const automatic = await textualizeFile('./report.pdf');

| API | Behavior | | ----------------------------- | -------------------------------------------------------------------------------------------------------------- | | 📄 file2text, getFileMIME | Accept paths, file:/HTTP(S) URLs or Buffer values. | | 🤖 file2markdown | Accepts the same inputs and an optional AI SDK LanguageModel; remote content is fetched once per conversion. | | 🖼️ image2text | Recognizes an image Buffer. | | 🔄 textualizeFile | Reads local text files directly; otherwise tries Markdown, logs failures and falls back to local extraction. | | 🧰 Other exports | makeFileURL, FileInput and markdownPrompt. |

Set MEDIA_AI_MODEL before importing the library to use the default model; its value is captured when the module loads.

Development and publishing

pnpm install
pnpm build
pnpm test
pnpm pack --dry-run
  1. 🧪 Tests: pnpm test covers local extraction, real OCR, and CLI behavior. Cloud AI calls are mocked; HTTP tests use a local server. The publish workflow tests Node.js 22, 24, and 26.
  2. 📦 Build: Creates ESM, declarations, and the CLI; pnpm pack builds automatically. Runtime dependencies are installed with the package.
  3. 🚀 Publish: The release workflow publishes version tags when NPM_TOKEN is configured. Alternatively, run pnpm publish --access public. No API keys are stored in the repository.