<commit_before>'use strict';
var Promise = require('es6-promise').Promise,
	doc = global.document,
	cached = {};

function loadScript(script) {
	return new Promise(function(resolve, reject) {
		script.onload = function() {
			this.onload = this.onerror = null;
			resolve();
		};

		script.onerror = function() {
			this.onload = this.onerror = null;
			reject(new Error('Failed to load ' + script.src));
		};
	});
}

function loadScriptIE(script) {
	return new Promise(function(resolve) {
		script.onreadystatechange = function() {
			if (this.readyState !== 'complete') {
				return;
			}

			this.onreadystatechange = null;
			resolve();
		};
	});
}

function scriptResolver(src) {
	return new Promise(function(resolve) {
		var head = doc.head || doc.getElementsByTagName('head')[0];
		var script = doc.createElement('script');
		script.type = 'text/javascript';
		script.charset = 'utf8';
		script.async = true;
		script.src = src;

		var loader = 'onload' in script ? loadScript : loadScriptIE;
		resolve(loader(script));

		head.appendChild(script);
	});
}

module.exports = function promisescript(srcs) {
	var promises = [],
		promise,
		i,
		length,
		src;
	if (typeof srcs === 'string') {
		srcs = [srcs];
	}

	length = srcs.length;
	for (i = 0; i < length; i++) {
		src = srcs[i];

		// if the script is cached, resolve with the original promise;
		if (cached[src]) {
			promises.push(cached[src]);
			continue;
		}

		promise = scriptResolver(src);

		cached[src] = promise;
		promises.push(promise);
	}

	if (length === 1) {
		return promises[0];
	}

	return promises;
};<commit_msg>If given an array, return an array (even if length === 1)<commit_after>'use strict';
var Promise = require('es6-promise').Promise,
	doc = global.document,
	cached = {};

function loadScript(script) {
	return new Promise(function(resolve, reject) {
		script.onload = function() {
			this.onload = this.onerror = null;
			resolve();
		};

		script.onerror = function() {
			this.onload = this.onerror = null;
			reject(new Error('Failed to load ' + script.src));
		};
	});
}

function loadScriptIE(script) {
	return new Promise(function(resolve) {
		script.onreadystatechange = function() {
			if (this.readyState !== 'complete') {
				return;
			}

			this.onreadystatechange = null;
			resolve();
		};
	});
}

function scriptResolver(src) {
	return new Promise(function(resolve) {
		var head = doc.head || doc.getElementsByTagName('head')[0];
		var script = doc.createElement('script');
		script.type = 'text/javascript';
		script.charset = 'utf8';
		script.async = true;
		script.src = src;

		var loader = 'onload' in script ? loadScript : loadScriptIE;
		resolve(loader(script));

		head.appendChild(script);
	});
}

module.exports = function promisescript(srcs) {
	var promises = [],
		shouldReturnArray = true,
		promise,
		i,
		length,
		src;

	if (typeof srcs === 'string') {
		srcs = [srcs];
		shouldReturnArray = false
	}

	length = srcs.length;
	for (i = 0; i < length; i++) {
		src = srcs[i];

		// if the script is cached, resolve with the original promise;
		if (cached[src]) {
			promises.push(cached[src]);
			continue;
		}

		promise = scriptResolver(src);

		cached[src] = promise;
		promises.push(promise);
	}

	if (!shouldReturnArray) {
		return promises[0];
	}

	return promises;
};
{'fraction_non_alphanumeric': 0.15438277221716712, 'fraction_numerical': 0.003639672429481347, 'mean_word_length': 3.704707560627675, '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': '2024857', 'n_tokens_mistral': 1243, 'n_tokens_neox': 1106, 'n_words': 261}