<commit_before>'use strict';

var helpers = require('./EventEmitter.helpers');

/**
 * @constructor
 * @param {Object} config object
 */
var EventEmitter = function (config) {
	if (this instanceof EventEmitter) {
		config = config || {};
		if (!helpers.checkObj(config)) throw new TypeError('Should be an object');
		this.evtHash= {};
		this.config = {
			maxListeners: config.maxListeners || 10,
			handlersDelay: config.handlersDelay || 0
		};
	} else {
		return new EventEmitter(config);
	}
};


/**
 * Add event listener
 * @param  {String} evt     event name
 * @param  {Function} handler
 * @return {Object}  EventEmitter object
 */
EventEmitter.prototype.on = function(evt, handler) {
	var self = this;
	var evts = self.evtHash;
	var config = self.config;

	if (!evts.hasOwnProperty(evt)) {
		evts[evt] = [handler];
	} else {
		if (evts[evt].length < config.maxListeners) {
			evts[evt].push(handler);
		} else {
			throw new Error('Can not add more than ' + config.maxListeners + ' handlers');
		}
	}

	return self;
};


// human hack
EventEmitter.prototype.addListener = EventEmitter.prototype.on;


/**
 * Add event that only can be executable once
 * @param  {String} evt     event name
 * @param  {Function} handler
 * @return {Object}   EventEmitter object
 */
EventEmitter.prototype.once = function(evt, handler) {
	var self = this;
	var config = self.config;
	var evtHash = self.evtHash;

	var listener = function (args) {
		args = ([]).slice.call(args);
		handler(args);
		self.removeListener(evt, listener);
	};

	if (!helpers.hasProperty(evtHash, evt)) {
		evtHash[evt] = [listener]
	} else {
		evtHash[evt].push(listener);
	}

	return self;
};


/**
 * Emit an event
 * @param  {String} evt
 * @return {Object} EventEmitter object
 */
EventEmitter.prototype.emit = function (evt) {
	var args = ([]).slice.call(arguments, 1);
	var evts = this.evtHash;
	if (helpers.hasProperty(evts, evt)) {
		evts[evt].forEach(function (handler) {
			handler(args);
		});
	} else {
		throw new Error('There is now such event handler');
	}

	return this;
};


/**
 * Return max listeners for single event length
 * @return {Int}
 */
EventEmitter.prototype.getMaxListeners = function () {
	return this.config.maxListeners;
};


/**
 * @param {Int} num
 */
EventEmitter.prototype.setMaxListeners = function (num) {
	if (typeof num === 'number' && num) {
		this.config.maxListeners = num;
	}

	return this;<commit_msg>:dog:<commit_after>'use strict';

var helpers = require('./EventEmitter.helpers');

/**
 * @constructor
 * @param {Object} config object
 */
var EventEmitter = function (config) {
	if (this instanceof EventEmitter) {
		config = config || {};
		if (!helpers.checkObj(config)) throw new TypeError('Should be an object');
		this.evtHash= {};
		this.config = {
			maxListeners: config.maxListeners || 10,
			handlersDelay: config.handlersDelay || 0
		};
	} else {
		return new EventEmitter(config);
	}
};


/**
 * Add event listener
 * @param  {String} evt     event name
 * @param  {Function} handler
 * @return {Object}  EventEmitter object
 */
EventEmitter.prototype.on = function(evt, handler) {
	var self = this;
	var evts = self.evtHash;
	var config = self.config;

	if (!evts.hasOwnProperty(evt)) {
		evts[evt] = [handler];
	} else {
		if (evts[evt].length < config.maxListeners) {
			evts[evt].push(handler);
		} else {
			throw new Error('Can not add more than ' + config.maxListeners + ' handlers');
		}
	}

	return self;
};


// human hack
EventEmitter.prototype.addListener = EventEmitter.prototype.on;


/**
 * Add event that only can be executable once
 * @param  {String} evt     event name
 * @param  {Function} handler
 * @return {Object}   EventEmitter object
 */
EventEmitter.prototype.once = function(evt, handler) {
	var self = this;
	var config = self.config;
	var evtHash = self.evtHash;

	var listener = function (args) {
		handler(args);
		self.removeListener(evt, listener);
	};

	if (!helpers.hasProperty(evtHash, evt)) {
		evtHash[evt] = [listener]
	} else {
		evtHash[evt].push(listener);
	}

	return self;
};


/**
 * Emit an event
 * @param  {String} evt
 * @return {Object} EventEmitter object
 */
EventEmitter.prototype.emit = function (evt, args) {
	if (args && !helpers.checkObj(args)) throw new TypeError('Should be an object');
	args = args || {};
	var evts = this.evtHash;
	if (helpers.hasProperty(evts, evt)) {
		evts[evt].forEach(function (handler) {
			handler(args);
		});
	} else {
		throw new Error('There is now such event handler');
	}

	return this;
};


/**
 * Return max listeners for single event length
 * @return {Int}
 */
EventEmitter.prototype.getMaxListeners = function () {
	return this.config.maxListeners;
};


/**
 * @param {Int} num
 */
EventEmitter.prototype.setMaxListeners = function (num) {
	if (typeof num === 'number' && num) {
		this.config.maxListeners = num;
	}

	return this;
{'fraction_non_alphanumeric': 0.14968087296685198, 'fraction_numerical': 0.001441218859378217, 'mean_word_length': 3.7395121951219514, 'pattern_counts': {'":': 0, '<': 5, '<?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': '191488', 'n_tokens_mistral': 1660, 'n_tokens_neox': 1665, 'n_words': 419}