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

discomd

v1.1.0

Published

Some useful features for Discord Markdown

Readme

discomd

Some useful features for Discord Markdown

npm GitHub Workflow Status GitHub Node

Install

npm install discomd

Usage

import { strip, toHTML, parse, formatTimestamp } from "discomd";

strip("**bold** and *italic* and ~~gone~~");
// -> "bold and italic and gone"

strip("> quoted\n[Discord](https://discord.com)");
// -> "quoted\nDiscord"

toHTML("**bold** and *italic* and ~~gone~~");
// -> "<strong>bold</strong> and <em>italic</em> and <s>gone</s>"

parse("**bold** text");
// -> [
//      { element: "bold", start: 0, end: 8, raw: "**bold**", content: "bold" },
//      { element: "text", start: 8, end: 13, raw: " text", content: " text" },
//    ]

formatTimestamp(1700000000, "R", { locale: "en-US" });
// -> e.g. "2 years ago" -- relative to now, so this drifts over time

Options

strip and toHTML take the same shape of options:

strip(text, {
  disable: [], // element names to leave untouched instead of removing, see below
});

toHTML(text, {
  disable: [], // element names to leave as literal (HTML-escaped) text instead of rendering
});

disable takes any of: "bold", "italic", "underline", "strikethrough", "spoiler", "code", "codeBlock", "blockQuote", "header", "subtext", "list", "link", "embedLink", "silent". Every element is removed/rendered by default.

strip("**bold** ||secret||", { disable: ["spoiler"] });
// -> "bold ||secret||"

toHTML("**bold** ||secret||", { disable: ["spoiler"] });
// -> "<strong>bold</strong> ||secret||"

Requirements

  • Node.js >= 22

Features

Both strip and toHTML cover the syntax described in Discord's Markdown 101 article:

  • Bold, italic, bold+italic, underline, strikethrough, spoilers
  • Inline code and fenced code blocks
  • Single-line (>) and multiline (>>>) block quotes
  • Headers (#, ##, ###) and subtext (-#)
  • List leaders (-, *, +, 1.)
  • Masked links ([title](url))
  • Backslash-escaped markdown characters (\*)

Plus Discord-specific tokens:

  • Suppressed embed links (<https://example.com>)
  • A leading @silent marker — only recognized as the first thing in the message

Mentions (<@id>, <@&id>, <@$id>, <#id>), custom emoji (<:name:id>, <a:name:id>) and timestamps (<t:unix:style>) are left as-is (untouched by strip, literal escaped text from toHTML), since their raw IDs carry no displayable information on their own.

strip

Strips all of the above, leaving plain text behind.

toHTML

Renders the same syntax to HTML: <strong>, <em>, <u>, <s>, <span class="spoiler">, <code>, <pre><code> (with a language-xxx class when a fenced code block specifies one), <blockquote>, <h1>-<h3>, <span class="subtext">, <ul>/<ol> and <a>.

All text is HTML-escaped up front (via escape-html), so the result is safe to insert into a page as-is — only the tags toHTML generates itself are ever emitted as raw markup. Masked links and suppressed embed links are only turned into <a> tags when their URL is http(s); anything else is left as literal escaped text.

Line breaks are preserved as-is (not converted to <br>, except to join lines within a single block quote) — render the result with white-space: pre-wrap, or convert newlines yourself.

parse

Tokenizes Discord Markdown without removing or rendering anything: parse(text) returns a flat, non-overlapping list of tokens ({ element, start, end, raw, content, ... }) covering the entire input — plain-text spans are tagged "text". It doesn't take a disable option; it always describes everything it recognizes.

element is a superset of the names disable accepts: it also tags "timestamp", "mention", "roleMention", "gameMention" (<@$id>), "channelMention", "emoji", "slashCommand" and "boldItalic" (for ***text***) — tokens strip/toHTML otherwise leave untouched or treat specially — so you can resolve or render them yourself, e.g. pass a "timestamp" token's epoch/style to formatTimestamp.

strip and toHTML are both built on parse: each token's content is resolved (recursively, for elements whose content can itself hold further markdown, like bold containing italic) and either kept or reverted to raw depending on disable. parse itself only ever describes the outermost construct at a given position — it doesn't recurse — consistent with the regex-based (not full CommonMark) approach.

formatTimestamp

Discord timestamps (<t:unix:style>) are intentionally not handled by strip/toHTML/parse's removal or rendering — only extracted as data by parse. Formatting them (locale, explicit style override, etc.) is its own concern:

formatTimestamp(1700000000, "F", { locale: "ja-JP" });

style (t/T/d/D/f/F/R) defaults to "f", matching Discord's own default when a message omits it. "R" renders a relative time (e.g. "3 years ago"); the rest render an absolute date/time via Intl.DateTimeFormat.

Contributing

Contributions are welcome! See CONTRIBUTING.md for details.

License

Distributed under the MIT License.