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

@art_is_code/activeclass_js

v1.0.0

Published

A lightweight, tag-based JavaScript utility for handling navigation active states with AJAX support.

Readme

@art_is_code/activeclass_js

A lightweight, intelligent JavaScript utility for handling navigation active states. Unlike standard scripts, it uses a Tag-based logic to manage complex hierarchies, multi-level menus, and dynamic content (AJAX) without ID conflicts.

🚀 Key Features

  • Tag-based Logic: A single link can activate multiple UI elements simultaneously across the DOM.
  • AJAX Native: Automatically monitors DOM changes using MutationObserver.
  • Anchor Support: Full support for hash-based URLs (#section).
  • Context Injection: Force active states on pages not present in the menu via "Ghost Elements".
  • Zero Dependencies: Pure Vanilla JavaScript (ES6+).
  • Manual Refresh: Public API to force state updates during manual URL changes (pushState).

🛠 Installation

npm install @art_is_code/activeclass_js

Alternatively, you can include it manually:

<script type="module">
  import { active } from './path/to/activeclass_js.js';
  active();
</script>

💡 Usage Examples

  1. Basic Link The link gets the active class automatically if the URL matches.
<a href="/about">About Us</a>
  1. Multi-level Hierarchy (The Tag System) Use data-ac-tags on the link to trigger other elements and data-ac-group on the targets.
<li data-ac-group="category-elections">Elections</li>

<li>
    <a href="/elections/candidates" data-ac-tags="category-elections">
        Candidates List
    </a>
</li>
  1. Ghost Trigger (Context Injection) Force a specific context even if the page isn't in the menu (e.g., a hidden detail page) using a "ghost" element.
<meta data-ac-force="category-elections, sidebar-group">

Pro Tip: The data-ac-force attribute is tag-agnostic. You can use <meta>, <span>, <div>, or even <template> depending on your architectural needs.

⚙️ Configuration & API

Initialize the plugin in your JavaScript entry point:

import { active } from './activeclass_js.js';

const ac = active({
    className: 'activecl',
    selector: 'a[href]:not([href=""])',
    observer: true
});

| Option | Default | Description | | :--- | :--- | :--- | | className | 'activecl' | The CSS class added to active elements. | | selector | 'a[href]:not([href=""])' | Which links the plugin should monitor. | | observer | true | Watch for DOM changes (AJAX support). | If you update the URL manually (e.g., via AJAX or history.pushState), call the refresh method:

ac.refresh();

📖 HTML Attributes Reference

| Attribute | Role | Description | | :--- | :--- | :--- | | data-ac-tags | Trigger | Comma-separated tags to activate when the link is active. | | data-ac-group | Target | Identifies which group(s) the element belongs to. | | data-ac-force | Trigger | Immediately activates the specified tags (useful for Ghost Elements). | | data-ac-query | Option | Set to "1" to match URL including query strings. | | data-ac-exclude | Option | Set to "1" to trigger tags without activating the link itself. |

Public Methods

📜 License

This project is licensed under the MIT License - see the LICENSE file for details. MIT © Andrea D'Agostino (art is code)