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

attr-auto-inject-plugin

v0.2.0

Published

Plugin for automatic HTML attribute generation

Readme

attr-auto-inject-plugin

Automatic generation of data-testid attributes for React components.

Supported Bundlers

| Bundler | Status | |---------------|--------------| | Webpack | ✅ Supported | | Rspack | ✅ Supported | | Vite | ✅ Supported |

Features

  • Fast - uses OXC parser instead of Babel for maximum performance
  • Reliable - AST-based parsing, not regular expressions
  • 🎯 Smart ID generation - automatically creates unique identifiers based on component structure
  • ⚙️ Customizable attribute - can change the attribute name (default: data-testid)

Installation

npm install -D attr-auto-inject-plugin

Usage

Webpack

Loader

module.exports = {
  module: {
    rules: [
      {
        test: /\.[jt]sx$/,
        exclude: /node_modules/,
        use: [
          {
            loader: 'attr-auto-inject-plugin/webpack-loader',
            options: {
              attributeName: 'data-testid',
            },
          },
        ],
      },
    ],
  },
};

Rspack

const { attrAutoInjectRspack } = require('attr-auto-inject-plugin');

export default {
  plugins: [
    attrAutoInjectRspack({
      attributeName: 'data-testid',
    }),
  ],
};

Vite

import { defineConfig } from 'vite'
import { attrAutoInjectVite } from 'attr-auto-inject-plugin'

export default defineConfig({
  plugins: [
    attrAutoInjectVite({
      attributeName: 'data-testid',
    }),
  ],
})

Options

attributeName

Type: string
Default: 'data-testid'

The name of the attribute that will be added to JSX elements.

// Use data-marker instead of data-testid
attrAutoInjectRspack({
  attributeName: 'data-marker',
});

// <Button /> → <Button data-marker="Button" />

How It Works

The plugin analyzes JSX code at the AST level and automatically adds data-testid attributes to every JSX element.

ID Generation

IDs are generated following the <Component>.<Tag> pattern:

// src/components/Header/Header.tsx
const Header = () => {
  return <header />;  // → data-testid="Header.header"
};

For nested components, the parent component name is used:

// src/components/Layout/index.tsx
const App = () => {
  return (
    <div>                    // → data-testid="App.div"
      <Header />             // → data-testid="App.Header"
      <main>                 // → data-testid="App.main"
        <p>Hello</p>         // → data-testid="App.p"
      </main>
      <Footer />             // → data-testid="App.Footer"
    </div>
  );
};

Render Functions

Functions starting with render are taken into account during ID generation:

// src/components/Card.tsx
const Card = () => {
  const renderIcon = () => {
    return <span className="icon" />;  // → data-testid="Card.Icon.span"
  };
  
  return <div>{renderIcon()}</div>;    // → data-testid="Card.div"
};

Duplicates

When duplicate tags exist, a counter is appended:

// src/components/Form.tsx
const Form = () => {
  return (
    <div />   // → data-testid="Form.div"
    <div />   // → data-testid="Form.div_2"
    <div />   // → data-testid="Form.div_3"
  );
};

Default Export

// src/pages/Login.tsx
export default () => {
  return <div />;  // → data-testid="default.div"
};

Ignored Tags

The following tags are skipped and do not receive an attribute:

  • Fragment
  • React.Fragment

Advantages

  • Performance - OXC parser is significantly faster than Babel
  • 📦 Fewer dependencies - no need for @babel/core or plugins
  • 🔄 Native TypeScript support - no separate plugins needed for TS/JSX
  • ⚙️ Flexibility - can customize the attribute name to your needs

License

MIT