objectvalidator 2.0.6

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 41

ObjectValidator #

Object-Validator for Dart

Usage #

Define your class you want to validate and implement the Verifiable<AnotherPerson> interface

class AnotherPerson implements Verifiable<AnotherPerson> {
    final int _age;

    AnotherPerson(this._age);

    int get age => _age;
    
    @override
    void validate({ifInvalid = throwViolationException}) => isAnotherPersonValid(this, ifInvalid: ifInvalid);
}

void isAnotherPersonValid(final AnotherPerson ap,
    { void Function(final AnotherPerson obj,final ObjectValidator ov) ifInvalid = throwViolationException }) {

    final ov = ObjectValidator();

    ov.verify(ap.age, Range(15, 55, onError: (final Range range)
        => (final invalidValue)
            => l10n("Age must be between ${range.start} and ${range.end} but was ${invalidValue.toString()}!")));

    ifInvalid(ap,ov);
}

If you want to check your object for being valid - it looks like this:

        test('> AnotherPerson should be between 15 and 55 years old', () {
            final person = AnotherPerson(55);
            expect(() => person.validate(), isNot(throwsException));
        }); 

        test('> AnotherPerson must be between 15 and 55 years old and fails', () {
            final person = AnotherPerson(99);
            expect(() => person.validate(), throwsException);

            try {
                person.validate();
            } on ViolationException catch(e) {
                violations.addAll(e.violations);
            }

            expect(violations.length, 1);
            expect(violations.first, "Age must be between 15 and 55 but was 99!");
        }); 

        test('> AnotherPerson - check with onError instead of Exception', () {
            final person = AnotherPerson(99);

            person.validate(ifInvalid: (final AnotherPerson ap, final ObjectValidator ov)
                => violations.addAll(ov.violations));

            expect(violations.length, 1);
            expect(violations.first, "Age must be between 15 and 55 but was 99!");
        }); 
        test('> AnotherPerson - check with global function', () {
            final person = AnotherPerson(99);

            // If you use 'isAnotherPersonValid' it's not necessary to 
            // implement the 'Verifiable<AnotherPerson>' interface for 'AnotherPerson' 
            isAnotherPersonValid(person,ifInvalid: (final AnotherPerson ap, final ObjectValidator ov)
                => violations.addAll(ov.violations));

            expect(violations.length, 1);
            expect(violations.first, "Age must be between 15 and 55 but was 99!");
        }); 
        

For more - check out my tests...

Features and bugs #

Please file feature requests and bugs at the issue tracker.

License #

Copyright 2019 Michael Mitterer, IT-Consulting and Development Limited,
Austrian Branch

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, 
software distributed under the License is distributed on an 
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
either express or implied. See the License for the specific language 
governing permissions and limitations under the License.

If this plugin is helpful for you - please (Circle) me.

Change Log for objectvalidator #

Object validation library

Unreleased #

Bugs #

  • Used generic for isAnotherPersonValid a1694db

Docs #

  • Readme shows how to use a global function for verification 26ae1f3

Refactor #

v2.0 - 2019-01-29

Feature #

  • ObjectValidator goes public 1dafd61

Refactor #

  • Description + Homepage was missing in pubspec.yaml ff1ad24
  • Added dryice as indirect dependency - needed by reflectable fc213dd

v1.0 - 2017-12-20

Docs #

  • Sample für die Verwendung der lib 08ab94a

v0.2 - 2017-12-07

Feature #

Docs #

  • Sample für die Verwendung der lib 08ab94a

This CHANGELOG.md was generated with Changelog for Dart

Use this package as a library

1. Depend on it

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


dependencies:
  objectvalidator: ^2.0.6

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:objectvalidator/objectvalidator.dart';
  
Version Uploaded Documentation Archive
2.0.6 Jan 29, 2019 Go to the documentation of objectvalidator 2.0.6 Download objectvalidator 2.0.6 archive
2.0.4 Jan 29, 2019 Go to the documentation of objectvalidator 2.0.4 Download objectvalidator 2.0.4 archive
2.0.2 Jan 29, 2019 Go to the documentation of objectvalidator 2.0.2 Download objectvalidator 2.0.2 archive
2.0.0 Jan 29, 2019 Go to the documentation of objectvalidator 2.0.0 Download objectvalidator 2.0.0 archive
1.0.7 Aug 30, 2018 Go to the documentation of objectvalidator 1.0.7 Download objectvalidator 1.0.7 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
95
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
65
Overall:
Weighted score of the above. [more]
41
Learn more about scoring.

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

  • Dart: 2.3.2
  • pana: 0.12.18

Platforms

Detected platforms: Flutter, web, other

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

Health suggestions

Fix lib/validators/IsValid.dart. (-1 points)

Analysis of lib/validators/IsValid.dart reported 2 hints:

line 7 col 51: Use = to separate a named parameter from its default value.

line 7 col 76: Use = to separate a named parameter from its default value.

Fix lib/validators/EMail.dart. (-0.50 points)

Analysis of lib/validators/EMail.dart reported 1 hint:

line 8 col 53: Use = to separate a named parameter from its default value.

Fix lib/validators/IsPositive.dart. (-0.50 points)

Analysis of lib/validators/IsPositive.dart reported 1 hint:

line 5 col 63: Use = to separate a named parameter from its default value.

Fix additional 11 files with analysis or formatting issues. (-3.50 points)

Additional issues in the following files:

  • lib/validators/MinLenght.dart (1 hint)
  • lib/validators/NotEmpty.dart (1 hint)
  • lib/validators/NotNull.dart (1 hint)
  • lib/validators/Password.dart (1 hint)
  • lib/validators/Pattern.dart (1 hint)
  • lib/validators/Range.dart (1 hint)
  • lib/validators/uuid.dart (1 hint)
  • lib/objectvalidator/ObjectValidator.dart (Run dartfmt to format lib/objectvalidator/ObjectValidator.dart.)
  • lib/objectvalidator/ViolationException.dart (Run dartfmt to format lib/objectvalidator/ViolationException.dart.)
  • lib/objectvalidator/interfaces.dart (Run dartfmt to format lib/objectvalidator/interfaces.dart.)
  • lib/validators.dart (Run dartfmt to format lib/validators.dart.)

Maintenance issues and suggestions

Support latest dependencies. (-5 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency.

The package description is too short. (-20 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.

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and objectvalidator.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
l10n >=2.0.15 <3.0.0 2.0.19
logging >=0.11.3 <1.0.0 0.11.3+2
matcher ^0.12.0 0.12.5
validate ^1.0.0 1.7.0
Transitive dependencies
analyzer 0.36.3
ansicolor 1.0.2
args 1.5.2
async 2.2.0
build_cli_annotations 1.1.0
charcode 1.1.2
collection 1.14.11
convert 2.1.1
crypto 2.0.6
csslib 0.16.0
dart_style 1.2.8
front_end 0.1.18
glob 1.1.7
html 0.14.0+2
intl 0.15.8
intl_translation 0.17.5
kernel 0.3.18
meta 1.1.7
optional 3.0.2+1
package_config 1.0.5
path 1.6.2
petitparser 2.3.0
pub_semver 1.4.2
source_span 1.5.5
stack_trace 1.9.3
string_scanner 1.0.4
term_glyph 1.1.0
typed_data 1.1.6
watcher 0.9.7+10
where 4.4.0 6.3.0
yaml 2.1.16
Dev dependencies
build_runner any
build_test any
build_web_compilers any
console_log_handler ^1.0.0 1.1.6
test any