Skip to content

Prismเอกสารคู่มือสำหรับ sure_prism

ไลบรารีย์สำหรับตรวจสอบข้อมูล Lua, FiveM (เน้นใช้ภายใน)

ตัวอย่าง

lua
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