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

@cognipeer/to-markdown

v2.0.1

Published

A versatile utility library for converting various file formats to Markdown. Now with TypeScript support!

Readme

@cognipeer/to-markdown

npm TypeScript License

A versatile, TypeScript-first utility library for converting various file formats to Markdown.

✨ Features

  • 🎯 Multiple Format Support: Convert PDF, DOCX, HTML, Excel, CSV, and more
  • 📦 Simple API: Easy to use with Promise-based interface
  • 🔧 TypeScript First: Written in TypeScript with full type definitions
  • 🚀 Fast & Efficient: Optimized for performance with modular architecture
  • 📚 Well Documented: Comprehensive documentation with examples
  • 🎨 Customizable: Options to control conversion behavior

📦 Installation

npm install @cognipeer/to-markdown

Using other package managers:

# Yarn
yarn add @cognipeer/to-markdown

# pnpm
pnpm add @cognipeer/to-markdown

🔧 Development

Building from Source

# Install dependencies
npm install

# Build TypeScript and bundles
npm run build

# Watch mode for development
npm run dev

Scripts

  • npm run build - Build TypeScript and create bundles
  • npm run build:ts - Compile TypeScript only
  • npm run build:rollup - Create rollup bundles only
  • npm run clean - Remove dist directory
  • npm run dev - Watch mode for TypeScript compilation

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  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

📝 Changelog

Version 2.0.0 (Latest)

  • ✨ Rewritten in TypeScript with full type definitions
  • 🏗️ Modular architecture with separate converter modules
  • 📚 Comprehensive documentation with GitHub Pages
  • 💡 Added usage examples
  • 🎯 Improved error handling
  • 📦 Better package exports (ESM + CJS)

Version 1.0.1

  • Initial release with JavaScript implementation

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

👤 Author

Cognipeer

🙏 Acknowledgments

Built with these amazing libraries:

🔗 Links


Made with ❤️ by Cognipeer

🚀 Quick Start

Basic Usage

import { convertToMarkdown, saveToMarkdownFile } from "@cognipeer/to-markdown";

// Convert from file path
const markdown = await convertToMarkdown("/path/to/document.docx");
console.log(markdown);

// Convert from buffer
const buffer = fs.readFileSync("document.pdf");
const markdown = await convertToMarkdown(buffer, {
  fileName: "document.pdf",
});
console.log(markdown);

// Convert from base64 string
const base64Content = "data:application/pdf;base64,JVBERi0xLjUNCiW...";
const markdown = await convertToMarkdown(base64Content);
console.log(markdown);

// Save converted markdown to a file
await saveToMarkdownFile(markdown, "converted-document", "./output");

TypeScript Usage

import { 
  convertToMarkdown, 
  saveToMarkdownFile,
  type ConverterOptions,
  type ConverterInput 
} from "@cognipeer/to-markdown";

// Type-safe conversion
const options: ConverterOptions = {
  fileName: "document.pdf",
  forceExtension: ".pdf"
};

const input: ConverterInput = "./document.pdf";
const result: string = await convertToMarkdown(input, options);

📖 API Reference

convertToMarkdown(input, options?)

Converts various file formats to Markdown.

Parameters:

  • input: ConverterInput - File path (string), base64 data (string), or Buffer
  • options?: ConverterOptions - Optional configuration
    • fileName?: string - Name of the file (helpful for buffer inputs)
    • forceExtension?: string - Force a specific file extension for processing
    • url?: string - Original URL (used for web content like YouTube or Bing search)

Returns: Promise<string> - The converted markdown content

Example:

const markdown = await convertToMarkdown("./document.pdf", {
  forceExtension: ".pdf"
});

saveToMarkdownFile(content, fileName, outputDir?)

Saves the markdown content to a file.

Parameters:

  • content: string - The markdown content to save
  • fileName: string - Name for the output file (without .md extension)
  • outputDir?: string - Directory to save the file (defaults to "output")

Returns: Promise<string> - Path to the saved file

Example:

const filePath = await saveToMarkdownFile(markdown, "document", "./output");
console.log(`Saved to: ${filePath}`);

📚 Documentation

For comprehensive documentation, please visit our documentation site.

💡 Examples

Check out the examples/ directory for more usage examples:

Running Examples

# Using tsx (recommended for development)
npx tsx examples/basic-usage.ts

# Or build and run
npm run build
node dist/examples/basic-usage.js

🏗️ Project Structure

to-markdown/
├── src/
│   ├── converters/      # Format-specific converters
│   │   ├── pdf.ts
│   │   ├── docx.ts
│   │   ├── html.ts
│   │   └── ...
│   ├── types/           # TypeScript type definitions
│   │   └── index.ts
│   ├── utils/           # Utility functions
│   │   ├── markdown.ts
│   │   └── fileDetection.ts
│   └── index.ts         # Main entry point
├── examples/            # Usage examples
├── docs/                # GitHub Pages documentation
├── dist/                # Compiled output
└── package.json
  • Web content: Special handling for YouTube videos and Bing search results

Examples

Convert PDF to Markdown

import { convertToMarkdown } from "@cognipeer/to-markdown";
import fs from "fs";

const pdfBuffer = fs.readFileSync("document.pdf");
const markdown = await convertToMarkdown(pdfBuffer, {
  fileName: "document.pdf",
});

console.log(markdown);

Convert DOCX to Markdown

import { convertToMarkdown } from "@cognipeer/to-markdown";

const markdown = await convertToMarkdown("/path/to/document.docx");
console.log(markdown);

Convert HTML to Markdown

import { convertToMarkdown, saveToMarkdownFile } from "@cognipeer/to-markdown";
import fs from "fs";

const htmlContent = fs.readFileSync("page.html", "utf-8");
const markdown = await convertToMarkdown(htmlContent, {
  forceExtension: ".html",
});
console.log(markdown);

Convert and Save to File

import { convertToMarkdown, saveToMarkdownFile } from "@cognipeer/to-markdown";

const markdown = await convertToMarkdown("/path/to/document.pdf");
const savedPath = await saveToMarkdownFile(
  markdown,
  "converted-document",
  "./output"
);
console.log(`Saved to: ${savedPath}`);

License

MIT