<commit_before>require('object.assign').shim();
var isEmpty = require('lodash.isempty');
var flatten = require('lodash.flatten');
var ValidationStrategy = require('./JoiValidationStrategy');

var ValidationFactory = Object.assign({
  isValid: function(errors, key) {
    if (isEmpty(errors)) {
      return true;
    } else {
      return key ? isEmpty(errors[key]) : isEmpty(errors);
    }
  },

  getValidationMessages: function(errors, key) {
    if (isEmpty(errors)) {
      return [];
    } else {
      if (key) {
        return errors[key] || [];
      } else {
        return flatten(Object.keys(errors).map(function(key) { return errors[key] || []; }));
      }
    }
  }
}, ValidationStrategy);

module.exports = ValidationFactory;<commit_msg>Simplify `ValidationFactory` even more<commit_after>require('object.assign').shim();
var isEmpty = require('lodash.isempty');
var flatten = require('lodash.flatten');
var ValidationStrategy = require('./JoiValidationStrategy');

var ValidationFactory = Object.assign({
  getValidationMessages: function(errors, key) {
    errors = errors || {};
    if (isEmpty(errors)) {
      return [];
    } else {
      if (key) {
        return errors[key] || [];
      } else {
        return flatten(Object.keys(errors).map(function(key) { return errors[key] || []; }));
      }
    }
  },

  isValid: function(errors, key) {
    return isEmpty(this.getValidationMessages(errors, key));
  },
}, ValidationStrategy);

module.exports = ValidationFactory;
{'fraction_non_alphanumeric': 0.1590909090909091, 'fraction_numerical': 0.0, 'mean_word_length': 3.6203703703703702, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5680327', 'n_tokens_mistral': 450, 'n_tokens_neox': 434, 'n_words': 86}