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

@aegisjsproject/commands

v1.0.2

Published

A lightweight command system for handling DOM interactions through custom events and the `commandfor` attribute.

Readme

@aegisjsproject/commands

A lightweight command system for handling DOM interactions through command events and the commandfor attribute.

CodeQL Node CI Lint Code Base

GitHub license GitHub last commit GitHub release GitHub Sponsors

npm node-current npm bundle size gzipped npm

GitHub followers GitHub forks GitHub stars Twitter Follow

Donate using Liberapay


Core Concept

This library is based on the Invoker Commands API. Elements with a commandfor attribute automatically dispatch command events to their target elements when triggered. The library handles these events with built-in commands or custom registered handlers.

<!-- Using Built-In Commands -->
<button commandfor="my-element" command="show-modal">Show Modal</button>
<dialog id="my-element">
  <p>Hello, World!</p>
  <button commandfor="my-element" command="close">Close</button>
</dialog>
<!-- Using Custom Commands -->
<button commandfor="another-el" command="--aegis-command-remove">Remove Element</button>
<div id="another-el">This content will be removed.</div>

Custom, pre-registered Commands

  • --aegis-command-hide/--aegis-command-unhide - Controls hidden attribute
  • --aegis-command-disable/--aegis-command-enable - Controls disabled attribute
  • --aegis-command-remove - Removes element from DOM
  • --aegis-command-scroll-into-view - Scrolls element into view (respects prefers-reduced-motion)
  • --aegis-command-request-fullscreen/--aegis-command-exit-fullscreen/--aegis-command-toggle-fullscreen - Fullscreen API
  • --aegis-command-show-picker - Opens input picker (date, color, etc.)
  • --aegis-command-step-up/--aegis-command-step-down - Steps numeric inputs
  • --aegis-command-open-details/--aegis-command-close-details/--aegis-command-toggle-details - Controls elements
  • --aegis-command-play-media/--aegis-command-pause-media - Media element controls
  • --aegis-command-request-picture-in-picture - Picture-in-picture for videos
  • --aegis-command-copy-text - Copies element's textContent to clipboard

API

observeCommands(target?)

Sets up automatic command handling. Call once during initialization.

import { observeCommands } from './commands.js';
observeCommands(); // Observes document.body by default

registerCommand(command, callback)

Registers custom commands (must be prefixed with --).

import { registerCommand } from './commands.js';

registerCommand('--my-command', (event) => {
  console.log('Custom command triggered on', event.target);
});

createCommand(callback)

Generates a unique command string and registers the callback.

import { createCommand } from './commands.js';

const cmd = createCommand((event) => {
  event.target.style.color = 'red';
});
// Use `cmd` as the command attribute value

command(callback)

Convenience function that returns a complete attribute string.

import { command } from './commands.js';

element.innerHTML = `<button ${command(e => alert('clicked'))}>Click me</button>`;

listenForCommands(target, init?)

Manually add command listener to specific elements.

import { listenForCommands } from './commands.js';
listenForCommands(myElement, { once: true });

Usage Patterns

Basic Setup

import { observeCommands } from './commands.js';
observeCommands();

Custom Commands

import { observeCommands, registerCommand } from './commands.js';

registerCommand('--toggle-class', (event) => {
  event.target.classList.toggle('active');
});

observeCommands();

Dynamic Command Generation

import { observeCommands, createCommand } from './commands.js';

const toggleColor = createCommand((event) => {
  const colors = ['red', 'blue', 'green'];
  const current = colors.indexOf(event.target.style.color);
  event.target.style.color = colors[(current + 1) % colors.length];
});

document.body.innerHTML += `<button commandfor="target" command="${toggleColor}">Change Color</button>`;
observeCommands();

CommandEvent Properties

Command events extend regular events with:

  • source - The element that triggered the command (the button/trigger)
  • command - The command string that was executed#

Memory Considerations

[!WARNING] Command listeners are not automatically removed when elements are deleted. If you're frequently adding/removing elements with commandfor attributes in long-running applications, consider using listenForCommands() with { once: true } for one-time interactions, or manually manage listeners for dynamic content.

Security

Command registration closes automatically after initial setup. Call closeCommandRegistration() explicitly if needed for additional security.