{"id":"vocksel/tag","name":"tag","scope":"vocksel","platform":"roblox","description":"Class to make tagging instances easy and typesafe","version":"0.2.0","latest":"0.2.0","versions":["0.2.0"],"license":"MIT","licenseRating":"safe","licenseCaveats":[],"licenseVerified":true,"dependencies":{"roblox/testez":{"version":"^0.4.1","alias":"TestEZ"},"osyrisrblx/t":{"version":"^3.0.0","alias":"t"}},"integrity":"35205f9398f6976446d96fb37b28d30bdca6b71fa511c46061b306102541b2bd","likes":0,"downloads":0,"install":"forest install vocksel/tag","url":"https://forest.dev/p/roblox/vocksel/tag","files":"https://api.forest.dev/ai/package/roblox/vocksel/tag/files","readme":"# Tag\n\nThis class allows you to create a CollectionService tag and quickly add/remove\nit on instances. It also allows you to enforce types for what each tag is\napplied to.\n\n```lua\nlocal tags = {\n    -- Using t, we enforce that a Character is a model.\n    Character = Tag.new(\"Character\", t.instanceOf(\"Model\")),\n\n    IsAlive = Tag.new(\"IsAlive\"),\n}\n\n-- You can apply the Character tag to anything, even NPCs, and they will all be\n-- handled here. This makes it easy to write code around different entities.\ntags.Character:onAdded(function(character)\n    print(character, \"added\")\nend)\n\ngame.Players.PlayerAdded:Connect(function(player)\n    player.CharacterAdded:Connect(function(character)\n        tags.Character:add(character)\n        tags.IsAlive:add(character)\n\n        local humanoid = character:WaitForChild(\"Humanoid\")\n        humanoid.Died:Connect(function()\n            tags.IsAlive:remove(character)\n        end)\n    end)\nend)\n```\n\nEach Tag instance has methods that wrap around the CollectionService API, so you\ncan quickly reference a tag and then perform operations with the context of the\ntag, instead of having to pass in a string constant to CollectionService.\n\n## Constructors\n\n**`Tag.new(name: string, instanceCheck?: (Instance) -> booleean)): Tag`**\n\nCreates a new tag instance. The `name` is the exact tag name that will be used\nby CollectionService. This is so level designers can easily parse the tags and\nadd them to instances in-game.\n\n## Properties\n\n**`Tag.name: string`**\n\nThe name supplied when constructing the tag.\n\n**`Tag.instanceCheck: ((Instance) -> boolean)?`**\n\nTypically this will be a [t](https://github.com/osyrisrblx/t) typechecker.\nOptional function that will be used to check if the instances that get passed\ninto methods of this class are correct.\n\n## Methods\n\n**`Tag:has(instance: Instance): boolean`**\n\nReturns true if the tag is applied to the instance. False otherwise. Same as\nCollectionService:HasTag().\n\n**`Tag:add(instance: Instance): void`**\n\nAdds the tag to the instance. Same as `CollectionService:AddTag()`.\n\n**`Tag:remove(instance: Instance): void`**\n\nRemoves the tag from the instance. Same as `CollectionService:RemoveTag()`.\n\n**`Tag:toggle(instance: Instance): void`**\n\nToggles the tag on the instance. If the tag is added, it will be removed, and\nvice versa.\n\n**`Tag:getTagged(): { Instance }`**\n\nGets all of the instances with this tag. Samne as `CollectionService:GetTagged()`.\n\n**`Tag:onAdded(callback: (Instance) -> nil): RBXScriptConnection`**\n\nRuns `callback` any time an instance is added with this tag. This is the same as\n`GetInstanceAddedSignal`.\n\nAlso, this will catch up existing instances by running `callback` on all\ninstances that are already in the game with the tag.\n\nReturns the connection to `GetInstanceAddedSignal`.\n\n**`Tag:onRemoved(callback: (Instance) -> nil): RBXScriptConnection`**\n\nRuns `callback` any time the tag is removed from an instance. This is the same\nas `GetInstanceRemovedSignal`.\n\nReturns the connection to `GetInstanceRemovedSignal`.\n","readmeTruncated":false}