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

doc-to-md-rag

v1.0.1

Published

**A RAG-Optimized PDF & DOCX to Markdown Converter for Node.js**

Readme

📄 doc-to-md-rag

A RAG-Optimized PDF & DOCX to Markdown Converter for Node.js

License: MIT npm version

Most PDF parsers destroy table layouts, turning data into "word soup" that confuses LLMs. doc-to-md-rag uses a heuristic block segmentation algorithm to detect visual grids and preserve them as clean, token-efficient Markdown tables, while keeping non-tabular text as normal paragraphs.

Perfect for RAG (Retrieval-Augmented Generation) pipelines, chatbots, and data extraction.

🚀 Features

  • RAG-First Design: Output is optimized for LLM context windows (no wasted tokens on empty rows/cols).
  • Intelligent Layout Engine: Automatically distinguishes between "Text Blocks" and "Table Blocks."
  • Native Node.js: No Python dependencies, no pdfplumber binaries needed.
  • Hybrid Support: Handles both .pdf and .docx (via Mammoth) seamlessly.
  • Zero "Ghost Columns": Smart clustering prevents the "100 empty columns" bug common in other parsers.

📦 Installation

npm install doc-to-md-rag

🛠️ Usage

import { convertToMarkdown } from 'doc-to-md-rag';

(async () => {
    try {
        // Works with PDF
        console.log("Converting PDF...");
        const pdfMd = await convertToMarkdown('./financial-report.pdf');
        console.log(pdfMd);

        // Works with DOCX
        console.log("Converting DOCX...");
        const docxMd = await convertToMarkdown('./contract.docx');
        console.log(docxMd);
        
    } catch (err) {
        console.error("Conversion failed:", err);
    }
})();

📊 Output Comparison

Why does this library exist? Standard parsers flatten tables, destroying the relationship between headers and data.

Standard Parsers (Bad for RAG)

The LLM loses the grid relationship and cannot answer questions like "What was the Net Revenue in 2022?" accurately.

Revenue 2023 2022
Total $500 $400
Net $50 $40

doc-to-md-rag (Perfect for RAG)

Preserves the grid structure using Markdown, allowing the LLM to understand row/column relationships.

| Revenue | 2023 | 2022 |
| :--- | :--- | :--- |
| Total | $500 | $400 |
| Net | $50 | $40 |

🤝 Contributing

Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📄 License

Distributed under the MIT License. See LICENSE for more information.