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

mdy-docs

v0.0.1

Published

Markdown documents with embedded data (`data` fences) and a JavaScript template layer (`{{ … }}`). A document carries its own data and renders itself.

Downloads

154

Readme

mdy docs

Markdown documents with embedded data (data fences) and a JavaScript template layer ({{ … }}). A document carries its own data and renders itself.

Files using these capabilities use the .mdy extension.

Pipeline

  1. Extract data — every ```data fence is parsed as YAML, merged into one data object, and stripped from the source. All other fences (```yaml, ```js, …) are left alone and render as normal code blocks.
  2. Compile — the remaining text becomes a single JavaScript function, so all {{ … }} share one scope.
  3. Run the function with the extracted data, producing markdown.
  4. Render the markdown to HTML with markdown-it.

Template syntax

| Syntax | Meaning | | --- | --- | | {{= expr }} | append the expression's value to the output | | {{ code }} | run statements, append nothing (loops, if, let, …) | | \{{ | a literal {{ |

  • Shared scope: a let/const in one brace is visible to every later brace.
  • Order-independent data: all data fences are collected before the template runs, so template code may reference data declared anywhere — even below it.
  • Whitespace control: a control-flow tag alone on its line leaves no blank line, so generated tables and lists stay contiguous.

Usage

import { render, renderToMarkdown, createProcessor } from 'mdy';

const html = render(documentSource);           // → HTML
const md   = renderToMarkdown(documentSource); // → generated markdown (pre-HTML)

// Custom markdown-it (e.g. a syntax highlighter for ```yaml blocks):
import MarkdownIt from 'markdown-it';
const { render: r } = createProcessor({
  md: new MarkdownIt({ highlight: (code, lang) => myHighlight(code, lang) }),
});

CLI

mdy [input] [options]

  input                 .mdy template; reads stdin if omitted or "-"
  -o, --out <file>      write output to <file> (default: stdout)
      --html            emit HTML instead of generated markdown
      --doc <index>     render document <index> of a multi-document file (default 0)
  -d, --data <k=v>      add a context value (repeatable; JSON-parsed if possible)
      --data-file <f>   merge a YAML/JSON file into the context
  -h, --help            show help
mdy report.mdy                        # → generated markdown on stdout
mdy report.mdy --html -o report.html  # → HTML file
mdy report.mdy -o report.md -d env=prod --data-file overrides.yaml
cat report.mdy | mdy - --html         # stdin → HTML on stdout
  • Output goes to stdout; pass -o to write a file (it won't overwrite the input).
  • A non-.mdy input is processed but warns on stderr.
  • Context from --data / --data-file overrides a document's data fences.

Data fences

Every ```data fence must be a YAML mapping; all fences in a document merge into one object (later keys win). To group values, nest them in YAML:

```data
report:
  title: "Invoice #42"
  owner: Grace Hopper
```

Multiple documents in one file

A file may hold several documents separated by a bare --- line (YAML-stream style). Documents are anonymous and positional — text before the first --- is document 0. Each document is a standard mdy unit (its own data fences + template), exactly as if it were a separate file.

Templates get a $ helper to address sibling documents by index:

| Call | Result | | --- | --- | | $.render(i, data) | run document i with data (overriding its own), returns markdown | | $.data(i) | document i's extracted data | | $.documents | [{ index, data }, …] for slicing / iteration | | $.count | number of documents |

Document 0 (the entry) is rendered by default; it composes the rest via $. Pass --doc <index> (or the entry argument to render/renderToMarkdown) to render a different one. This lets one document act as a per-item template applied across sibling data records — see examples/document-set.mdy:

```data
title: Team Roster
```
# {{= title }}

{{ for (const m of $.documents.slice(2)) { }}
{{= $.render(1, m.data) }}
{{ } }}

---
### {{= name }}
- Age: {{= age }}

---
```data
name: Alice
age: 30
```

Because splitting happens on --- lines before markdown parsing, use *** or ___ for a thematic break (<hr>) inside a document.

See examples/ for runnable documents and test/mdy.test.js for behavior.

Security

Template code runs via new Function with full runtime access. Only process trusted documents, or sandbox with node:vm / isolated-vm.

Test

npm test