<commit_before>"use strict";
(function() {
	this.Sexhr = function(options)
	{
		options || (options = {});

		return new Promise(function(resolve, reject) {
			var url = options.url;
			var method = (options.method || 'get').toUpperCase();
			var emulate = options.emulate || true;

			if(!options.url) throw new Error('no url given');

			url = url.replace(/#.*$/, '');
			if(emulate && ['GET', 'POST'].indexOf(method) < 0)
			{
				var append = '?_method='+method;
				if(url.match(/\?/))
				{
					url = url.replace(/\?/, append+'&');
				}
				else
				{
					url += append;
				}
				method = 'POST';
			}

			var xhr = new XMLHttpRequest();
			xhr.open(method, url, true);
			xhr.responseType = options.response_type || '';
			if(options.timeout) xhr.timeout = options.timeout;

			Object.keys(options.headers || {}).forEach(function(k) {
				xhr.setRequestHeader(k, options.headers[k]);
			});
			xhr.onload = function(e)
			{
				if(xhr.status >= 200 && xhr.status < 300)
				{
					var value = xhr.response;
					return resolve([value, xhr]);
				}
				else if(xhr.status >= 400)
				{
					reject({xhr: xhr, code: xhr.status, msg: xhr.responseText});
				}
			};
			xhr.onabort = function(e)<commit_msg>adding options.querydata (for adding data to the querystring) as well centralizing the actual query string -> url write is<commit_after>"use strict";
(function() {
	this.Sexhr = function(options)
	{
		options || (options = {});

		return new Promise(function(resolve, reject) {
			var url = options.url;
			var method = (options.method || 'get').toUpperCase();
			var emulate = options.emulate || true;

			if(!options.url) throw new Error('no url given');

			url = url.replace(/#.*$/, '');
			var qs = [];
			if(options.querydata)
			{
				qs = Object.keys(options.querydata)
					.map(function(key) {
						return key + '=' + encodeURIComponent(options.querydata[key]);
					});
			}
			if(emulate && ['GET', 'POST'].indexOf(method) < 0)
			{
				qs.push('_method='+method);
				method = 'POST';
			}
			if(qs.length)
			{
				var querystring = qs.join('&');
				if(url.match(/\?/))
				{
					url = url.replace(/&$/) + '&' + querystring;
				}
				else
				{
					url += '?' + querystring;
				}
			}

			var xhr = new XMLHttpRequest();
			xhr.open(method, url, true);
			xhr.responseType = options.response_type || '';
			if(options.timeout) xhr.timeout = options.timeout;

			Object.keys(options.headers || {}).forEach(function(k) {
				xhr.setRequestHeader(k, options.headers[k]);
			});
			xhr.onload = function(e)
			{
				if(xhr.status >= 200 && xhr.status < 300)
				{
					var value = xhr.response;
					return resolve([value, xhr]);
				}
				else if(xhr.status >= 400)
				{
					reject({xhr: xhr, code: xhr.status, msg: xhr.responseText});
				}
			};
			xhr.onabort = function(e)
{'fraction_non_alphanumeric': 0.18227127091491635, 'fraction_numerical': 0.00711997152011392, 'mean_word_length': 2.8024357239512856, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 8, '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': '387756', 'n_tokens_mistral': 1255, 'n_tokens_neox': 982, 'n_words': 197}