A fp inspired validation DSL. For Dart and Flutter projects.
Features
Completely extensible (create your own combinators, validator primitives, etc)
Flexible Verify is an extension based API (There is not single class created its all pure functions)
Customizable (Define you own error types if required) organize validators how ever you want
Bloc friendly (See examples for a concrete implementation)
Null safe (as a prerelease)
Usage
Creating validators
A Validator is just a simple function alias:
// One of 2 variats depending on wether the validated subject will be transformed into another type or nottypedefValidatorT<S, T> = Either<List<dynamic>, T> Function(S subject);
typedefValidator<S> = Either<List<dynamic>, S> Function(S subject);
So you can create your own validator by just specifying a function for example:
Note: The difference between check and checkField is that the later ignore the verification when the value is null,
this will likely change in next version supporting null safety.
Run a validator
Running a validator is a simple as passing in a parameter since its just a function.
To be a bit more eloquent a verify method is provided, this method is special because besides
forwarding the argument to the calling validator it can also be used to filter the error list and
have it cast to a specific error type. Just supply a specific type parameter.
final signUpValidation = Verify.subject<SignUpState>();
final errors = signUpValidation
.verify<SignUpError>(newState); // Either<List<SignUpError>, SignUpState>
Built in validators
Verify doesn't come with many built in validators, because they are so simple to create.
It does come with some regex shorthands.
final validator = Verify.fromRegex(RegExp(r"(^\d+$)", error: Error('not just digits')) // Validator<String, int>
Form validation
Often times you will have modeled your error type similar to: