pro_validator 3.0.0
pro_validator: ^3.0.0 copied to clipboard
Composable, callable validators for Dart and Flutter: text, number and date validators, one-line custom checks, whole-model validation and 40+ string format checkers.
Changelog #
3.0.0 #
Major redesign. One deep core, typed validators for numbers and dates, a
composition story that works for every value type, and an experimental
whole-model validation layer. The library is split into focused modules
(core / text / number / date / model / string).
Breaking changes #
- One base class. Every validator now extends
Validator<T>, which handles empty input once:call(T?)skipsnull(and, for text, blank strings) whenignoreEmptyValuesistrue— the default. Concrete validators implementisValidonly for real, non-empty values. ignoreEmptyValues: falsenow uniformly means "empty input is an error". Previously text validators ranisValidon the empty string, so e.g. a strictMaxLengthValidatorcould accept''.MultiValidatoris replaced byValidatorGroup<T>, which groups validators of any one type:MultiValidator(validators: [...])→ValidatorGroup([...]).errors()and the&operator work as before — and now also fornum/DateTimevalidators.MatchValidatornow compares values with==instead ofidentical, so two equal runtime strings (e.g. two form fields) correctly match. Its signature iscall(Object?, Object?).RequiredValidatornow correctly fails on empty andnullinput (previously it was short-circuited and returnednull).MultiValidator.callreturned the failing validator's re-readerror;ValidatorGroup.callreturns the failing validator's actual result.
Added #
- Number validators (
Validator<num>):MinValidator,MaxValidator,RangeValidator,PositiveValidator,NegativeValidator,MultipleOfValidator(with floattolerance),EvenValidator,OddValidator. - Date validators (
Validator<DateTime>):AfterValidator,BeforeValidator,DateRangeValidator,PastValidator,FutureValidator(with an injectableclockfor deterministic tests). - Whole-model validation (experimental):
ModelValidator<T>withruleFor(key), chained.check(selector, validator), cross-field.must(predicate), conditions.when/.unlessand rule-sets.only. Returns aValidationResultkeyed by field. ValidatorGroup<T>+ the&operator to compose validators of any type without building a list manually.PredicateValidator<T>— build a validator from anybool Function(T)without declaring a class.Patterns.x.toValidator(error: ...)— turn any of the 40+ built-inPatternsentries into aPatternValidator, reusing its compiled regex.CreditCardValidator— scheme regex plus Luhn checksum.OneOfValidator,FileExtensionValidator,ConditionalValidator.PatternValidator.fromRegExpto reuse a pre-compiledRegExp(any flags); string-built patterns are compiled once and cached.- Public
Patternsenum,isX(String)checkers andStringextensions ('x'.isEmail,isLuhn(...), etc.), now exported from the package.
Fixed #
iban,swiftOrBicandvatare now case-insensitive, so lowercase input (as pasted from statements/invoices) is accepted, consistent with the other case-insensitive formats (email/uuid/macAddress/hexColor) and with how validator.js / schwifty / form_builder_validators handle these. Previously only uppercase matched.phoneNumberaccepts grouped international layouts (+44 20 8759 9036,+380 (50) 688-88-88): the pattern is now E.164-style — an optional leading+and 7–15 digits with spaces/dots/dashes/parentheses as separators — instead of the old US-centric 3-3-4 shape.emailRFC5322was compiled case-sensitively but its body only matched lowercase[a-z], so any address with an uppercase letter (Example@Example.com) was wrongly rejected. It is now case-insensitive, like the simpleemailpattern.iso8601DateTimeno longer accepts impossible field values (month 13, day 40, hour 25, minute/second 99); the date/time components are now range-bounded like thedate/time/dateTimepatterns.MinLengthValidator/MaxLengthValidator/LengthRangeValidatornow trim the value before counting length, so surrounding whitespace can no longer pad a value past the minimum (MinLengthValidator(min: 8)no longer accepts"a ") nor push it over the maximum.HasANumberValidatornow recognises any Unicode decimal digit (\p{Nd}, e.g. Arabic-Indic٥, fullwidth5), consistent with the Unicode-aware uppercase/lowercase checkers.CreditCardValidatornow strips only spaces and dashes (the documented separators) before checking, instead of every non-digit, so a value with embedded letters (4111abcd…) is correctly rejected rather than silently reduced to a valid number.emailRFC5322no longer backtracks catastrophically (ReDoS). Its domain grammar wrongly allowed a.inside a label while also using.as the label separator, so an input likea@a.a.a.…blew up exponentially (~22s at 52 chars). Dots now only separate labels; matching is linear.iso8601DateTimenow accepts a valid offset-less timestamp (a localDateTime.toIso8601String()) and basic/hour-only offsets (+0200,-05); previously it required aZor extended (+02:00) offset and rejected the rest.hexColornow requires the leading#, so ordinary hex-lettered words ("decade","facade") no longer validate as colors.decimalnow rejects a trailing dot with no fraction ("123.").- Corrected swapped latitude/longitude doc comments and email pattern docs.
Removed #
- The free-function
hasMatch(pattern, input)helper (it recompiled the regex on every call and duplicatedPatterns/PatternValidator). UsePatterns.x.hasMatch,PatternValidator, or aRegExpdirectly.
2.0.1 #
- Update dependencies.
2.0.0 #
- Bump sdk version to ^3.0.0.
1.1.1 #
- Fix - skip checks if value is null.
1.1.0 #
- Breaking changes - ignoreEmptyValues true by default.
1.0.1 #
- Added access to ignoreEmptyValues field.
1.0.0+1 #
- Fix readme.
1.0.0 #
- Initial version.