schemani 0.0.1-alpha.3

  • Readme
  • Changelog
  • Example
  • Installing
  • new60

schemani #

Simple and extensible data schema validation for Dart and Flutter. If you know Yup and Laravel Validation you will feel like home using this package.

Please note that the schemani/formini packages are under development. There are still some issues to resolve before this has any help for real use cases. #roadmap

Usage #

import 'package:schemani/schemani.dart';

main() {
  const userSchema = MapSchema({
    'name': [Required()],
    'email': [Required(), Email()],
  });

  try {
    userSchema.validate({
      'name': null,
      'email': 'foo example.org',
    });
  } on MapValidationException catch (e) {
    e.exceptions.forEach((field, exception) {
      print('$field => $exception');
    });
  }
}

Will throw MapValidationException only once combining the inner ValidationExceptions.

flutter: name => Required field
flutter: email => Invalid email address

Usage with formini

Use schemani_formini package for validating formini values using schemas. Or just copy the one simple file to your project.

API reference #

https://pub.dev/documentation/schemani

Contributing #

Please open an issue or pull request in GitHub. Any help and feedback is much appreciated.

flutter pub pub run test

Licence #

MIT

Roadmap #

  • ListSchema
  • Rules
    • References to another fields inside a rule
    • More basic rules (min, max, between, url, etc...)
  • i18n ValidationException.toString()
  • Benchmarking

[0.0.1-alpha.3] - 2019/09/26

  • Add support for nested MapSchemas

[0.0.1-alpha.2] - 2019/09/26

  • Remove flutter dependencies

[0.0.1-alpha.1] - 2019/09/23

  • First release

example/schemani.dart

import 'package:schemani/schemani.dart';

void main() {
  const userSchema = MapSchema({
    'name': [Required()],
    'email': [Required(), Email()],
    'profile': MapSchema({
      'avatar': [Required()],
    }),
  });

  try {
    userSchema.validate({'name': null, 'email': 'example.org'});
  } on MapValidationException catch (e) {
    handle(e);
  }
}

/// MapValidationExceptions handler.
handle(MapValidationException e) {
  e.exceptions.forEach((field, exception) {
    if (exception is MapValidationException) {
      return handle(exception);
    }

    print('$field => $exception');
  });
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  schemani: ^0.0.1-alpha.3

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:schemani/schemani.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
32
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
70
Overall:
Weighted score of the above. [more]
60
Learn more about scoring.

We analyzed this package on Oct 9, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:schemani/schemani.dart.

Maintenance suggestions

The package description is too short. (-15 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Package is pre-release. (-5 points)

Pre-release versions should be used with caution; their API can change in breaking ways.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
Dev dependencies
test ^1.8.0