{"id":"itzbbbbas/typeguard","name":"typeguard","scope":"itzbbbbas","platform":"roblox","description":"One runtime type checker for Roblox Luau. Builders return the Luau type they check, so typeof(spec) is the static type. Remote payloads, attribute schemas, content registries and DataStack store templates share it.","version":"0.1.0","latest":"0.1.0","versions":["0.1.0"],"license":"MIT","licenseRating":"safe","licenseCaveats":[],"licenseVerified":true,"dependencies":{},"integrity":"671a6dbc400f862b769648cd25484002985544e57e9dd8db8f8c5db913573e91","likes":0,"downloads":0,"install":"forest install itzbbbbas/typeguard","url":"https://forest.dev/p/roblox/itzbbbbas/typeguard","files":"https://api.forest.dev/ai/package/roblox/itzbbbbas/typeguard/files","readme":"# Typeguard\n\nOne runtime type checker for Roblox Luau. Each builder returns its spec cast to the Luau type it checks, so `typeof(spec)` is the static type and a shape is written once. Remote payloads, attribute schemas, content registries and [DataStack](https://github.com/itzbbbbas/DataStack) store templates share it.\n\n```toml\nTypeguard = \"itzbbbbas/typeguard@0.1.0\"\n```\n\n```lua\nlocal Typeguard = require(ReplicatedStorage.Packages.Typeguard)\nlocal T = Typeguard\n\nlocal GRAB = T.Struct({\n\tuid = T.String({ max_length = 64 }),\n\tat = T.Vector3({ max_magnitude = 4096 }),\n\tleaf = T.Optional(T.Int({ min = 1 })),\n})\ntype Grab = typeof(GRAB)\n\nlocal reason = Typeguard.Check(payload, GRAB, \"payload\")\nif reason then\n\twarn(reason) -- payload.at: magnitude 9000 above max 4096\n\treturn\nend\nlocal grab = payload :: Grab\n```\n\n## Builders\n\nEvery builder takes one options table. `default` rides along for a template or a schema and is never checked.\n\n| Builder | Options | Rejects |\n| --- | --- | --- |\n| `T.Number` | `default, min, max, nan` | a non-number, NaN or infinity unless `nan = true`, a value outside `min..max` |\n| `T.Int` | `default, min, max` | `T.Number` plus a fraction |\n| `T.String` | `default, max_length, one_of, pattern` | a non-string, a long string, a value outside `one_of`, a `string.match` miss |\n| `T.Bool` | `default` | a non-boolean |\n| `T.Any` | `default` | nothing |\n| `T.Enum` | `members, default` | a value not in `members`, compared with `==` |\n| `T.Literal(value)` | | anything but `value` |\n| `T.Big` | `default` | a value that is not a `{ m, e }` big number |\n| `T.Vector3` | `default, max_magnitude` | a NaN or infinite component, a long vector |\n| `T.CFrame` | `default` | a NaN or infinite position |\n| `T.Color3`, `T.EnumItem` | `default` | the wrong `typeof` |\n| `T.Function` | | a non-function |\n| `T.Instance` | `class` | a non-Instance, or one that fails `IsA(class)` |\n| `T.Struct(shape)` | `exact, max_keys` | a missing or failing field, an unknown key unless `exact = false`, too many keys |\n| `T.Dict(value)` | `key, max_count, default` | a failing value, a key of the wrong type, too many entries |\n| `T.Array(value)` | `max_count, default` | a hole, a failing element, too many elements |\n| `T.Optional(inner)` | | a non-nil value that fails `inner` |\n| `T.OneOf(a, b, ...)` | | a value that fails every shape |\n| `T.ServerOnly(inner)` | | what `inner` rejects; sets `server_only` for DataStack replication |\n| `T.Of(value)` | | a value whose `typeof` differs, or a table that does not match `value` exactly |\n\nA raw value inside a shape is an implicit `T.Of`. A raw table is an exact struct, so a plain template checks as itself.\n\n## Functions\n\n| Function | Returns |\n| --- | --- |\n| `Typeguard.Check(value, spec, path?)` | `nil` on pass, else `path.key: reason` |\n| `Typeguard.Ok(value, spec)` | boolean |\n| `Typeguard.Defaults(spec)` | the default tree; an `Optional` is nil, a `Dict` or `Array` is empty |\n| `Typeguard.Is(value)` | true when a builder made it |\n| `Typeguard.Kind(spec)` | `\"int\"`, `\"struct\"`, …, or `\"raw\"` |\n| `Typeguard.Unwrap(spec)` | the spec under `Optional` and `Of` |\n| `Typeguard.Emit(spec, name?)` | Luau type source, `<name>` and `<name>Paths` |\n| `Typeguard.BigMath` | `New`, `Add`, `Sub`, `Mul`, `Div`, `Compare`, `Short`, `ToString` for big numbers |\n\nNothing touches a Roblox service at load, so the package runs under Lune and zune. Roblox datatype checks use `typeof`, so they need Roblox or a runtime that provides those datatypes.\n\n## Develop\n\n```sh\nzune run tests/lib.spec.luau\nstylua --check src tests\nselene src\nnpm run docs:check\n```\n","readmeTruncated":false}