length function
- List<
IValidator> validators
Checks whether the given value has a length property and the length matches the validators
Implementation
IValidator length(List<IValidator> validators) => Validator((value) {
if (hasLengthProperty(value)) {
final result = all(validators).validate((value as dynamic).length);
return result.copyWith(
expectations: [
Expectation(
message: 'length ${result.expectations}',
value: value,
code: 'value.length_out_of_range',
data: {'length': (value as dynamic).length},
)
],
);
} else {
return expectation('${value.runtimeType} does not have a length property', value, null, 'logic.predicate_failed')
.toInvalidResult();
}
});