<commit_before>'use strict';
var Promise = require('es6-promise').Promise;
var errors = require('common-errors');
var path = require('path');
var fs = require('fs');

module.exports = function (value) {
  return new Promise(function(resolve, reject) {
    if (!value) {
      reject(new errors.ArgumentNullError('value'));
    }
    ['path'].forEach(function (key) {
      if(!value.hasOwnProperty(key) || !value[key]) {
        reject(new errors.ArgumentNullError(key));
      }
    });

    var filePath = path.normalize(value['path']);
    fs.readFile(filePath, 'utf8', function (error, data) {
      if (error) {
        reject(new errors.io.FileLoadError(filePath));
      }
      try {
        var contents = JSON.parse(data);
      } catch (error) {
        reject(new errors.Error('JSON.parse', error));
      }
      resolve(contents);
    });
  });
};<commit_msg>refactor(json): use if else block<commit_after>'use strict';
var Promise = require('es6-promise').Promise;
var errors = require('common-errors');
var path = require('path');
var fs = require('fs');

module.exports = function (value) {
  return new Promise(function(resolve, reject) {
    if (!value) {
      throw new errors.ArgumentNullError('value');
    }
    ['path'].forEach(function (key) {
      if(!value.hasOwnProperty(key) || !value[key]) {
        throw new errors.ArgumentNullError(key);
      }
    });

    var filePath = path.normalize(value['path']);
    fs.readFile(filePath, 'utf8', function (err, data) {
      if (err) {
        reject(new errors.io.FileLoadError(filePath));
      } else {
        try {
          var contents = JSON.parse(data);
        } catch (error) {
          reject(new errors.Error('JSON.parse', error));
        }
        resolve(contents);
      }
    });
  });
};
{'fraction_non_alphanumeric': 0.16750700280112044, 'fraction_numerical': 0.002240896358543417, 'mean_word_length': 2.933920704845815, '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': '4081083', 'n_tokens_mistral': 542, 'n_tokens_neox': 541, 'n_words': 113}