Vuito example

node v14.20.1
version: 1.2.1
endpointsharetweet
Step 1, define your template.
const { Template, required, minLength } = require("vuito") function customCheck(value) { return value !== 'alreadyUsed' } const auth = new Template({ username: [ { test: required, message: 'Username is required' }, { test: minLength(3), message: 'Username must be at least 3 characters long' }, { test: customCheck, message: 'Username is already taken' }, ], // Of course you can add as much fields as you want })
Step 2, check your data.
// Valid username await auth.check({ username: 'michel' }) .then(() => console.log('ok')) .catch(console.error)
// Invalid username await auth.check({ username: 'alreadyUsed' }) .then(() => console.log('ok')) .catch(console.error)
// Valid username, check only username await auth.username.check('michel') .then(() => console.log('ok')) .catch(console.error)
// Invalid username, check only username await auth.username.check('alreadyUsed') .then(() => console.log('ok')) .catch(console.error)
// No username await auth.check({}) .then(() => console.log('ok')) .catch(console.error)
// Username too small, check only username await auth.username.check('12') .then(() => console.log('ok')) .catch(console.error)
Watch a Nuxt.js demo here => https://vuito.vercel.app/
Loading…

no comments

    sign in to comment