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

@nysds/cem-plugin-examples

v1.1.0

Published

CEM analyzer plugin that extracts @example JSDoc tags into a structured examples array

Readme

cem-plugin-examples

A Custom Elements Manifest analyzer plugin that extracts @example JSDoc tags into a structured examples array on each declaration.

Unlike plugins that embed examples into the description field as HTML, this plugin writes clean structured data — making it easy for tools like MCP servers, documentation generators, and IDEs to consume examples directly.

Installation

npm install -D cem-plugin-examples

Usage

Add the plugin to your CEM analyzer config:

// custom-elements-manifest.config.mjs
import { cemExamplesPlugin } from "cem-plugin-examples";

export default {
  plugins: [
    cemExamplesPlugin(),
  ],
};

JSDoc Format

Add @example tags to your component class JSDoc. The first line is the title, followed by a fenced code block:

/**
 * A button component.
 *
 * @example Primary button
 * ```html
 * <my-button variant="primary">Click me</my-button>
 * ```
 *
 * @example Button with icon
 * ```html
 * <my-button icon="check">Confirm</my-button>
 * ```
 */
export class MyButton extends HTMLElement { }

You can also use <caption> tags (for compatibility with existing JSDoc conventions):

/**
 * @example <caption>Primary button</caption>
 * ```html
 * <my-button variant="primary">Click me</my-button>
 * ```
 */

Render HTML

Sometimes the code you want to show an author differs from the markup you want to render in a live preview (e.g. in Storybook or a reference site) — the rendered version might be wrapped in a demo container, include sibling elements, or set up surrounding state.

Add a @render tag and match it to an @example by story name (the title line, matched case-insensitively). The rendered HTML is merged onto the same example object under a render key:

/**
 * @example Primary button
 * ```html
 * <my-button variant="primary">Click me</my-button>
 * ```
 *
 * @render Primary button
 * ```html
 * <div class="demo-wrap">
 *   <my-button variant="primary">Click me</my-button>
 * </div>
 * ```
 */

If no @render shares an example's title, the example is emitted unchanged (no render key) — fully backward compatible. A @render with no matching @example is skipped (and logged in dev mode).

Output

The plugin adds an examples array to the declaration in custom-elements.json:

{
  "kind": "class",
  "name": "MyButton",
  "tagName": "my-button",
  "description": "A button component.",
  "examples": [
    {
      "title": "Primary button",
      "code": "<my-button variant=\"primary\">Click me</my-button>",
      "lang": "html"
    },
    {
      "title": "Button with icon",
      "code": "<my-button icon=\"check\">Confirm</my-button>",
      "lang": "html"
    }
  ]
}

Each example has:

| Field | Type | Description | |-------|------|-------------| | title | string | The example caption/title | | code | string | The code content (without fenced block markers) | | lang | string? | The language identifier from the fenced block (e.g., html, js) | | render | string? | HTML for live rendering, from a matching @render tag. Omitted when no @render shares the example's title |

Options

cemExamplesPlugin({
  // Name of the property to write examples to (default: "examples")
  propertyName: "examples",
});

Supported Declarations

The plugin extracts @example tags from:

  • Classes (including web component classes)
  • Class properties and methods
  • Standalone functions

License

MIT