{"id":"nazumah/janitor","name":"janitor","scope":"nazumah","platform":"roblox","description":"Mirrored from the Wally registry.","version":"1.1.4","latest":"1.1.4","versions":["0.1.0","1.0.0","1.1.0","1.1.1","1.1.2","1.1.3","1.1.4"],"license":"MIT","licenseRating":"safe","licenseCaveats":["License identified from the packaged LICENSE file; the manifest declared none."],"licenseVerified":true,"dependencies":{"nazumah/async":{"version":"^1.0.4","alias":"Async"}},"integrity":"61231dbee396d94850ab08c1e29cd335b8e2e146822e1782d2dbd0841f6906c7","likes":0,"downloads":0,"install":"forest install nazumah/janitor","url":"https://forest.dev/p/roblox/nazumah/janitor","files":"https://api.forest.dev/ai/package/roblox/nazumah/janitor/files","readme":"# Janitor\n\n[![Wally](https://img.shields.io/badge/Wally-1.1.4-blue.svg)](https://wally.run/package/nazumah/janitor)\n[![License](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)\n[![Luau](https://img.shields.io/badge/Luau-Strict-blueviolet.svg)](https://luau-lang.org/)\n\nJanitor is a powerful resource management and cleanup utility for Luau on Roblox. It helps developers track and dispose of objects, connections, and tasks, ensuring that memory leaks and dangling listeners don't accumulate in complex systems.\n\n---\n\n## Technical Advantages\n\n- **Method Agnostic Disposal**: Supports any object with standard disposal methods like `.Destroy()`, `.Disconnect()`, or `.cancel()`.\n- **Indexed Cleanup**: Assign unique keys to objects. Adding a new object to an existing index automatically cleans up the previous occupant.\n- **Async Interoperability**: First-class support for the [Async](https://github.com/Nazumah/roblox-luau-async) library. Adding an Async object to a Janitor ensures it is cancelled if the Janitor is destroyed.\n- **Instance-Linked Lifecycle**: Automatically trigger cleanup when a specific Roblox Instance is destroyed using `LinkToInstance`.\n- **First-Class IntelliSense**: Uses explicit `Static` and `Janitor` types to ensure that `require` returns a fully-typed interface.\n\n---\n\n## Installation\n\n### Wally\nUpdate your `wally.toml`:\n\n```toml\n[dependencies]\nJanitor = \"nazumah/janitor@1.1.4\"\nAsync = \"nazumah/async@1.0.4\"\n```\n\n---\n\n## Quick Start\n\n### 1. Tracking Multiple Objects\n```lua\nlocal Janitor = require(path.to.Janitor)\nlocal myJanitor = Janitor.new()\n\n-- Add a Roblox instance\nlocal part = myJanitor:Add(Instance.new(\"Part\"), \"Destroy\")\n\n-- Add an event connection\nmyJanitor:Add(part.Touched:Connect(print), \"Disconnect\")\n\n-- Add a custom function\nmyJanitor:Add(function()\n    print(\"Custom cleanup logic!\")\nend, true)\n\n-- Cleanup everything\nmyJanitor:Cleanup()\n```\n\n### 2. Indexed Retrieval\n```lua\nmyJanitor:Add(Instance.new(\"Part\"), \"Destroy\", \"MainPart\")\n\n-- Later...\nlocal part = myJanitor:Get(\"MainPart\")\n```\n\n### 3. Destruction Linking\n```lua\nlocal npc = workspace.NPC\nmyJanitor:LinkToInstance(npc)\n\n-- When npc is destroyed, myJanitor:Cleanup() is called automatically.\n```\n\n---\n\n## Documentation\n\n- [Why Use Janitor?](docs/WhyUseJanitor.md)\n- [API Reference](docs/API.md)\n\n---\n\n## License\nLicensed under the [MIT](LICENSE) License.","readmeTruncated":false}