New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

validation-composable

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

validation-composable

Lightweight validation for Vue — just 40 lines of code.

latest
npmnpm
Version
0.3.2
Version published
Maintainers
1
Created
Source

✅ Validation Composable

Lightweight, practical validation for Vue. Only 40 lines of code. No special components to wrap your forms. No proprietary schema syntax to learn. Just bring your favorite schema library and go.

🔌 Works with Zod, Yup, Valibot, and any other Standard Schema library.

Installation

npm i validation-composable

Usage

import { useValidation } from 'validation-composable'

const { validate, issues } = useValidation(data, schema)

Example

<script setup>
// Use your own data (Reactive, Ref, Pinia, etc.)
const data = reactive({
  subject: '',
  body: '',
})

// Use your favorite schema library
const schema = z.object({
  subject: z.string().min(1, 'Subject is required'),
  body: z.string().min(1, 'Body is required'),
})

// Pass the data and schema to the composable
const { validate, issues } = useValidation(data, schema)

// Validate before submission. It auto-validates on data changes.
async function send() {
  const valid = await validate()
  if (!valid) return

  …
}
</script>

<template>
  <form @submit="send">
    <input v-model="data.subject" :class="{ 'border-red': issues.subject }" />
    <span v-if="issues.subject">{{ issues.subject[0] }}</span>

    <textarea v-model="data.body" :class="{ 'border-red': issues.body }" />
    <span v-if="issues.body">{{ issues.body[0] }}</span>
  </form>
</template>

💡 Pro Tip: Consider creating reusable input components to display validation errors automatically. This eliminates repetition and ensures consistent styling across your forms.

API

const { validate, issues, clearIssues } = useValidation(data, schema)
  • validate(): validates and fills issues; returns true when valid
  • issues: reactive object that mirrors your data; failing fields contain arrays of error messages
  • clearIssues(): clears all issues

Keywords

validation

FAQs

Package last updated on 25 Aug 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts