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

compuse

v0.0.2

Published

Library for analyzing components usage in various codebases usign any frameworks.

Downloads

5

Readme

Compuse

Compuse is a library for analyzing component usage in your codebase. It provides a unified interface to extract detailed information about how components are used, regardless of whether you're working with React, Vue, Angular, Svelte, Lit-HTML, or plain HTML.

Features

  • Framework Agnostic: Analyze component usage across multiple frameworks with a single API.
  • Detailed Analysis: Extract component names, attributes, slots, and events.
  • Code Fragments: Get the exact code fragment for each component usage.
  • Line Numbers: Pinpoint the exact location of component usage in your code.
  • Extensible: Easily create your own analyzers to support custom frameworks or specific analysis needs.

Installation

Install Compuse using your favorite package manager:

# pnpm
pnpm add compuse

# npm
npm install compuse

# yarn
yarn add compuse

Usage

The core of Compuse is the analyzeCode generator function. It takes your code and a framework-specific analyzer as input and yields detailed ComponentUsage objects.

analyzeCode(code, analyzer, options)

  • code (string): The source code to analyze.
  • analyzer (Analyzer): The framework-specific analyzer to use.
  • options (AnalyzeOptions): Optional configuration.
    • components (string[]): A list of component tags to exclusively analyze.

Example: Analyzing a React Component

import { analyzeCode, reactAnalyzer } from 'compuse';

const code = `
  function App() {
    return (
      <MyComponent
        id="my-id"
        prop={someValue}
        onClick={handleClick}
      >
        <div slot="header">Header</div>
        Default Content
      </MyComponent>
    );
  }
`;

for (const usage of analyzeCode(code, reactAnalyzer)) {
  console.log(usage);
}

This will output:

{
  "component": "MyComponent",
  "attributes": [
    { "name": "id", "value": "my-id", "computed": false },
    { "name": "prop", "value": "someValue", "computed": true }
  ],
  "events": [
    { "name": "onClick" }
  ],
  "slots": [
    { "name": "slot", "fragment": "<div slot=\"header\">Header</div>" },
    { "name": "default", "fragment": "Default Content" }
  ],
  "fragment": "<MyComponent id=\"my-id\" prop={someValue} onClick={handleClick}>\n  <div slot=\"header\">Header</div>\n  Default Content\n</MyComponent>",
  "lines": { "start": 3, "end": 10 }
}

Supported Analyzers

Compuse comes with built-in analyzers for popular frameworks:

  • angularAnalyzer
  • htmlAnalyzer
  • litHtmlAnalyzer
  • reactAnalyzer
  • svelteAnalyzer
  • vueAnalyzer

Creating a Custom Analyzer

You can create a custom analyzer by implementing the Analyzer interface. This is useful for supporting custom frameworks or extending the functionality of existing analyzers.

import type { Analyzer } from 'compuse';
import { parse } from 'fragmint';
import { customParsePlugin } from './custom-parse-plugin';

export const customAnalyzer: Analyzer = {
  name: 'customAnalyzer',
  parsePlugin: customParsePlugin, // A fragmint parse plugin

  extractName(node) {
    // Logic to extract the component name from an AST node
    return node.tag;
  },

  extractAttributes(node) {
    // Logic to extract attributes
    return node.attributes || [];
  },

  extractEvents(node) {
    // Logic to extract events
    return (node.attributes || []).filter(attr => attr.name.startsWith('on-'));
  },
  
  extractSlots(node) {
    // Logic to extract slots
    return (node.children || []).map(child => ({
      name: child.attributes?.find(attr => attr.name === 'slot')?.value || 'default',
      fragment: child.raw,
    }));
  },
};

Contributing

Contributions are welcome! Please see our CONTRIBUTING.md for more information.

License

This project is licensed under the ISC License.