A form validation library that borrows its syntax from unit testing ↦
You may have heard my little rant about WET form validation logic on the latest episode of The Changelog. Well maybe you didn’t, but Evyatar did. It prompted him to reach out and let me know about Vest, his declarative validation framework:
The idea behind Vest is that your validations can be described as a ‘spec’ or a contract that reflects your form or feature structure. Your validations run in production, and they are framework agnostic - meaning Vest works well with React, Angular, Vue, or even without a framework at all.
I dig the syntax! Here’s a taste:
import vest, { test } from 'vest';
export default vest.create('user_form', (data = {}, currentField) => {
vest.only(currentField);
test('username', 'Username is required', () => {
enforce(data.username).isNotEmpty();
});
test('username', 'Username is too short', () => {
enforce(data.username).longerThanOrEquals(3);
});
});
Now all we need is a tool that will inspect our server-side logic and generate the equivalent Vest code. 😉
Discussion
Sign in or Join to comment or subscribe