@vuito/vue

Vue.js mixin wrapper for vuito validation library.
666 5
Install
npm install @vuito/vue
Latest Version:2.1.1
Vue:2 · 3
License:MIT
Last Updated:Feb 3, 2025
Links: GitHub  ·  npm
Maintainer: mathix420

vuito

Simple, lightweight, isomorphic, and template-based validation library.

Maintainability Test Coverage


⚡ Installation ⚡ Usage ⚡ Vue.js Mixin ⚡ Template Reuse ⚡


Installation

npm i vuito

Or via JsDeliver, UNPKG, or bundle.run.

Usage

Full documentation ➡️ https://vuito.vercel.app

Imports

CJS

const { regex, required } = require('vuito');
// OR
const regex = require('vuito/validators/regex.cjs');

Vuito is fully tree-shakable, so you can import only methods you need.

ES6

import { regex, required } from 'vuito';

Directly in the browser

import { regex, required } from 'https://esm.run/vuito';

Templates

With templates, you can easily create and reuse validations.

validations/auth.ts:

import { templateify, required, minLength, maxLength } from 'vuito';

export const signIn = templateify({
  username: [
    { test: required, message: 'Please enter a username.' },
    { test: minLength(3), message: 'Username is too short.' },
    { test: maxLength(20), message: 'Username is too big.' },
  ],
  password: [
    { test: required, message: 'Please enter a password.' },
    { test: minLength(12), message: 'Password is too short.' },
  ]
});

Validate

index.ts:

import { signIn } from './validations/auth';

signIn.check({
  username: 'test123',
  password: 'tooshort',
})
.then(() => console.log('Sign-in data is valid!'))
.catch(console.error)

// Result: console.error: Password is too short.

Vue.js Mixin

⚠️ Only supporting Vue2 currently ⚠️

minizipped size

Use vuito with Vue.js or Nuxt.js like a breeze!

npm i @vuito/vue

pages/signin.vue:

<template>
  <span>{{ errors.username }}</span>
  <input type="text" id="username"
    :class="{error: !!errors.username}"
    v-model="fields.username" @input.capture="onInput"
  >

  <span>{{ errors.password }}</span>
  <input type="password" id="password"
    :class="{error: !!errors.password}"
    v-model="fields.password" @input.capture="onInput"
  >
</template>

<script>
import { signIn } from '~/validations/auth';
import Vuito from '@vuito/vue';

export default {
  mixins: [Vuito(signIn)]
}
</script>

Template Reuse

To reuse your validation template you have many solutions.

  1. Create a validation package in your monorepo.
  2. Create a private package in NPM, GitHub, GitLab, ...
  3. Any other solution that lets you share a js/ts file between projects.
  4. Maybe SWAP would be a good option for you.

Related Packages

vue-template-loader

Vue.js 2.0 template loader for webpack

184,454 263
simple-vue-validator

lightweight yet flexible validation lib for vue.js

96,321 289
vue-validator

Validator component for Vue.js

80,472 2,167
vue-responsive-image

A Vue component to manage responsive images

7,273 58
vue-valid8

A simple form validation package made for Vue.js.

1,793 3

Version History

Version Released Vue License
2.1.1 >=2.0.0 MIT
2.0.7 >=2.0.0 MIT
2.0.3 >=2.0.0 MIT
2.0.1 >=2.0.0 MIT
1.2.0 ^2.0.0 MIT
Pre-releases (1)
Version Released Vue License
1.1.8-alpha.1 ^2.0.0 MIT