<commit_before>/**
 * Timed
 * Copyright (c) 2011 <NAME>, <NAME>
 * https://github.com/ChiperSoft/Timed
 * Licensed under the BSD license (BSD_LICENSE.txt)
 *
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @version 1.0
 */


(function (context, doc) {
	/**
	 * Reasonable defaults (delay: 4, units: ms), based on how Mozilla works with timers:
	 * https://developer.mozilla.org/en/window.setTimeout#Minimum_delay_and_timeout_nesting
	 * @constant
	 */
	var defaults = {
		delay: 4,
		units: "milliseconds"
	};
	
	// each supported unit, in milliseconds
	var ms	= 1,
		sec = ms	* 1000,
		min = sec	* 60,
		hr	= min	* 60,
		day = hr	* 24;
			
	//supported unit formats.
	var valid_units = {
		millisecond		: ms,
		milliseconds	: ms,
		ms				: ms,

		second			: sec,
		seconds			: sec,
		sec				: sec,
		secs			: sec,
		s				: sec,

		minute			: min,
		minutes			: min,
		min				: min,
		mins			: min,
		m				: min,

		hour			: hr,
		hours			: hr,
		hr				: hr,
		hrs				: hr,
		h				: hr,

		day				: day,
		days			: day,
		d				: day
	};
	
	
	/**
	 * Accepts more human-readable arguments for creating JavaScript timers and 
	 * converts them to values that can be inspected and passed along to 
	 * setTimeout or setInterval.
	 * If the time when the timer should run is negative or faster than 
	 * the default it uses the default delay and default units.
	 */
	function create_timer() {
		var parsed = {
			delay : null,
			units : null,
			when : null,
			callback : null
		}, ac = arguments.length,
			name,
			timer;
	
		if ( (ac < 2) || ac > 3) throw ("Timed.after and Timed.every - Accept only 2 or 3 arguments");
		
		
		//parse callback function
		parsed.callback = arguments[ac - 1];
		if (typeof parsed.callback !== 'function') throw ("Timed.after and Timed.every - Require a callback as the last argument");
		
		
		//if the first arg is an array, run this function on each item and return the value, else do normal arg calls
		if (arguments[0] instanceof Array) {
			//create a baseline for the units
			parsed.units = 'milliseconds';
			
			for (name in arguments[0]) {
				timer = create_timer.apply(this, [arguments[0][name][0], arguments[0][name][1], parsed.callback]);
				parsed.delay += timer.when;
			}
		} else {
			//parse delay field
			parsed.delay = (typeof arguments[0] === "string") ? parseFloat(arguments[0], 10) : arguments[0];
			if (typeof parsed.delay !== "number" || isNaN(parsed.delay)) throw ("Timed.after and Timed.every - Require a numerical delay as the 1st argument");
	
	
	
			//parse units field
			if (typeof arguments[0] === "string" && parsed.delay !== null) { //find units in "50sec" style delays
				parsed.units = arguments[0].replace(/[^a-z]*/, "") || null;
			}
			if (typeof arguments[1] === "string") {
				parsed.units = arguments[1];
			}
			if (parsed.units === null && ac === 2) { // no units specified
				parsed.units = defaults.units;
			}
			
			if (typeof valid_units[parsed.units] !== "number") throw ("Timed.after and Timed.every - Require a valid unit of time as the 2nd argument");		
	
	
		
			// Reset to defaults, if necessary
			if (parsed.delay < defaults.delay && parsed.units === defaults.units) {
				parsed.delay = defaults.delay;
			}
			if (parsed.delay < 0) {
				parsed.delay = defaults.delay;
				parsed.units = defaults.units;
			}
		}
		
		parsed.when = parsed.delay * valid_units[parsed.units];
		
		return parsed;
	}
	

	var Timed = {
		/**
		 * Syntactic sugar for setTimeout.
		 *		setTimeout(function() { ... }, 300000); // becomes:
		 *		Timed.after(5, "minutes", function() { ... });
		 *
		 *		// other valid calls:
		 *		Timed.after(100, function() { ... }); // 100 milliseconds
		 *		Timed.after("9.7", function() { ... }); // 9.7 milliseconds
		 *		Timed.after("50sec", function() { ... }); // 50 seconds
		 *		Timed.after("33", "hours", function() { ... }); // 33 hours
		 *
		 * Valid time units include millisecond, second, minute, hour, & day
		 * along with all their common abbreviations and pluralizations.
		 */
		after : function after() {
			var timer = create_timer.apply(this, arguments);
			return setTimeout(timer.callback, timer.when);
		},

		/**<commit_msg>Complete rewrite of create_timer. Now concatenates and converts both arguments into a unified string which is then parsed via a regex. This significantly reduces the file size of Timed, as we no longer need a collection of all the valid unit types.<commit_after>/**
 * Timed
 * Copyright (c) 2011 <NAME>, <NAME>
 * https://github.com/ChiperSoft/Timed
 * Licensed under the BSD license (BSD_LICENSE.txt)
 *
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @version 1.0
 */


(function (context, doc) {
	/**
	 * Accepts more human-readable arguments for creating JavaScript timers and 
	 * converts them to values that can be inspected and passed along to 
	 * setTimeout or setInterval.
	 * If the time when the timer should run is negative or faster than 
	 * the default it uses the default delay and default units.
	 */
	function create_timer() {
		var parsed = {when : null, callback : null},
			ac = arguments.length;
	
		//parse callback function
		parsed.callback = arguments[ac - 1];
		if (typeof parsed.callback !== 'function') throw ("Timed.after and Timed.every - Require a callback as the last argument");
		
		//parse the first argument. if array, merge, otherwise force string. If a second argument is passed, append it as well.
		var period = (arguments[0] instanceof Array?arguments[0].join(''):String(arguments[0])) + (ac===3?String(arguments[1]):'');
				
		var match = period.toLowerCase().replace(/[^a-z0-9\.]/g, "").match(/(?:(\d+(?:\.\d+)?)(?:days?|d))?(?:(\d+(?:\.\d+)?)(?:hours?|hrs?|h))?(?:(\d+(?:\.\d+)?)(?:minutes?|mins?|m))?(?:(\d+(?:\.\d+)?)(?:seconds?|secs?|s))?(?:(\d+(?:\.\d+)?)(?:milliseconds?|ms))?/);
		
		if (match[0]) {
			parsed.when = 
				parseFloat(match[1]||0)*86400000 + //days
				parseFloat(match[2]||0)*3600000 +  //hours
				parseFloat(match[3]||0)*60000 +  //minutes
				parseFloat(match[4]||0)*1000 +	//seconds
				  parseInt(match[5]||0,10);		//milliseconds
				
		} else if (ac===3 || !(parsed.when = parseInt(arguments[0],10))) {
			throw ("Timed.after and Timed.every - Could not parse delay arguments, check your syntax");
		}
		
		return parsed;
	}
	

	var Timed = {
		/**
		 * Syntactic sugar for setTimeout.
		 *		setTimeout(function() { ... }, 300000); // becomes:
		 *		Timed.after(5, "minutes", function() { ... });
		 *
		 *		// other valid calls:
		 *		Timed.after(100, function() { ... }); // 100 milliseconds
		 *		Timed.after("9.7", function() { ... }); // 9.7 milliseconds
		 *		Timed.after("50sec", function() { ... }); // 50 seconds
		 *		Timed.after("33", "hours", function() { ... }); // 33 hours
		 *
		 * Valid time units include millisecond, second, minute, hour, & day
		 * along with all their common abbreviations and pluralizations.
		 */
		after : function after() {
			var timer = create_timer.apply(this, arguments);
			return setTimeout(timer.callback, timer.when);
		},

		/**
{'fraction_non_alphanumeric': 0.16211215485340166, 'fraction_numerical': 0.02134927412467976, 'mean_word_length': 2.956644144144144, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 16, 'https://': 3, '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': '4678257', 'n_tokens_mistral': 2694, 'n_tokens_neox': 2250, 'n_words': 679}