nuxt-precognition
nuxt-precognition
Nuxt module implementing Laravel Precognition protocol in Nitro
Nuxt Precognition
Nuxt Precognition is a validation module for Nuxt that implements the Precognition protocol in a backend-agnostic way. It supports any backend or validation library, and is not tied to Laravel.
Requirements
- Nuxt >= 3.x
- Node.js >= 18
Why Nuxt Precognition?
- Backend agnostic: Works with any backend that supports the Precognition protocol.
- Validation library agnostic: Use Zod, Yup, or any other validation library.
- Client & server side validation: Seamless validation on both ends.
- Optimal TypeScript support: Typesafe forms and error handling.
- Highly customizable: Plug in your own error parsers and status handlers.
Quick Example
interface User {
email: string
password: string
}
const form = useForm(
(): User => ({ email: '', password: '' }),
(body, headers) => $fetch('/api/login', { method: 'POST', headers, body })
)
Installation
Install the module in your Nuxt app:
npx nuxi module add nuxt-precognition
Contributing
# Install dependencies
npm install
# Generate type stubs
npm run dev:prepare
# Develop with the playground
npm run dev
# Build the playground
npm run dev:build
# Run ESLint
npm run lint
# Run Vitest
npm run test
npm run test:watch
# Release new version
npm run release
License
MIT © sot1986