verify 0.0.1 copy "verify: ^0.0.1" to clipboard
verify: ^0.0.1 copied to clipboard

outdated

An extension based Validation DSL.

Build Status

A fp inspired validation DSL. For dart and flutter projects.

Requirements #

The implementation of Verify relies on heavily on dart extension methods, which are available for Dart versions >= 2.6

Features #

  • Completely extensible (create your own combinators, validator primatives, etc)
  • Flexible Verify is an extension based API (There is not single class created its all pure functions)
  • Customizable (Define you own error types) organize validators how ever you want
  • Plays well with bloc

Examples #

Create simple validators from predicates

    final contains@ = Verify.property(
      (String email) => email.contains('@'),
        error: Error('email has to contain @')
        );

    final notEmpty = Verify.propery<String>((str) => !str.isEmpty, error: Error('field required'));

Reuse validators

final Validator_<String> emailValidator = Verify.all([ contains@, notEmpty ])

Validate a model correctness

Given a model, for instance a user:

class User extends Equatable {
  final String phone;
  final String mail;
  final int age;

  User(this.phone, this.mail, this.age);

  @override
  List<Object> get props => [phone, mail, age];
}

Create some validations on its fields

final userValidator = Verify.empty<User>()
    .checkProperty((user) => !user.phone.isEmpty, error: Error('phone empty'))
    .validatingField((user) => user.mail, emailValidator);

final someUser = User('','', 25);
final Either<List<Error>, User> validationResult = userValidator.verify(someUser);

Organize validators

Here is one approach to organize validations for specific type

class ValidateString {
  static Validator_<String> length(int length,
      {@required ValidationError error}) {
    return Verify.property((s) => s.length == length, error: error);
  }
}
53
likes
0
pub points
53%
popularity

Publisher

unverified uploader

An extension based Validation DSL.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

dartz, equatable, meta

More

Packages that depend on verify