{"id":"cody-nelson/trove","name":"trove","scope":"cody-nelson","platform":"roblox","description":"Less jank sleitnick trove","version":"0.0.1","latest":"0.0.1","versions":["0.0.1"],"license":"MIT","licenseRating":"safe","licenseCaveats":[],"licenseVerified":true,"dependencies":{"osyrisrblx/t":{"version":"^3.1.1","alias":"t"}},"integrity":"2ef5d8b2e52df4cb7ce29fadca1b2937a4283a827b0d4fb0947f29702b390a3a","likes":0,"downloads":0,"install":"forest install cody-nelson/trove","url":"https://forest.dev/p/roblox/cody-nelson/trove","files":"https://api.forest.dev/ai/package/roblox/cody-nelson/trove/files","readme":"# Attr\r\nAttr is an attribute utility library for Roblox.\r\n\r\nIt is highly recommended to use Attr with [t by Osyris](https://github.com/osyrisrblx/t) for typechecking. The `t` library provides simple typechecking methods that can be passed into Attr as validators.\r\n\r\n## Example Usage\r\n```luau\r\nlocal Attr = require(Path.To.Attr)\r\nlocal t = require(Path.To.t)\r\n\r\nlocal fooInstance: Instance = workspace.FooInstance\r\n\r\nlocal function CustomValidator(attributeValue: any?): (boolean, string)\r\n    return typeof(attributeValue) == \"number\", \"Attribute must be a number\"\r\nend\r\n\r\nlocal customExample = Attr.GetAttribute(fooInstance, \"SomeAttribute\", CustomValidator)\r\n-- If `SomeAttribute` is a number, it will return the number\r\n-- If `SomeAttribute` is not a number, it will error with the message \"Attribute must be a number\"\r\n\r\nlocal ownerId = Attr.GetAttribute(fooInstance, \"OwnerId\", t.integer)\r\n-- If `OwnerId` is an integer, it will return the integer\r\n-- If `OwnerId` is not an integer or does not exist, it will error\r\n\r\nlocal valueWithDefault = Attr.GetAttribute(fooInstance, \"Value\", t.string, \"Default\")\r\n-- If `Value` is a string, it will return the string\r\n-- If `Value` is not a string, it will return `Default`\r\n```\r\n## Types\r\n### Attribute Validator\r\n```luau\r\ntype AttributeValidatorFn = (any?) -> (boolean, string?)\r\n```\r\nAn AttributeValidator is a function which takes in the current value of the attribute and returns a boolean and a string. The boolean is if it passed the check, and the string is the reason why not which will be shown when it errors.\r\n### Attribute Filter\r\n```luau\r\ntype AttributeFilterFn = (string, any?) -> boolean\r\n```\r\nAn AttributeFilter is a function that takes the attribute name and value, and returns a boolean indicating whether the attribute passes the filter.\r\n\r\n## Functions\r\n### Attr.GetAttribute\r\n```luau\r\nAttr.GetAttribute(instance: Instance, attributeName: string, Validator: AttributeValidatorFn?, defaultValue: any?): any?\r\n```\r\n> Returns the attribute with the given name if the validator returns true. If the validator fails and a default value is provided, it returns the default; if there is no default, it errors.\r\n\r\n### Attr.ObserveAttribute\r\n```luau\r\nAttr.ObserveAttribute(Callback: (any?) -> (), instance: Instance, attributeName: string, Validator: AttributeValidatorFn?, default: any?): RBXScriptConnection\r\n```\r\n> Calls the callback immediately with the current attribute value, using the same logic as [GetAttribute](#attrgetattribute). Returns an `RBXScriptConnection`.\r\n\r\n### Attr.GetAttributes\r\n```luau\r\nAttr.GetAttributes(instance: Instance, Filter: AttributeFilterFn?): { [string]: any }\r\n```\r\n> Returns a dictionary of attributes (AttributeName: AttributeValue) that pass the filter (if one is provided).\r\n","readmeTruncated":false}