pixel-validate
v1.0.0
Published
Very simple and lightweight validation widget for SvelteKit
Downloads
3
Maintainers
Readme
Pixel-validate
Very lightweight and simple validate widget
Supports svelte 3 and 4
Usage
import {$validate} from '$lib/components/widgets/validate/validate';
import {fail} from '@sveltejs/kit';
import type {Actions, ServerLoad} from '@sveltejs/kit';
const schema = {
email: {required: $validate.rule.required(), email: $validate.rule.email()},
password: {required: $validate.rule.required()}
};
export const actions: Actions = {
login: async ({request, fetch, cookies}) => {
const data = Object.fromEntries(await request.formData());
try {
$validate.parse(schema, data); # or you can use parseFormData
} catch (e) {
console.log(e);
return fail(400, {message: 'validation error', errors: e});
}
}
};
validators: required, email, minLength, maxLength, sameAs, onlyLetters, checked, file