<commit_before>/*
* Very simple Action API
*/
var actions = {
	_uid: 0
};
/**
* Invokes callbacks for all given actions
*/
function doAction(ident) {
	var ns = 'global';
	if( typeof ident == 'object') {
		ns = ident.ns;
		ident = ident.name;
	} else if( typeof ident == 'string') {
		var index = ident.indexOf(':');
		if(index != -1) {
			ns = ident.slice(0, index);
			ident = ident.slice(index + 1, ident.length);
		}
	}
	log(ns + ':' + ident, arguments);
	if(actions[ns] && actions[ns][ident]) {
		var callbacks = actions[ns][ident];
		var args = Array.prototype.slice.call(arguments).splice(1);
		for(var i = 0; i < callbacks.length; i++) {
			callbacks[i].callback.apply(callbacks[i].thisArg, args);
		}
	}
}

/**
* Registers an action with optional this arg
*/
function addAction(ident, callback, thisArg, priority) {
	function indexOf(haystack, callback) {
		for(var i = 0; i < haystack.length; i++) {
			if(haystack[i].callback == callback && haystack[i].thisArg == thisArg) {
				return i;
			}
		}
		return -1;
	}

	var ns = 'global';
	if( typeof ident == 'object') {
		ns = ident.ns;
		ident = ident.name;
	} else if( typeof ident == 'string') {
		var index = ident.indexOf(':');
		if(index != -1) {
			ns = ident.slice(0, index);
			ident = ident.slice(index + 1, ident.length);
		}
	}
	var args = {
		callback : callback,
		thisArg : thisArg ? thisArg : window,
		priority : priority ? priority : 10,
		id: actions._uid++
	};
	if(actions[ns] && actions[ns][ident]) {
		if(indexOf(actions[ns][ident], callback) == -1) {
			actions[ns][ident].push(args);
			actions[ns][ident].sort(function(a, b) {
				return (a.priority > b.priority) - (a.priority < b.priority);
			})
		} else {
			return actions[ns][ident][indexOf(actions[ns][ident], callback)].id;
		}
	} else {
		if(!actions[ns]) {
			actions[ns] = {};
		}
		actions[ns][ident] = new Array(args);
	}
	return args.id;
}

/**
* Removes an action
*/
function removeAction(ident, callback) {
	function indexOf(haystack, callback) {
		var func = typeof callback === 'function';
		for(var i = 0; i < haystack.length; i++) {
			if(func) {
				if(haystack[i].callback == callback) {
					return i;
				}
			} else {
				if(haystack[i].id == callback) {
					return i;
				}
			}
		}
		return -1;
	}

	var ns = 'global';
	if( typeof ident == 'object') {
		ns = ident.ns;
		ident = ident.name;
	} else if( typeof ident == 'string') {
		var index = ident.indexOf(':');
		if(index != -1) {
			ns = ident.slice(0, index);
			ident = ident.slice(index + 1, ident.length);
		}
	}
	if(actions[ns] && actions[ns][ident]) {
		if(callback == undefined) {
			delete actions[ns][ident];
			return;
		}
		var index = indexOf(actions[ns][ident], callback);
		if(index != -1) {
			actions[ns][ident].splice(index, 1);
		}
	}
}<commit_msg>cleanup<commit_after>/**
 * Actions namespace object.
 * @type {object}
 */
var actions = {
	hash: {
		_uid: 0
	}
};

/**
 * Helps gettings the right namespace and name
 * @param {string|object} ident Identifier of the action, can have a namespace e.g. 'namespace:action' as string or an object with 'ns' and 'name' keys.
 */
actions._split = function(ident) {
	var split = {
		ns: 'global',
		name: ident
	}
	if( typeof ident == 'object') {
		split.ns = ident.ns;
		split.name = ident.name;
	} else if( typeof ident == 'string') {
		var index = ident.indexOf(':');
		if(index != -1) {
			split.ns = ident.slice(0, index);
			split.name = ident.slice(index + 1, ident.length);
		}
	}
	return split;
}

/**
* Invokes action
* @param {string|object} ident Identifier of the action, can have a namespace e.g. 'namespace:action' as string or an object with 'ns' and 'name' keys.
*/
actions.doAction = function(ident) {
	ident = actions._split(ident);
	log(ident.ns + ':' + ident.name, arguments);
	if(actions.hash[ident.ns] && actions.hash[ident.ns][ident.name]) {
		var callbacks = actions.hash[ident.ns][ident.name];
		var args = Array.prototype.slice.call(arguments).splice(1);
		for(var i = 0; i < callbacks.length; i++) {
			callbacks[i].callback.apply(callbacks[i].thisArg, args);
		}
	}
}

/**
* Registers an action.
* @param {string|object} ident Identifier of the action, can have a namespace e.g. 'namespace:action' as string or an object with 'ns' and 'name' keys.
* @param {function} callback Callback fucntion
* @param {object} thisArg Optional this scope
* @param {number} priority Priority of the callback (default 10)
*/
actions.addAction = function(ident, callback, thisArg, priority) {
	function indexOf(haystack, callback) {
		for(var i = 0; i < haystack.length; i++) {
			if(haystack[i].callback == callback && haystack[i].thisArg == thisArg) {
				return i;
			}
		}
		return -1;
	}
	
	ident = actions._split(ident);

	var args = {
		callback : callback,
		thisArg : thisArg ? thisArg : window,
		priority : priority ? priority : 10,
		id: actions.hash._uid++
	};
	if(actions.hash[ident.ns] && actions.hash[ident.ns][ident.name]) {
		if(indexOf(actions.hash[ident.ns][ident.name], callback) == -1) {
			actions.hash[ident.ns][ident.name].push(args);
			actions.hash[ident.ns][ident.name].sort(function(a, b) {
				return (a.priority > b.priority) - (a.priority < b.priority);
			})
		} else {
			return actions.hash[ident.ns][ident.name][indexOf(actions.hash[ident.ns][ident.name], callback)].id;
		}
	} else {
		if(!actions.hash[ident.ns]) {
			actions.hash[ident.ns] = {};
		}
		actions.hash[ident.ns][ident.name] = new Array(args);
	}
	return args.id;
}

/**
* Removes an action callback.
* @param {string|object} ident Identifier of the actions
* @param {function|number} callback Callback function or ID
* @return {number} ID of callback or -1 if not existent
*/
actions.removeAction= function(ident, callback) {
	function indexOf(haystack, callback) {
		var func = typeof callback === 'function';
		for(var i = 0; i < haystack.length; i++) {
			if(func) {
				if(haystack[i].callback == callback) {
					return i;
				}
			} else {
				if(haystack[i].id == callback) {
					return i;
				}
			}
		}
		return -1;
	}

	ident = actions._split(ident);
	
	if(actions.hash[ident.ns] && actions.hash[ident.ns][ident.name]) {
		if(callback == undefined) {
			delete actions.hash[ident.ns][ident.name];
			return true;
		}
		var index = indexOf(actions.hash[ident.ns][ident.name], callback);
		if(index != -1) {
			actions.hash[ident.ns][ident.name].splice(index, 1);
			return true;
		} else {
			return false;
		}
	} else {
		return false;
	}
}
{'fraction_non_alphanumeric': 0.17494566904687986, 'fraction_numerical': 0.006054020490530891, 'mean_word_length': 3.4867688022284122, 'pattern_counts': {'":': 0, '<': 11, '<?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': '4461666', 'n_tokens_mistral': 2526, 'n_tokens_neox': 2278, 'n_words': 551}