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

infinite-toggle-manager

v1.2.0

Published

Are you tired of dealing with messy code when managing active state in your components? Say goodbye to complexity and embrace the simplicity of ElementStateController!

Readme

Infinite-Toggle-Manager

A Lightweight JavaScript Toggle Manager for Effortless State Control! 🚀

Tired of juggling messy classList.toggle() calls or tracking active states across multiple elements/components? Infinite-Toggle-Manager simplifies it all!

✨ Why use it?

🔄 Toggle anything – Manage active/inactive states for HTML elements, UI components, or even JS objects.

🧩 Minimal setup – Ditch manual state checks and let this class handle the logic.

🚫 No more conflicts – Cleanly enforce single-active or multi-active states without spaghetti code.

Perfect for tabs, modals, menus, or any interactive UI!

Table of Contents


ElementStateController

ElementStateController and ElementState are two JavaScript classes that provide a convenient and versatile way to manage states. The classes allow you to control a group of items' states.

🔧 Control Element States: With ElementStateController, you can effortlessly make active, inactive, or toggle states of the elements, giving you complete control over their functionality. 💡

🎯 Perfect for Every Use Case: Whether it's managing user settings, controlling UI elements, or implementing dynamic behavior, ElementStateController has got you covered! 🧩

💪 Manage Multiple Elements with Ease: Say goodbye to repetitive tasks! ElementStateController empowers you to handle multiple elements with a single instance.

🎨 Customize to Your Heart's Content: Tailor each element's behavior to requirements with ease.

📦 Simple Installation: Installing ElementStateController is a breeze! Just run a single npm command, and you're ready to go.

Constructor

constructor(elements: Object, options: Object)

Parameters:

  • elements (Object): A record of element names and their corresponding ElementState or ElementStateData objects.
  • options (Object): An optional object that can contain the following properties:
    • activeAll (boolean): Determines whether all elements should be turned on initially. Cannot be true if inactiveAll is also true.
    • inactiveAll (boolean): Determines whether all elements should be initially inactive. Cannot be true if activeAll is also true.
    • multiple (boolean): Allows turning on multiple elements at once.

Methods

addElement(name: string, elementState: Object): void

Adds a new element to the controller. Throws an error if an element with the same name already exists.

activeAll(): void

Turns on all elements managed by the ElementStateController. Logs a warning if multiple is false.

inactiveAll(): void

Turns off all elements managed by the ElementStateController. Elements marked as isAlwaysActive will remain active.

active(name: string): void

Activates a specific element by name. Throws an error if the element contradicts the "multiple active state" rule.

inactive(name: string): void

Deactivates a specific element by name.

toggle(name: string): void

Toggles the state of a specific element by name. Logs a warning if the element is marked as isAlwaysActive. If multiple is false, toggling one element will deactivate others.

setIsAlwaysActive(name: string, value: boolean): void

Sets the isAlwaysActive property for a specific element. Throws an error if the value is not a boolean.

hasAllowMultipleElements(): boolean

Returns true if multiple active elements are allowed, otherwise false.


ElementState

The ElementState class represents the state of an individual element.

Constructor

Parameters:

  • name (String): The name of the element. Must be a non-empty string.
  • value (Boolean): An optional parameter that determines the initial state of the element. Default is false.
  • isAlwaysActive (Boolean): An optional parameter that determines if the element's state should always be active. Default is false. If set to true, the value must also be true.

Methods

active(): void

Activates the element.

inactive(): void

Deactivates the element. Logs a warning if the element is marked as isAlwaysActive.

toggle(): void

Toggles the state of the element. Logs a warning if the element is marked as isAlwaysActive.

isActive(): boolean

Returns true if the element is active, otherwise false.

isAlwaysActive(): boolean

Returns true if the element is marked as always active, otherwise false.

setIsAlwaysActive(value: boolean): void

Sets the isAlwaysActive property. If set to true, the element is automatically activated. Throws an error if the value is not a boolean.


ElementError

The ElementError class is used to handle specific error scenarios in ElementStateController and ElementState. It provides predefined error messages for common issues.

Error Types

| Error Type | Description | | ----------------------------------------- | ------------------------------------------------------------------- | | ELEMENT_NOT_SET | Thrown when attempting to access an element that is not defined. | | ELEMENT_ALREADY_EXIST | Thrown when attempting to add an element with a duplicate name. | | ELEMENT_CONTRADICTS_MULTIPLE_STATE_RULE | Thrown when an operation violates the "multiple active state" rule. |


Contributing

Contributions are welcome! If you have suggestions or improvements, feel free to fork the repository and submit a pull request.

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature/YourFeature).
  3. Commit your changes (git commit -m 'Add YourFeature').
  4. Push to the branch (git push origin feature/YourFeature).
  5. Open a pull request.

License

Distributed under the MIT License. See LICENSE for more information.


Contact