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 failsnot(v)logical negation
- Null / presence semantics:
nullable(v)(orv.nullable()) => key must exist; value may be nulloptional(v)(orv.optional()) => key may be missing; if present must passv
- Schema helpers:
eskema({...})for Map field validation (propagates nested error paths)eskemaList([...])positional list schemalistEach(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;
allstops early,anyreturns on first pass. - Transformers (defined separately) can precede these validators;
allwill forward transformed values to subsequent validators.
Conventions:
- Prefer
$isTypeconstants for zero‑arg validators in hot paths. - Use
isTypeOrNull<T>()for union of a type plus null. - For collection equality use
isDeepEqinstead ofisEqon 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
itemvalue of typeT -
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
boolFor 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
DateTimeFor better performance and readability, use the $isDateTime variable directly. -
isDeepEq<
T> (T otherValue) → IValidator -
Checks whether the given value is equal to the
otherValuevalue of typeT -
isDouble(
) → IValidator -
Returns a IValidator that checks if the given value is a
doubleFor 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
EnumFor better performance and readability, use the $isEnum variable directly. -
isEq<
T> (T otherValue) → IValidator -
Checks whether the given value is equal to the
otherValuevalue of typeT -
isFunction(
) → IValidator -
Returns a IValidator that checks if the given value is a
FunctionFor better performance and readability, use the $isFunction variable directly. -
isFuture<
T> () → IValidator -
Returns a IValidator that checks if the given value is a
FutureFor 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
intFor 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
IterableFor better performance and readability, use the $isIterable variable directly. -
isList<
T> () → IValidator -
Returns a IValidator that checks if the given value is a
ListFor 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
MapFor 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
nullFor better performance and readability, use the $isNull variable directly. -
isNumber(
) → IValidator -
Returns a IValidator that checks if the given value is a
numFor 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
optionsvalues of typeT -
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
SetFor better performance and readability, use the $isSet variable directly. -
isStrictUrl(
) → IValidator -
isString(
) → IValidator -
Returns a IValidator that checks if the given value is a
StringFor better performance and readability, use the $isString variable directly. -
isSymbol(
) → IValidator -
Returns a IValidator that checks if the given value is a
SymbolFor 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
itemValidatorfor 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
sizelength -
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
childvalidator and adds the providederrormessage to the result if the validation fails. Preserves the underlying child'scodeanddata(if the child failed). See docs/expectation_codes.md.