คล้าย Zod
ฟังก์ชั่นถูกออกแบบมาให้คล้าย Zod สำหรับใครที่คุ้นเคยอยู่แล้วสามารถใช้งานต่อได้ง่าย
ไลบรารีย์สำหรับตรวจสอบข้อมูล Lua, FiveM (เน้นใช้ภายใน)
local somePlayerData = {
identifier = 123,
name = 'John Stone'
}
local playerSchema <const> = prism:object({
identifier = prism:string().identifier(),
name = prism:string()
})
local data, errorMessage = playerSchema.parse(somePlayerData)
if errorMessage then
error(errorMessage)
--[[
errorMessage => {
code = 'invalid_type',
path = 'identifier',
message = 'Invalid type. Received: number, expected: string'
}
]]
else
--[[
data => {
identifier = 'steam:112233445566',
name = 'John Stone'
}
]]
end