<commit_before>const _ = require('lodash');

function mapValidationErrors(errors, values) {
  const valueMap = Object.keys(values).reduce((prev, curr) => {
    const val = {};
    val[curr] = {
      value: values[curr],
    };

    return Object.assign({}, prev, val);
  }, {});

  const errorMap = Object.keys(errors).reduce((prev, curr) => {
    if (errors[curr].name && errors[curr].name === 'ValidatorError') {
      const val = {};
      val[curr] = {
        message: errors[curr].message,
      };

      return Object.assign({}, prev, val);
    }
  }, {});

  return _.merge({}, errorMap, valueMap);
}

module.exports = mapValidationErrors;<commit_msg>controller helper: parse mongoose path to object<commit_after>const qs = require('qs');

function mapValidationErrors(errors) {
  const errorString = Object.keys(errors).reduce((prev, curr) => {
    if (errors[curr].name && errors[curr].name === 'ValidatorError') {
      return `${prev}${curr}=${errors[curr].message}&`;
    }
  }, '');

  const parsedError = qs.parse(errorString, {
    allowDots: true,
  });

  return parsedError;
}

module.exports = mapValidationErrors;
{'fraction_non_alphanumeric': 0.17869718309859156, 'fraction_numerical': 0.0, 'mean_word_length': 3.6790123456790123, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '1208861', 'n_tokens_mistral': 356, 'n_tokens_neox': 352, 'n_words': 70}