<commit_before>'use strict';

module.exports = function setupResolveDeep(Promise) {
  let promiseMap = Promise.map || function mapImpl(promiseList, functor) {
    return Promise.all(promiseList.map(promiseOrValue =>
      Promise.resolve(promiseOrValue).then(functor)
    ));
  };
  
  return Promise.resolveDeep = function resolveNestedPromises(obj) {
    return Promise.resolve(obj).then(obj => {
      if(Array.isArray(obj)) {
        return promiseMap(obj, resolveNestedPromises);
      }
      else if(obj && typeof obj === 'object' ) {
        let promisesToResolve = [];
        Object.keys(obj).map(key => {
          let promise = resolveNestedPromises(obj[key]).then(val => {
            obj[key] = val;
          });
          promisesToResolve.push(promise)
        });
        if(promisesToResolve.length) {
          return Promise.all(promisesToResolve).then(() => obj);
        }
      }
      return obj;
    });
  };
};<commit_msg>Use bluebird Promise.props<commit_after>'use strict';

module.exports = function setupResolveDeep(Promise) {
  let promiseMap = Promise.map || function mapImpl(promiseList, functor) {
    return Promise.all(promiseList.map(promiseOrValue =>
      Promise.resolve(promiseOrValue).then(functor)
    ));
  };
  let promiseProps = Promise.props || function propsImpl(obj) {
    let promisesToResolve = [];
    Object.keys(obj).map(key => {
      let promise = Promise.resolve(obj[key]).then(val => {
        obj[key] = val;
      });
      promisesToResolve.push(promise)
    });
    return Promise.all(promisesToResolve).then(() => obj);
  };
  
  return Promise.resolveDeep = function resolveNestedPromises(obj) {
    return Promise.resolve(obj).then(obj => {
      if(Array.isArray(obj)) {
        return promiseMap(obj, resolveNestedPromises);
      }
      else if(obj && typeof obj === 'object' ) {
        Object.keys(obj).map(key => {
          obj[key] = resolveNestedPromises(obj[key]);
        });
        return promiseProps(obj);
      }
      return obj;
    });
  };
};
{'fraction_non_alphanumeric': 0.14194184327254805, 'fraction_numerical': 0.0, 'mean_word_length': 2.8446969696969697, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, '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': '3965268', 'n_tokens_mistral': 608, 'n_tokens_neox': 618, 'n_words': 99}