@sveltecult/red v0.0.14
Red
Red is a versatile form data validation library inspired by Laravel, offering a fluent API to ensure data integrity and consistency in web applications. Please note that this project is currently a work in progress and undergoing active development.
Important Changes
There were lots of bug fixes and changes from v0.0.13
.
🚨 Rules are now OPTIONAL by default.
🚨 Validation types (Rule.date()
, Rule.string()
, Rule.number()
, etc.) now also function as if they are rule but stop when encountered failure.
Features
- Fluent validation API
- Now supports for various input types: array, boolean, date, file, number, string.
- Array validation using
[]
and.*
notations - Customizable validation rules
- Framework agnostic
- Now with 40+ available rules
Installation
To install Red, use your preferred package manager:
npm install @sveltecult/red
Or, if you're using Bun:
bun add @sveltecult/red
Getting Started
Detailed instructions on getting started and list of available validation rules can be found in the Documentation.
Basic Usage
import { Rule, Validation } from '@sveltecult/red';
/** @type {import('./$types').Actions} */
export const actions = {
default: async ({ request }) => {
const formData = await request.formData();
const validation = new Validation(formData, {
email: Rule.string().required().email(),
password: Rule.string().required().minLength(8).confirmed()
});
const errors = await validation.errors();
if (errors.any() === true) {
console.log(errors.all());
}
}
};
Writing Custom Validation
Red allows writing custom validation logic using the .custom()
rule for scenarios where standard validation rules don't meet specific requirements, such as database-related checks. Click here to learn more about how to create your own custom validation.
Contributing
We welcome contributions! If you'd like to contribute to Red, please follow our Contribution Guidelines and submit a pull request.
License
Red is licensed under the MIT License.