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

A Dart validation library inspired by zod

Luthor #

Luthor is a validation library, heavily inspired by zod

Installation #

Dart:

dart pub add luthor

Flutter:

flutter pub add luthor

Usage #

import 'package:luthor/luthor.dart';

void main() {
  final schema = l.string();
  final validResult = schema.validate('hello');

  print(validResult.isValid); // true
  print(validResult.message); // null
  print(validResult.data); // 'hello'
  
  final invalidResult = schema.validate(123);

  print(invalidResult.isValid); // false
  print(invalidResult.message); // 'value must be a string'
  print(invalidResult.data); // 123
  
  // Strings can have extra validations that can be applied to them
  l.string().email();
  l.string().min(3);
  l.string().max(3);
  
  // You can chain validations together
  // This will validate that the string is between 3 and 30 characters long
  // and is required so null is not allowed
  final usernameValidator = l.string().min(3).max(30).required();
  
  // NOTE: all validators allow null values unless you call .required()
  // This is different to zod where all validators are required by default
}
13
likes
0
pub points
44%
popularity

Publisher

verified publisherex3.dev

A Dart validation library inspired by zod

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

More

Packages that depend on luthor