typed
this is my re-imagination of the already existing library, “t”, stole borrowed some features from zod, and sprinkled in some typechecking magic sprinkled in*–packaged all into one library.
*it is highly recommended to use an external editor as roblox’s ide cant infer some of the schemas
caution: library is still under development; use at your own risk. report any bugs you find if you decide to use it
what is typed
typed is a runtime type validation library–a library that allows you to verify data that came from arbitrary sources by building schemas. to also make the development experience a lot better, it also provides applies types that cohere to your built schema
example usage
const t = require("path/to/typed")
const schema = t.table({
hello = t.string(),
world = t.transform(t.number())(function(v: number)
return v + 1
end),
notHere = t.optional(t.boolean()),
})
const data = {
hello = "hello",
world = 41,
}
print(schema.parse(data)) -- { ok = true, value = { hello = "hello", world = 42 } }
quick api overview
these are the following methods that exist under the typed module:
primitive schemas
t.boolean()
t.number()
t.string()
t.table(shape)
t.none() or t["nil"]()
t.vector()
t.buffer()
t.callable() or t["function"]()
t.userdata()
composite
t.array()
utility
t.any()
t.literal(value)
t.optional(a)
t.transform(a)
t.union(a, b)
t.intersect(a, b)
schema type
schema._infer phantom data
schema.validate(value)
schema.parse(value)
schema.unwrapParse(value)
schema.enforce(value: T) - it just enforces a value to adhere to the _infer type without needing you to do :: type or const variable: type
i’ll probably get some better documentation later on, for now you can just inspect the code directly to get an idea on how things work. you could also just ask me here too if needed
you can find the source code in the link below:
if you find any bugs, or would like to suggest any features, please let me know below or make pull requests / issues in the github linked above
this is one of my first ever posts on the community resources topic – hope you enjoy this