Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Value brings simple way of defining Value Objects in Dart. It uses power of Freezed package and its Union types.

The main reason to use Value is to wrap simple types like String and num into meaningful types that can be easily validated.

Some commonly used value types are provided by the library:

  • EmailAddress
  • Url

Getting started

Add to your pubspec.yaml:

dependencies:
  value:
    git: https://github.com/adriank/value.git

Usage

Using Value turns this code:

  final emailAddress = 'me@example.com';
  print(emailAddress.runtimeType); // String

into a meaningful EmailAddress type that can be validated:

  final emailAddress = EmailAddress('me@example.com');
  print(emailAddress.runtimeType); // String
  print(emailAddress.isValid); // true
  final otherEmailAddress = EmailAddress('example.com');
  print(invalidEmailAddress().when(
    (emailAddress) => 'Valid! $emailAddress',
    invalidEmail: (invalidEmail) => 'Not valid! $invalidEmail',
  )); // 'Not valid! example.com'

Check example directory to learn more:

Additional resources

Read about making invalid state unrepresentable: Making invalid state unrepresentable by Khalil Stemmler Why we should use exhaustive checks by Nicholas Fahrenkrog

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages