validators library

Top‑level built‑in validators and combinators.

Overview:

  • Stateless type validators: isString(), isInt(), isMap(), etc. Each has a cached $ alias ($isString, $isInt) for zero‑arg reuse.
  • Logical/comparison: isGt, isGte, isLt, isLte, isEq, isDeepEq.
  • Collection / structure helpers: contains, containsKey, listEach, eskema, eskemaList.
  • String/length: stringIsOfLength, stringContains, stringMatchesPattern.
  • Numeric/string parsing predicates: isIntString, isDoubleString, isNumString.
  • Date/time: isDate (parsable ISO 8601 string), isDateTime (actual DateTime type).
  • Combinators:
    • all([...]) AND composition (short‑circuits on first failure)
    • any([...]) OR composition (returns first success, else aggregates failures)
    • none([...]) succeeds only if every validator fails
    • not(v) logical negation
  • Null / presence semantics:
    • nullable(v) (or v.nullable()) => key must exist; value may be null
    • optional(v) (or v.optional()) => key may be missing; if present must pass v
  • Schema helpers:
    • eskema({...}) for Map field validation (propagates nested error paths)
    • eskemaList([...]) positional list schema
    • listEach(v) uniform element validation
  • Utility wrappers:
    • withError(child, message) replace expectation message

Value flow:

  • Basic validators are pure predicates that attach Expectations.
  • Combinators compose results; all stops early, any returns on first pass.
  • Transformers (defined separately) can precede these validators; all will forward transformed values to subsequent validators.

Conventions:

  • Prefer $isType constants for zero‑arg validators in hot paths.
  • Use isTypeOrNull<T>() for union of a type plus null.
  • For collection equality use isDeepEq instead of isEq on lists/maps/sets.

See README for detailed examples and nullable vs optional explanation.

This library is intentionally minimal: advanced behaviors (async validators, transformers, refiners) live in their own files to keep this surface stable.

Properties

$isBool IValidator
final
$isDate IValidator
final
$isDateTime IValidator
final
$isDouble IValidator
final
$isDoubleString IValidator
final
$isEmail IValidator
final
$isEnum IValidator
final
$isFunction IValidator
final
$isFuture IValidator
final
$isInt IValidator
final
$isIntString IValidator
final
$isIterable IValidator
final
$isList IValidator
final
$isLowerCase IValidator
final
$isMap IValidator
final
$isNull IValidator
final
$isNumber IValidator
final
$isNumString IValidator
final
$isRecord IValidator
final
$isSet IValidator
final
$isStrictUrl IValidator
final
$isString IValidator
final
$isSymbol IValidator
final
$isUpperCase IValidator
final
$isUrl IValidator
final
$isUuidV4 IValidator
final
$listEmpty IValidator
final
$listNotEmpty IValidator
final
$stringEmpty IValidator
final
$stringNotEmpty IValidator
final

Functions

all(List<IValidator> validators) IValidator
Passes the test if all of the Validators are valid, and fails if any of them are invalid
any(List<IValidator> validators) IValidator
Passes the test if any of the Validators are valid, and fails if any are invalid
contains<T>(T item) IValidator
Checks whether the given value contains the item value of type T
containsKey(String key) IValidator
eskema(Map<String, IValidator> mapEskema) IValidator
Returns a Validator that checks a value against a Map eskema that declares a validator for each key.
eskemaList<T>(List<IValidator> eskema) IValidator
Returns a Validator that checks a value against the eskema provided, the eskema defines a validator for each item in the list
eskemaStrict(Map<String, IValidator> schema) IValidator
Returns a Validator that checks a value against a Map eskema and fails if any keys exist in the map that are not defined in the schema.
isBool() IValidator
Returns a IValidator that checks if the given value is a bool For better performance and readability, use the $isBool variable directly.
isDate() IValidator
Checks whether the given value is a valid DateTime formatted String
isDateTime() IValidator
Returns a IValidator that checks if the given value is a DateTime For better performance and readability, use the $isDateTime variable directly.
isDeepEq<T>(T otherValue) IValidator
Checks whether the given value is equal to the otherValue value of type T
isDouble() IValidator
Returns a IValidator that checks if the given value is a double For better performance and readability, use the $isDouble variable directly.
isDoubleString() IValidator
Validates that the String can be parsed as a double (e.g. '123.45', '-1e3')
isEmail() IValidator
Validates that the String is a valid email address.
isEmpty() IValidator
isEnum() IValidator
Returns a IValidator that checks if the given value is a Enum For better performance and readability, use the $isEnum variable directly.
isEq<T>(T otherValue) IValidator
Checks whether the given value is equal to the otherValue value of type T
isFunction() IValidator
Returns a IValidator that checks if the given value is a Function For better performance and readability, use the $isFunction variable directly.
isFuture<T>() IValidator
Returns a IValidator that checks if the given value is a Future For better performance and readability, use the $isFuture variable directly.
isGt(num min) IValidator
Checks whether the given value is greater than min
isGte(num min) IValidator
Checks whether the given value is greater or equal to min
isInRange(num min, num max) IValidator
Checks whether the given numeric value is within the range min, max (inclusive).
isInt() IValidator
Returns a IValidator that checks if the given value is a int For better performance and readability, use the $isInt variable directly.
isIntString() IValidator
Validates that the String can be parsed as an int (e.g. '123', '-42')
isIterable<T>() IValidator
Returns a IValidator that checks if the given value is a Iterable For better performance and readability, use the $isIterable variable directly.
isList<T>() IValidator
Returns a IValidator that checks if the given value is a List For better performance and readability, use the $isList variable directly.
isLowerCase() IValidator
Validates that it's a String and it's lowecase
isLt(num max) IValidator
Checks whether the given value is less than max
isLte(num max) IValidator
Checks whether the given value is less than or equal max
isMap<K, V>() IValidator
Returns a IValidator that checks if the given value is a Map For better performance and readability, use the $isMap variable directly.
isNotEmpty() IValidator
Checks whether the given value is not empty
isNull() IValidator
Returns a IValidator that checks if the given value is null For better performance and readability, use the $isNull variable directly.
isNumber() IValidator
Returns a IValidator that checks if the given value is a num For better performance and readability, use the $isNumber variable directly.
isNumString() IValidator
Validates that the String can be parsed as a num (int or double)
isOneOf<T>(List<T> options) IValidator
Checks whether the given value is one of the options values of type T
isRecord() IValidator
Returns a IValidator that checks if the given value is a Record
isSet<T>() IValidator
Returns a IValidator that checks if the given value is a Set For better performance and readability, use the $isSet variable directly.
isStrictUrl() IValidator
isString() IValidator
Returns a IValidator that checks if the given value is a String For better performance and readability, use the $isString variable directly.
isSymbol() IValidator
Returns a IValidator that checks if the given value is a Symbol For better performance and readability, use the $isSymbol variable directly.
isType<T>() IValidator
Returns a Validator that checks if the given value is the correct type
isTypeOrNull<T>() IValidator
Returns a Validator that checks if the given value is the correct type
isUpperCase() IValidator
Validates that it's a String and it's uppercase
isUrl({bool strict = false}) IValidator
Validates that the String is a valid URL. By it uses non-strict validation (like "example.com").
isUuidV4() IValidator
Validates that the String is a valid UUID (v4).
length(List<IValidator> validators) IValidator
Checks whether the given value has a length property and the length matches the validators
listContains<T>(dynamic item) IValidator
Validates that the List contains item
listEach(IValidator itemValidator) IValidator
Returns a Validator that runs itemValidator for each item in the list
listEmpty<T>() IValidator
Validate that the list is empty
listIsOfLength(int size) IValidator
Validates that it's a list of size length
listLength<T>(List<IValidator> validators) IValidator
Validates that it's a List and the length matches the validators
none(List<IValidator> validators) IValidator
Passes the test if none of the validators pass
not(IValidator validator) IValidator
Passes the test if the passed in validator is not valid
nullable(IValidator validator) IValidator
If the field is not present (null) it will be considered valid If you want to allow empty strings as valid, use optional instead
optional(IValidator validator) IValidator
If the field is not present, it will be considered valid, if present, it executes the validator. It's different from nullable in that it also checks for empty strings
stringContains(String str) IValidator
Validates that the String contains str
stringEmpty<T>() IValidator
Validate that it's a String and the string is empty
stringIsOfLength(int size) IValidator
Validates that the String's length is the same as the provided size
stringLength(List<IValidator> validators) IValidator
Validates that the String's length matches the validators
stringMatchesPattern(Pattern pattern, {String? error}) IValidator
Validates that the String matches the provided pattern
throwInstead(IValidator validator) IValidator
Returns a Validator that throws a ValidatorFailedException instead of returning a result
validator(bool comparisonFn(dynamic value), Expectation errorFn(dynamic value)) Validator<Result>
when(IValidator condition, {required IValidator then, required IValidator otherwise}) IValidator
Creates a conditional validator. It's conditional based on some other field in the eskema.
withExpectation(IValidator child, Expectation error) IValidator
Returns a IValidator that wraps the given child validator and adds the provided error message to the result if the validation fails. Preserves the underlying child's code and data (if the child failed). See docs/expectation_codes.md.