<commit_before>/**
 * serialize.js
 *
 * Convert JS data types into string representations parsable by PHP's unserialize() function.
 *
 * Copyright (c) 2016 <NAME>
 * Released under the MIT license
 *
 */
;(function(){
	window.PHP = window.PHP || {};

	/**
	 * Serialize a JS value for PHP consumption
	 * @param  {mixed} data  any piece of data represented in JS
	 * @param  {bool} assoc  whether to convey objects as associative arrays
	 * @return {string}      the serialized value as a string
	 */
	PHP.serialize = function(data, assoc) {
		switch(typeof data) {
			case 'string':
				return 's:' + data.length + ':"' + data + '";';
			case 'number':
				if (isNaN(data)) return 'd:NAN;';
				if (!isFinite(data)) return 'd:' + (data>0?'':'-') + 'INF;';
				if (Number.isInteger(data)) return 'i:' + data + ';';
				return 'd:' + data + ';';
			case 'boolean':
				return 'b:' + +data + ';';
			case 'object':
			case 'function':
				if (!data) return 'N;';
				if (Array.isArray(data)) {
					// for loop is the best way to handle the possibility of sparse arrays
					for(var out='a:'+data.length+':{',i=0; i<data.length; i++) {
						out += PHP.serialize(i) + PHP.serialize(data[i]);
					}
					return out + '}';
				}
				var keys = Object.keys(data);
				return (assoc?'a:':'O:8:"stdClass":') + keys.length + ':{'
					+ keys.reduce(function(running, key){
						return running + PHP.serialize(key) + PHP.serialize(data[key]);
					}, '') + '}';
			default:
				// treat anything else as null
				// this includes undefined, since PHP does not have that type
				return 'N;';
		}
	};

})();<commit_msg>Move default return value outside of switch<commit_after>/**
 * serialize.js
 *
 * Convert JS data types into string representations parsable by PHP's unserialize() function.
 *
 * Copyright (c) 2016 <NAME>
 * Released under the MIT license
 *
 */
;(function(){
	window.PHP = window.PHP || {};

	/**
	 * Serialize a JS value for PHP consumption
	 * @param  {mixed} data  any piece of data represented in JS
	 * @param  {bool} assoc  whether to convey objects as associative arrays
	 * @return {string}      the serialized value as a string
	 */
	PHP.serialize = function(data, assoc) {
		switch(typeof data) {
			case 'string':
				return 's:' + data.length + ':"' + data + '";';
			case 'number':
				if (isNaN(data)) return 'd:NAN;';
				if (!isFinite(data)) return 'd:' + (data>0?'':'-') + 'INF;';
				if (Number.isInteger(data)) return 'i:' + data + ';';
				return 'd:' + data + ';';
			case 'boolean':
				return 'b:' + +data + ';';
			case 'object':
			case 'function':
				if (!data) return 'N;';
				if (Array.isArray(data)) {
					// for loop is the best way to handle the possibility of sparse arrays
					for(var out='a:'+data.length+':{',i=0; i<data.length; i++) {
						out += PHP.serialize(i) + PHP.serialize(data[i]);
					}
					return out + '}';
				}
				var keys = Object.keys(data);
				return (assoc?'a:':'O:8:"stdClass":') + keys.length + ':{'
					+ keys.reduce(function(running, key){
						return running + PHP.serialize(key) + PHP.serialize(data[key]);
					}, '') + '}';
		}
		// treat anything else as null
		// this includes undefined, since PHP does not have that type
		return 'N;';
	};

})();
{'fraction_non_alphanumeric': 0.1788140827671402, 'fraction_numerical': 0.004323656578134651, 'mean_word_length': 3.053817271589487, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 7, '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': '1915075', 'n_tokens_mistral': 1261, 'n_tokens_neox': 1054, 'n_words': 323}