0.0.14 • Published 2 years ago

@sveltecult/red v0.0.14

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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

License

Red is licensed under the MIT License.

0.0.14

2 years ago

0.0.13

2 years ago

0.0.12

2 years ago

0.0.11

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago