<commit_before>dice = {
	version: "0.7.0",

	roll: function(str, scope){
		var parsed = dice.parse.parse(str);
		var evaled = dice.eval.eval(parsed, scope);
		return evaled;
	},

	statistics: function(str, scope, samples){
		if(typeof(scope) == "number"){
			samples = scope;
			scope = {};
		}
		scope = scope || {};
		samples = samples || 1000;
		var resultSet = [];
		var i;
		for(i = 0; i < samples; i++){
			resultSet.push(dice.roll(str, scope));
		}
		var mean = resultSet.reduce(function(n, acc){ return n + acc; }, 0) / samples;
		var min = resultSet.reduce(function(n, acc){ return n < acc ? n : acc; }, resultSet[0]);
		var max = resultSet.reduce(function(n, acc){ return n > acc ? n : acc; }, resultSet[0]);
		return {
			'results': resultSet,
			'mean': mean,
			'min': parseInt(min.toFixed()),
			'max': parseInt(max.toFixed())
		};
	},

	stringify_expression: function(evaled_op){
		var sub = dice.stringify(evaled_op.expression);
		var prefix = evaled_op.op[0];
		if(prefix === 'p'){
			prefix = '';
		}
		
		return prefix + "( " + sub + " )";
	},

	stringify_op: function(evaled_op){
		var rs = dice.stringify(evaled_op.rightSide);
		var ls = dice.stringify(evaled_op.leftSide);
		return rs + ' ' + evaled_op.op + ' ' + ls;
	},

	stringify_rolls: function(evaled_roll){
		var minStr = evaled_roll.min > 1 ? evaled_roll.min + '..' : '';
		var preamble = evaled_roll.x + evaled_roll.mode + minStr + evaled_roll.max + ':[';
		return preamble + evaled_roll.rolls.join(', ') + ']';
	},

	stringify: function(evaled){
		if(evaled.expression){
			return dice.stringify_expression(evaled);
		}

		if(evaled.op){
			return dice.stringify_op(evaled);
		}

		if(evaled.rolls){
			return dice.stringify_rolls(evaled);
		}

		return evaled.toString();
	}

};<commit_msg>Added support for node module-ness.<commit_after>var dice = {};
var parse = require('./parser.js');
var eval = require('./evaluate.js');
dice.parse = parse.parse;
dice.eval = eval.eval;
dice.version = "0.7.0";

function roll(str, scope){
	var parsed = parse.parse(str);
	var evaled = eval.eval(parsed, scope);
	return evaled;
};

dice.roll = roll;

dice.statistics = function(str, scope, samples){
	if(typeof(scope) == "number"){
		samples = scope;
		scope = {};
	}
	scope = scope || {};
	samples = samples || 1000;
	var resultSet = [];
	var i;
	for(i = 0; i < samples; i++){
		resultSet.push(roll(str, scope));
	}
	var mean = resultSet.reduce(function(n, acc){ return n + acc; }, 0) / samples;
	var min = resultSet.reduce(function(n, acc){ return n < acc ? n : acc; }, resultSet[0]);
	var max = resultSet.reduce(function(n, acc){ return n > acc ? n : acc; }, resultSet[0]);
	return {
		'results': resultSet,
		'mean': mean,
		'min': parseInt(min.toFixed()),
		'max': parseInt(max.toFixed())
	};
};

function stringify_expression(evaled_op){
	var sub = stringify(evaled_op.expression);
	var prefix = evaled_op.op[0];
	if(prefix === 'p'){
		prefix = '';
	}
	
	return prefix + "( " + sub + " )";
};

function stringify_op(evaled_op){
	var rs = stringify(evaled_op.rightSide);
	var ls = stringify(evaled_op.leftSide);
	return rs + ' ' + evaled_op.op + ' ' + ls;
};

function stringify_rolls(evaled_roll){
	var minStr = evaled_roll.min > 1 ? evaled_roll.min + '..' : '';
	var preamble = evaled_roll.x + evaled_roll.mode + minStr + evaled_roll.max + ':[';
	return preamble + evaled_roll.rolls.join(', ') + ']';
};

function stringify(evaled){
	if(evaled.expression){
		return stringify_expression(evaled);
	}

	if(evaled.op){
		return stringify_op(evaled);
	}

	if(evaled.rolls){
		return stringify_rolls(evaled);
	}

	return evaled.toString();
};

dice.stringify = stringify;

var k;
for(k in dice){
    exports[k] = dice[k];
}

return dice;
{'fraction_non_alphanumeric': 0.18032345013477089, 'fraction_numerical': 0.007008086253369272, 'mean_word_length': 3.90224570673712, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2581841', 'n_tokens_mistral': 1491, 'n_tokens_neox': 1387, 'n_words': 294}