validate method

Future<List<String>> validate(
  1. Map values, {
  2. List<String>? properties,
  3. List<String>? groups,
  4. bool? whitelist = false,
})

Validates properties that have validators.

Accepts a map property which is validated again property validations. Validations can be filtered to specific properties using properties named parameter. Additionally, validations can also be filtered by validation groups.

Implementation

Future<List<String>> validate(Map values,
    {List<String>? properties,
    List<String>? groups,
    bool? whitelist: false}) async {
  List<String> errors = [];

  Iterable<PropertyValidator> filtered = this._validators.where((p) =>
      _isInProperties(p.property, properties) &&
      _isInGroups(p.groups, groups));

  for (PropertyValidator propertyValidator in filtered) {
    List<String> propertyErrors =
        await this._getPropertyValidatorErrors(propertyValidator, values);

    if (propertyErrors.length > 0) {
      errors.addAll(propertyErrors);
    }
  }

  return errors;
}