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

@nelsondev/component

v1.1.21

Published

Ultra-lightweight web component library with a clean API for building reusable components.

Readme

@nelsondev/component

Lightweight web component library with a clean API for building reusable custom elements. Only 6KB minified.

Installation

npm install @nelsondev/component

Or use it directly in browser

<script src="https://unpkg.com/@nelsondev/component/dist/tron-component.min.js"></script>

Hello World

import { defineComponent } from '@nelsondev/component';

defineComponent('hello-world', (context) => {
    const props = context.defineProps(['name']);
    context.defineTemplate(`<h1>Hello, ${props.name}!</h1>`);
});
<hello-world name="nelsontron"></hello-world>

API Reference

defineComponent(tagName, definition)

Register a component.

Parameters:

  • tagName (string) - Custom element name (must contain hyphen)
  • definition (function) - Component definition receiving context object

element

Reference to the component's DOM element.


defineSlots(names)

Define content projection slots.

Parameters:

  • names (array) - Array of slot names (defaults to ['default'])

defineProps(propsList)

Define component properties with automatic type conversion.

Parameters:

  • propList (array) - Array of property definitions

defineStyle()

Get component's CSS classes.


defineEvent(handler)

Create event handler for templates.

Parameters:

  • handler (function) - Event handler function

exportEvent(name, handler)

Expose method on component instance.

Parameters:

  • name (string) - Method name
  • handler (function) - Handler function

onMounted(callback)

Register mounted lifecycle hook.

Parameters:

  • callback (function) - Callback function

onUnmounted(callback)

Register mounted lifecycle hook.

Parameters:

  • callback (function) - Callback function

defineTemplate(html)

Set component HTML template.

Parameters:

  • html (string) - HTML template string

Examples

Counter Component

Reactivity isn't the goal of this library, just clean, light DOM reusable components.

defineComponent('my-counter', ({ element, defineTemplate, defineEvent }) => {
  let count = 0
  
  const increment = defineEvent(() => {
    count++
    element.querySelector('div span').innerHTML = `Count: ${count}`
  });
  
  defineTemplate(`
    <div>
      <span>Count: ${count}</span>
      <button onclick="${increment}">+</button>
    </div>
  `);
});
<my-counter value="5"></my-counter>

Modal Component

defineComponent('my-modal', ({ defineSlots, defineEvent, exportEvent, element }) => {
  const slots = defineSlots();
  
  const show = defineEvent(() => {
    element.style.display = 'block';
  });
  
  const hide = defineEvent(() => {
    element.style.display = 'none';
  });
  
  exportEvent('show', show);
  exportEvent('hide', hide);
  
  defineTemplate(`
    <div class="modal-backdrop" onclick="${hide}">
      <div class="modal-content" onclick="event.stopPropagation()">
        ${slots.default}
        <button onclick="${hide}">×</button>
      </div>
    </div>
  `);
});
<my-modal>
  <h2>Modal Title</h2>
  <p>Modal content here</p>
</my-modal>

<script>
  document.querySelector('my-modal').show();
</script>

Slotted Component

defineComponent('my-card', ({ defineSlots, defineTemplate }) => {
  const slots = defineSlots(['header', 'default', 'footer']);
  
  defineTemplate(`
    <div class="card">
      <header>${slots.header}</header>
      <main>${slots.default}</main>
      <footer>${slots.footer}</footer>
    </div>
  `);
});
<my-card>
  <template slot="header">Card Title</template>
  <p>Card content</p>
  <template slot="footer">
    <button>Action</button>
  </template>
</my-card>

Class injection

defineComponent('my-component', ({ defineStyle, defineTemplate }) => {
    const style = defineStyle()

    defineTemplate(`
        <div class="${style}">
            <h1>Css classes are passed into the inner element</h1>
        </div>
    `)
})
<my-component class="d-flex align-center justify-center m-4"></my-component>

Browser Support

  • Chrome 54+
  • Firefox 63+
  • Safari 10.1+
  • Edge 79+

License

MIT