objectvalidator 2.0.6

  • Readme
  • Changelog
  • Installing
  • 10

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

Alternatively, your editor might support 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';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
0
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
50
Overall:
Weighted score of the above. [more]
10
Learn more about scoring.

We analyzed this package on Oct 16, 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:

Error(s) prevent platform classification:

Make sure dartfmt successfully runs on your package's source files.

Analysis issues and suggestions

Make sure dartfmt successfully runs on your package's source files.

Running dartfmt -n . failed with the following output:

Exception: dartfmt on lib/ failed with exit code 65
Could not format because the source could not be parsed:

line 10, column 35 of lib/objectvalidator/interfaces.dart: Function-typed parameters can't specify 'const', 'final' or 'var' in place of a return type.
  ╷
10│     void validate({ void Function(final T obj,final ObjectValidator ov) ifInvalid = throwViolationException });
  │                                   ^^^^^
  ╵
line 10, column 47 of lib/objectvalidator/interfaces.dart: Function-typed parameters can't specify 'const', 'final' or 'var' in place of a return type.
  ╷

Health issues and suggestions

Fix lib/objectvalidator/interfaces.dart. (-43.75 points)

Analysis of lib/objectvalidator/interfaces.dart failed with 2 errors:

line 10 col 35: Function-typed parameters can't specify 'const', 'final' or 'var' in place of a return type.

line 10 col 47: Function-typed parameters can't specify 'const', 'final' or 'var' in place of a return type.

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 additional 8 files with analysis or formatting issues. (-4 points)

Additional issues in the following files:

  • lib/validators/IsPositive.dart (1 hint)
  • 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)

Maintenance issues and suggestions

Fix platform conflicts. (-20 points)

Error(s) prevent platform classification:

Make sure dartfmt successfully runs on your package's source files.

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.38.5
ansicolor 1.0.2
args 1.5.2
async 2.4.0
build_cli_annotations 1.1.0
charcode 1.1.2
collection 1.14.12
convert 2.1.1
crypto 2.1.3
csslib 0.16.1
dart_style 1.3.1
front_end 0.1.27
glob 1.2.0
html 0.14.0+3
intl 0.15.8 0.16.0
intl_translation 0.17.7
js 0.6.1+1
kernel 0.3.27
meta 1.1.7
node_interop 1.0.3
node_io 1.0.1+2
optional 3.1.0
package_config 1.1.0
path 1.6.4
pedantic 1.8.0+1
petitparser 2.4.0
pub_semver 1.4.2
source_span 1.5.5
stack_trace 1.9.3
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
watcher 0.9.7+12
where 4.4.0 6.4.0
yaml 2.2.0
Dev dependencies
build_runner any
build_test any
build_web_compilers any
console_log_handler ^1.0.0 1.1.6
test any