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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@asafarim/markdown-utils

v1.3.3

Published

Utility functions for markdown processing, metadata extraction, and content parsing

Readme

Package @asafarim/markdown-utils

npm version License: MIT TypeScript

A comprehensive collection of utility functions for markdown processing, metadata extraction, content parsing, and validation. Built with TypeScript for excellent developer experience and type safety.

🚀 Features

  • 📅 Date Utilities - Extract creation/update dates from markdown content
  • 📝 Content Parsing - Extract headings, paragraphs, links, images, and code blocks
  • 🔧 Path Utilities - Handle file paths, slugs, and directory operations
  • ✅ Validation - Validate markdown syntax, links, images, and tables
  • 🎯 TypeScript Support - Full type definitions included
  • 🌳 Tree Shakable - Import only what you need
  • 📦 Multiple Formats - ESM and CommonJS support

• 👉 View live demo at: @asafarim/markdown-utils Demo

📦 Installation

npm install @asafarim/markdown-utils
yarn add @asafarim/markdown-utils
pnpm add @asafarim/markdown-utils

🏁 Quick Start

Named Imports (Recommended)

import { 
  getFirstHeading, 
  getCreationDate, 
  stripMarkdown,
  validateMarkdown 
} from '@asafarim/markdown-utils';

const content = `
# My Document
Created: 2024-12-07

**Bold text** and *italic text*.
`;

// Extract heading
const title = getFirstHeading(content); // "My Document"

// Extract date
const created = getCreationDate(content); // Date object

// Get plain text
const plainText = stripMarkdown(content); // Clean text without markdown

// Validate content
const validation = validateMarkdown(content);
console.log(validation.isValid); // true

Default Import

import markdownUtils from '@asafarim/markdown-utils';

// Use grouped utilities
const title = markdownUtils.content.getFirstHeading(content);
const created = markdownUtils.date.getCreationDate(content);
const isValid = markdownUtils.validation.isValidMarkdown(content);

📚 API Reference

Date Utilities

Extract and work with dates from markdown content:

import { 
  getCreationDate, 
  getUpdateDate, 
  formatDate, 
  getTimeAgo 
} from '@asafarim/markdown-utils';

// Extract dates from various patterns
const created = getCreationDate('Date: 2024-12-07');
const updated = getUpdateDate('Updated: December 8, 2024');

// Format dates
const formatted = formatDate(new Date()); // "Dec 7, 2024"
const timeAgo = getTimeAgo(new Date(Date.now() - 86400000)); // "1 day ago"

Content Parsing

Parse and extract content from markdown:

import { 
  getFirstHeading,
  getAllHeadings,
  extractLinks,
  extractImages,
  getWordCount,
  getReadingTime
} from '@asafarim/markdown-utils';

const content = `
# Main Title
## Subtitle

Check out [my website](https://example.com) and this ![image](photo.jpg).
`;

const title = getFirstHeading(content); // "Main Title"
const headings = getAllHeadings(content); // Array of heading objects
const links = extractLinks(content); // Array of link objects
const images = extractImages(content); // Array of image objects
const wordCount = getWordCount(content); // Number of words
const readingTime = getReadingTime(content); // Estimated minutes

Path Utilities

Handle file paths and create slugs:

import { 
  getFileNameWithoutExtension,
  filenameToSlug,
  filenameToTitle,
  extractDateFromPath
} from '@asafarim/markdown-utils';

const filename = getFileNameWithoutExtension('/docs/my-file.md'); // "my-file"
const slug = filenameToSlug('My Great Article!'); // "my-great-article"
const title = filenameToTitle('my-great-article'); // "My Great Article"
const date = extractDateFromPath('2024-12-07-article.md'); // Date object

Validation

Validate markdown content and syntax:

import { 
  validateMarkdown,
  validateMarkdownLinks,
  isValidMarkdown
} from '@asafarim/markdown-utils';

const content = `# Title\n[Link](https://example.com)`;

const validation = validateMarkdown(content);
console.log(validation.isValid); // true
console.log(validation.stats); // { wordCount: 2, headingCount: 1, ... }

const linkValidation = validateMarkdownLinks(content);
console.log(linkValidation[0].isValid); // true

🎯 Use Cases

Blog/Documentation Systems

import { getFirstHeading, getCreationDate, getReadingTime } from '@asafarim/markdown-utils';

function processMarkdownPost(content: string) {
  return {
    title: getFirstHeading(content),
    publishedAt: getCreationDate(content),
    readingTime: getReadingTime(content),
    wordCount: getWordCount(content)
  };
}

Static Site Generators

import { extractDateFromPath, filenameToSlug } from '@asafarim/markdown-utils';

function processMarkdownFiles(filePaths: string[]) {
  return filePaths.map(path => ({
    slug: filenameToSlug(path),
    date: extractDateFromPath(path),
    path
  }));
}

Content Validation

import { validateMarkdown } from '@asafarim/markdown-utils';

function validateContent(content: string) {
  const result = validateMarkdown(content);
  
  if (!result.isValid) {
    console.error('Validation errors:', result.errors);
  }
  
  if (result.warnings.length > 0) {
    console.warn('Warnings:', result.warnings);
  }
  
  return result;
}

🛠️ Development

# Clone the repository
git clone https://github.com/AliSafari-IT/asafarim.git
cd asafarim/ASafariM.Clients/packages/markdown-utils

# Install dependencies
pnpm install

# Run tests
pnpm test

# Run tests with coverage
pnpm test:coverage

# Build the package
pnpm build

# Run linting
pnpm lint

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request. 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

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

🙏 Acknowledgments

📞 Support


Made with ❤️ by Ali Safari