Skip to content

Latest commit

 

History

156 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


Logo

Zema

Schema validation for Dart, inspired by Zod.
Define schemas once, parse anywhere. All errors collected in a single pass.
Explore the docs »

Contribute · Report a bug · Request a feature

Zema is a type-safe schema validation library for Dart. Think Zod, but for Dart. Declare your data contracts once and reuse them across your whole application, whether it's parsing API responses, validating form inputs, or enforcing invariants at runtime.

# pubspec.yaml
dependencies:
  zema: ^0.6.0
import 'package:zema/zema.dart';

final userSchema = z.object({
  'name': z.string().min(2),
  'email': z.string().email(),
  'age': z.integer().gte(18).optional(),
});

// parse() returns the validated value or throws ZemaException
final user = userSchema.parse({
  'name': 'Alice',
  'email': 'alice@example.com',
});

// safeParse() never throws, returns ZemaResult<T>
final result = userSchema.safeParse(rawInput);

switch (result) {
  case ZemaSuccess(:final value):
    print(value['name']);
  case ZemaFailure(:final errors):
    for (final issue in errors) {
      print('${issue.path.join(".")}: ${issue.message}');
    }
}

Packages

Package Description CI Pub
zema Core validation library zema pub
zema_forms Flutter form widgets & controller zema_forms pub
zema_firestore Cloud Firestore integration via withConverter zema_firestore pub
zema_hive Hive local storage integration zema_hive pub
zema_standard_schema Standard Schema adapter for CLI frameworks & consumers zema_standard_schema pub

Why Zema?

  • Exhaustive error collection. No short-circuiting. Every issue is found and reported in one pass.
  • Composable. Schemas are just values. Combine, transform, and reuse them freely.
  • Type-safe. Full Dart 3 type inference. What you validate is what you get.
  • Fast. Competitive with hand-written validation. Benchmarks included.
  • Immutable. Every method returns a new schema. No side effects, no surprises.

Performance

Schemas defined once at the top level and reused, measured with benchmark_harness on an Apple M-series chip, Dart 3.x (JIT). Lower is better.

Scenario zema acanthis zard ez_validator luthor
String.email 0.81 µs 1.80 µs 3.83 µs 0.78 µs 74.7 µs
Integer.range 0.17 µs 0.47 µs 2.13 µs 0.33 µs 0.62 µs
Object.flat (4 fields) 4.37 µs 4.34 µs 13.4 µs 10.1 µs 92.8 µs
Object.failure (3 errors) 12.8 µs 6.27 µs 68.0 µs 11.3 µs 40.2 µs

Object.failure measures exhaustive error collection across all fields simultaneously, a core feature of Zema. Libraries that short-circuit on the first error will appear faster on this specific scenario.

Run the benchmarks yourself: make bench


Documentation

Full documentation is available at zema.meragix.dev.


Contributing

Contributions are welcome! Head over to CONTRIBUTING.md to get started.


License

This project is licensed under the MIT License. See the LICENSE file for details.

About

Type-safe schema validation for Dart, inspired by the simplicity and developer experience of Zod.

Resources

Contributing

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages