{"id":40719961,"url":"https://github.com/maleeshagimshan98/infinite-toggle-manager","last_synced_at":"2026-01-21T13:36:03.521Z","repository":{"id":255743328,"uuid":"670769217","full_name":"maleeshagimshan98/infinite-toggle-manager","owner":"maleeshagimshan98","description":"Are you tired of dealing with messy code when managing switches in your application? Say goodbye to complexity and embrace the simplicity of SwitchController!","archived":false,"fork":false,"pushed_at":"2025-04-26T18:17:47.000Z","size":198,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-23T17:34:22.480Z","etag":null,"topics":["switch","switcher","vue","vue3"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/maleeshagimshan98.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-07-25T19:48:17.000Z","updated_at":"2025-04-26T18:17:53.000Z","dependencies_parsed_at":"2025-04-26T19:34:09.765Z","dependency_job_id":null,"html_url":"https://github.com/maleeshagimshan98/infinite-toggle-manager","commit_stats":null,"previous_names":["maleeshagimshan98/vue-switch-controller","maleeshagimshan98/infinite-toggle-manager","maleeshagimshan98/active-state-switcher"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/maleeshagimshan98/infinite-toggle-manager","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maleeshagimshan98%2Finfinite-toggle-manager","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maleeshagimshan98%2Finfinite-toggle-manager/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maleeshagimshan98%2Finfinite-toggle-manager/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maleeshagimshan98%2Finfinite-toggle-manager/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maleeshagimshan98","download_url":"https://codeload.github.com/maleeshagimshan98/infinite-toggle-manager/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maleeshagimshan98%2Finfinite-toggle-manager/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28633774,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-21T04:47:28.174Z","status":"ssl_error","status_checked_at":"2026-01-21T04:47:22.943Z","response_time":86,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["switch","switcher","vue","vue3"],"created_at":"2026-01-21T13:36:01.834Z","updated_at":"2026-01-21T13:36:03.514Z","avatar_url":"https://github.com/maleeshagimshan98.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Infinite-Toggle-Manager\n\nA Lightweight JavaScript Toggle Manager for Effortless State Control! 🚀\n\nTired of juggling messy classList.toggle() calls or tracking active states across multiple elements/components? Infinite-Toggle-Manager simplifies it all!\n\n✨ Why use it?\n\n🔄 Toggle anything – Manage active/inactive states for HTML elements, UI components, or even JS objects.\n\n🧩 Minimal setup – Ditch manual state checks and let this class handle the logic.\n\n🚫 No more conflicts – Cleanly enforce single-active or multi-active states without spaghetti code.\n\nPerfect for tabs, modals, menus, or any interactive UI!\n\n## Table of Contents\n\n- [ElementStateController](#elementstatecontroller)\n  - [Usability](#usability)\n  - [Key Features](#key-features)\n  - [Constructor](#constructor)\n  - [addElement(name: string, elementState: ElementState | ElementStateData)](#addswitchname-string-switchobj-object)\n  - [activeAll()](#activeall)\n  - [inactiveAll()](#inactiveall)\n  - [active(name: string)](#onname-string)\n  - [inactive(name: string)](#offname-string)\n  - [toggle(name: string)](#togglename-string)\n  - [setIsAlwaysActive(name: string, value: boolean)](#setisalwaysactive)\n  - [hasAllowMultipleElements()](#hasallowmultipleelements)\n  - [Example](#example)\n- [ElementState](#elementstate)\n  - [Constructor](#constructor-1)\n  - [active()](#active)\n  - [inactive()](#inactive)\n  - [toggle()](#toggle)\n  - [isActive(): boolean](#isactive-boolean)\n  - [isAlwaysActive(): boolean](#isalwayson-boolean)\n  - [setIsAlwaysActive(value: boolean)](#setisalwaysactive-1)\n  - [Example](#example-1)\n- [ElementError](#elementerror)\n  - [Error Types](#error-types)\n  - [Example](#example-2)\n\n---\n\n## ElementStateController\n\nElementStateController 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.\n\n🔧 Control Element States: With ElementStateController, you can effortlessly make active, inactive, or toggle states of the elements, giving you complete control over their functionality. 💡\n\n🎯 Perfect for Every Use Case: Whether it's managing user settings, controlling UI elements, or implementing dynamic behavior, ElementStateController has got you covered! 🧩\n\n💪 Manage Multiple Elements with Ease: Say goodbye to repetitive tasks! ElementStateController empowers you to handle multiple elements with a single instance.\n\n🎨 Customize to Your Heart's Content: Tailor each element's behavior to requirements with ease.\n\n📦 Simple Installation: Installing ElementStateController is a breeze! Just run a single npm command, and you're ready to go.\n\n### Constructor\n\n```javascript\nconstructor(elements: Object, options: Object)\n```\n\n**Parameters:**\n\n- `elements` (Object): A record of element names and their corresponding `ElementState` or `ElementStateData` objects.\n- `options` (Object): An optional object that can contain the following properties:\n  - `activeAll` (boolean): Determines whether all elements should be turned on initially. Cannot be true if `inactiveAll` is also true.\n  - `inactiveAll` (boolean): Determines whether all elements should be initially inactive. Cannot be true if `activeAll` is also true.\n  - `multiple` (boolean): Allows turning on multiple elements at once.\n\n---\n\n### Methods\n\n#### addElement(name: string, elementState: Object): void\n\nAdds a new element to the controller. Throws an error if an element with the same name already exists.\n\n#### activeAll(): void\n\nTurns on all elements managed by the `ElementStateController`. Logs a warning if `multiple` is false.\n\n#### inactiveAll(): void\n\nTurns off all elements managed by the `ElementStateController`. Elements marked as `isAlwaysActive` will remain active.\n\n#### active(name: string): void\n\nActivates a specific element by name. Throws an error if the element contradicts the \"multiple active state\" rule.\n\n#### inactive(name: string): void\n\nDeactivates a specific element by name.\n\n#### toggle(name: string): void\n\nToggles 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.\n\n#### setIsAlwaysActive(name: string, value: boolean): void\n\nSets the `isAlwaysActive` property for a specific element. Throws an error if the value is not a boolean.\n\n#### hasAllowMultipleElements(): boolean\n\nReturns `true` if multiple active elements are allowed, otherwise `false`.\n\n---\n\n## ElementState\n\nThe `ElementState` class represents the state of an individual element.\n\n### Constructor\n\n**Parameters:**\n\n- `name` (String): The name of the element. Must be a non-empty string.\n- `value` (Boolean): An optional parameter that determines the initial state of the element. Default is `false`.\n- `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`.\n\n---\n\n### Methods\n\n#### active(): void\n\nActivates the element.\n\n#### inactive(): void\n\nDeactivates the element. Logs a warning if the element is marked as `isAlwaysActive`.\n\n#### toggle(): void\n\nToggles the state of the element. Logs a warning if the element is marked as `isAlwaysActive`.\n\n#### isActive(): boolean\n\nReturns `true` if the element is active, otherwise `false`.\n\n#### isAlwaysActive(): boolean\n\nReturns `true` if the element is marked as always active, otherwise `false`.\n\n#### setIsAlwaysActive(value: boolean): void\n\nSets the `isAlwaysActive` property. If set to `true`, the element is automatically activated. Throws an error if the value is not a boolean.\n\n---\n\n## ElementError\n\nThe `ElementError` class is used to handle specific error scenarios in `ElementStateController` and `ElementState`. It provides predefined error messages for common issues.\n\n### Error Types\n\n| Error Type                                | Description                                                         |\n| ----------------------------------------- | ------------------------------------------------------------------- |\n| `ELEMENT_NOT_SET`                         | Thrown when attempting to access an element that is not defined.    |\n| `ELEMENT_ALREADY_EXIST`                   | Thrown when attempting to add an element with a duplicate name.     |\n| `ELEMENT_CONTRADICTS_MULTIPLE_STATE_RULE` | Thrown when an operation violates the \"multiple active state\" rule. |\n\n---\n\n\n## Contributing\n\nContributions are welcome! If you have suggestions or improvements, feel free to fork the repository and submit a pull request.\n\n1. Fork the repository.\n2. Create a new branch (`git checkout -b feature/YourFeature`).\n3. Commit your changes (`git commit -m 'Add YourFeature'`).\n4. Push to the branch (`git push origin feature/YourFeature`).\n5. Open a pull request.\n\n---\n\n## License\n\nDistributed under the MIT License. See `LICENSE` for more information.\n\n---\n\n## Contact\n\n- **Author**: Maleesha Gimshan\n- **Email**: [maleesha.gimshan.98@outlook.com](mailto:maleesha.gimshan.98@outlook.com)\n- **GitHub**: [github.com/maleeshagimshan98](https://github.com/maleeshagimshan98)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaleeshagimshan98%2Finfinite-toggle-manager","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaleeshagimshan98%2Finfinite-toggle-manager","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaleeshagimshan98%2Finfinite-toggle-manager/lists"}