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

@papit/analyse

v0.0.3

Published

Reads a web component package's source and writes analyse.json, describing each custom element's tag, properties, methods, events, states, slots, parts and CSS variables, along with its full extends chain. Use it to generate docs, editor data or framework

Readme

@papit/analyse

Reads a web component package's source and writes analyse.json, describing each custom element's tag, properties, methods, events, states, slots, parts and CSS variables, along with its full extends chain. Use it to generate docs, editor data or framework wrappers from the code itself.

Logo


Type Tests NPM version


Installation

npm install @papit/analyse

Or run it without installing:

npx @papit/analyse

Usage

From inside a package, write analyse.json next to its package.json:

npx @papit/analyse

As a package script:

{
  "scripts": {
    "analyse": "npx @papit/analyse"
  }
}

From code:

import { analyseFile, analysePackage } from "@papit/analyse";

// a whole package: exported elements with the extends chain resolved
const analysis = analysePackage("packages/web/design-system/atoms/switch");
analysis.elements[0].tagName; // "pap-switch"

// one file: every class with an `extends` clause, parent left as a reference
const [core] = analyseFile("src/component.ts");
core.extends; // { className: "CustomElementInternals", import: "@papit/web-component" }

CLI flags

| Flag | Default | Description | | --- | --- | --- | | -o <file> | analyse.json | Output file, relative to the package. | | --no-reuse | off | Re-analyse every dependency instead of reusing its analyse.json. |

API

analysePackage

analysePackage(location: string, options?: { reuse?: boolean }): PackageAnalysis

Finds the entry files behind package.json exports/main (mapped to src/ the way @papit/build does). It follows re-exports to every exported custom element class and takes tag names from customElements.define. Then it resolves each parent class in turn: the same package first, then the workspace, then node_modules. The chain stops at a built-in such as HTMLElement. A parent it can't find stays a Reference.

analyseFile

analyseFile(file: string): Core[]

Analyses one source file and the stylesheets it imports. The tag name comes from HTMLElementTagNameMap or customElements.define in that file.

What is analysed

| Field | Source | | --- | --- | | properties | Public fields, and protected @property fields that have an attribute (visibility: "protected"), as the attribute is set from outside. @property({ type, attribute, reflect }) is mirrored from the engine: attribute is the key as written unless set, and reflect defaults to true whenever there is an attribute. @query and @translate fields are left out. type is as written; resolvedType is what the checker makes of an alias or indexed access (ButtonColor → "primary" \| "secondary" \| …). | | methods | Public methods with their signatures. Lifecycle callbacks, render, @bind handlers and private members are left out. | | events | dispatchEvent(new Event \| CustomEvent("name")), including inside decorator callbacks, plus @fires tags. | | states | _internals.states.add("name"). | | html | <slot name> and part="…" from html`…` templates and plain strings returned by render(), plus @slot / @csspart tags. | | css | --x: … declarations and var(--x, fallback) usages in imported .css files, plus @cssprop tags. | | extends | The parent Core, a Reference (class name + import) or { builtin }. |

Types the source doesn't spell out, such as an untyped initialiser, an alias or a CustomEvent detail, come from the TypeScript checker. It is only built when needed, once per package.

In JSDoc, only an @ at the start of a line begins a tag, so a description can mention @property mid-text.

The full shape lives in src/types.ts:

type PackageAnalysis = { name: string; version: string; elements: Core[] };
type Core = {
  tagName?: string; className: string; description?: string;
  source: { package?: string; file: string };
  properties: Property[]; methods: Method[]; events: Event[]; states: string[];
  html: { slots: Slot[]; parts: Part[] }; css: { variables: CssVariable[] };
  extends: Core | Reference | { builtin: string } | null;
};

Reuse

When a parent class lives in another package that already has an analyse.json, that file is used instead of analysing the package again:

  • In the workspace: reused only while it's newer than every file in the package's src/ and its package.json.
  • In node_modules: always reused. A package without src/ can only be read from its analyse.json.

--no-reuse (or reuse: false) re-analyses everything that has source.

License

Licensed under the @Papit License 1.0 Copyright (c) 2024 Henry Pap (@onkelhoy)

Key points

  • ✅ Free to use in commercial projects
  • ✅ Free to modify and distribute
  • ✅ Attribution required
  • ❌ Cannot resell the component itself as a standalone product

See the LICENSE file for full details.


Related