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

@hardlydifficult/document-generator

v1.1.3

Published

Platform-agnostic document builder with chainable API.

Downloads

942

Readme

@hardlydifficult/document-generator

Platform-agnostic document builder with chainable API.

Installation

npm install @hardlydifficult/document-generator

Quick Start

import { Document, toMarkdown, toPlainText } from '@hardlydifficult/document-generator';

const document = new Document()
  .header("Weekly Report")
  .text("Summary of this week's **key highlights**.")
  .list(["Completed feature A", "Fixed bug B", "Started project C"])
  .divider()
  .link("View details", "https://example.com")
  .context("Generated on 2025-01-15");

// Output as markdown
console.log(toMarkdown(document.getBlocks()));

// Output as plain text
console.log(toPlainText(document.getBlocks()));

API

new Document()

Create a new document builder. All methods are chainable.

Chainable Methods

| Method | Description | |--------|-------------| | .header(text) | Add a header/title | | .text(content) | Add text paragraph (supports bold, italic, ~~strike~~) | | .list(items) | Add a bulleted list | | .divider() | Add a horizontal divider | | .context(text) | Add footer/context text | | .link(text, url) | Add a hyperlink | | .code(content) | Add code (auto-detects inline vs multiline) | | .image(url, alt?) | Add an image |

document.getBlocks(): Block[]

Get the internal block representation for custom processing.

Inline Markdown Support

Text blocks support standard inline markdown that gets auto-converted per platform:

new Document().text('This has **bold**, *italic*, and ~~strikethrough~~ text.');
  • Standard markdown: **bold**, *italic*, ~~strike~~
  • Slack: Converted to *bold*, _italic_, ~strike~
  • Discord: Uses standard markdown (no conversion needed)
  • Plain text: Formatting stripped

Note: Use .code() and .link() methods for code and links—not markdown syntax.

Code Blocks

The .code() method auto-detects format:

// Single line → inline code
new Document().code('const x = 1');  // → `const x = 1`

// Multiline → code block
new Document().code('const x = 1;\nconst y = 2;');
// → ```
//   const x = 1;
//   const y = 2;
//   ```

Outputters

toMarkdown(blocks): string

Convert to standard markdown format.

toPlainText(blocks): string

Convert to plain text, stripping all formatting.

Block Types

Internal block types for custom processing:

type Block =
  | { type: 'header'; text: string }
  | { type: 'text'; content: string }
  | { type: 'list'; items: string[] }
  | { type: 'divider' }
  | { type: 'context'; text: string }
  | { type: 'link'; text: string; url: string }
  | { type: 'code'; content: string; multiline: boolean }
  | { type: 'image'; url: string; alt?: string };

Integration with @hardlydifficult/chat

Documents integrate seamlessly with the chat package for Slack and Discord:

import { Document } from '@hardlydifficult/document-generator';
import { createChatClient } from '@hardlydifficult/chat';

const client = createChatClient({ type: 'slack' });
const channel = await client.connect(channelId);

const report = new Document()
  .header("Daily Metrics")
  .text("Here are today's **key numbers**:")
  .list(["Users: 1,234", "Revenue: $5,678", "Errors: 0"])
  .context("Generated automatically");

// Automatically converted to Slack Block Kit
await channel.postMessage(report);