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

function Dice(options) {
  var self = this;
  var defaults = {
    command: 'd20',
    throttles: {
      times: 100,
      repeat: 100,
      faces: 100,
      multiplier: 100,
      modifier: 100
    }
  };

  self.options = _.assign(defaults, options);

  self.data = {
    command: null,
    parsed: null,
    outcomes: [],
    text: [],
    verbose: []
  };

};

// validates that any value provided is less than our throttle value
Dice.prototype.throttle = function throttle() {
  var self = this;
  var parsed = self.data.parsed;
  var throttles = self.options.throttles;

  _.forOwn(parsed, function(value, key) {
    if (value && typeof value === 'number' && _.has(throttles, key) && value > throttles[key]) {
      throw new Error(key + ' (' + value + ') exceeds the limit of ' + throttles[key] + ' that has been imposed');
    }
  });

}

// rolls the die and returns the outcome
Dice.prototype.roll = function roll(faces) {
  if (typeof faces !== 'number') {
    throw new Error('`faces` must be a number');
  }
  var min = 1;
  var max = faces;
  return Math.floor(Math.random() * (max - min + 1)) + min;
}

// execute command
Dice.prototype.execute = function execute(command) {
  var self = this;
  var data = self.data;
  var parsed = self.parse(command);

  data.parsed = parsed;
  data.command = parsed.command;

  // throttle values provided
  self.throttle();<commit_msg>fixed issue where execute wasn't returning correct data for empty commands<commit_after>var _ = require('lodash');

function Dice(options) {
  var self = this;
  var defaults = {
    command: 'd20',
    throttles: {
      times: 100,
      repeat: 100,
      faces: 100,
      multiplier: 100,
      modifier: 100
    }
  };

  self.options = _.assign(defaults, options);

  self.data = {
    command: null,
    parsed: null,
    outcomes: [],
    text: [],
    verbose: []
  };

};

// validates that any value provided is less than our throttle value
Dice.prototype.throttle = function throttle() {
  var self = this;
  var parsed = self.data.parsed;
  var throttles = self.options.throttles;

  _.forOwn(parsed, function(value, key) {
    if (value && typeof value === 'number' && _.has(throttles, key) && value > throttles[key]) {
      throw new Error(key + ' (' + value + ') exceeds the limit of ' + throttles[key] + ' that has been imposed');
    }
  });

}

// rolls the die and returns the outcome
Dice.prototype.roll = function roll(faces) {
  if (typeof faces !== 'number') {
    throw new Error('`faces` must be a number');
  }
  var min = 1;
  var max = faces;
  return Math.floor(Math.random() * (max - min + 1)) + min;
}

// execute command
Dice.prototype.execute = function execute(command) {
  var self = this;
  var data = self.data;

  if (typeof command === 'undefined' || (typeof command === 'string' && !command.trim().length)) {
    command = self.options.command;
  }

  var parsed = self.parse(command);

  data.parsed = parsed;
  data.command = command;

  // throttle values provided
  self.throttle();
{'fraction_non_alphanumeric': 0.14332353901403852, 'fraction_numerical': 0.012406137773424747, 'mean_word_length': 2.933247753530167, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4562229', 'n_tokens_mistral': 1041, 'n_tokens_neox': 979, 'n_words': 291}