<commit_before>/*
 * Paper.js
 *
 * This file is part of Paper.js, a JavaScript Vector Graphics Library,
 * based on Scriptographer.org and designed to be largely API compatible.
 * http://paperjs.org/
 * http://scriptographer.org/
 *
 * Distributed under the MIT license. See LICENSE file for details.
 *
 * Copyright (c) 2011, <NAME> & <NAME>
 * http://lehni.org/ & http://jonathanpuckey.com/
 *
 * All rights reserved.
 */

// Extend Base with utility functions used across the library.
Base.inject({
	statics: true,

	read: function(list, start, length) {
		var start = start || 0,
			length = length || list.length - start;
		var obj = list[start];
		if (obj instanceof this
				// If the class defines _readNull, return null when nothing
				// was provided
				|| this.prototype._readNull && obj == null && length <= 1)
			return obj;
		obj = new this(this.dont);
		return obj.initialize.apply(obj, start > 0 || length < list.length
			? Array.prototype.slice.call(list, start, start + length)
			: list) || obj;
	},

	readAll: function(list, start) {
		var res = [], entry;
		for (var i = start || 0, l = list.length; i < l; i++) {
			res.push(Array.isArray(entry = list[i])
				? this.read(entry, 0)
				: this.read(list, i, 1));
		}
		return res;
	},

	/**
	 * Utility function for adding and removing items from a list of which
	 * each entry keeps a reference to its index in the list in the private
	 * _index property. Used for PaperScope#projects and Item#children.
	 */
	splice: function(list, items, index, remove) {
		var amount = items && items.length,
			append = index === undefined;
		index = append ? list.length : index;
		// Update _index on the items to be added first.
		for (var i = 0; i < amount; i++)
			items[i]._index = index + i;
		if (append) {
			// Append them all at the end by using push
			list.push.apply(list, items);
			// Nothing removed, and nothing to adjust above
			return [];
		} else {
			// Insert somewhere else and/or remove
			var args = [index, remove];
			if (items)
				args.push.apply(args, items);
			var removed = list.splice.apply(list, args);
			// Delete the indices of the removed items
			for (var i = 0, l = removed.length; i < l; i++)
				delete removed[i]._index;<commit_msg>Define Base.initialize() as a general purpose way to initialize a newly created object with values from a provided object and default values from another, in case they are not provided.<commit_after>/*
 * Paper.js
 *
 * This file is part of Paper.js, a JavaScript Vector Graphics Library,
 * based on Scriptographer.org and designed to be largely API compatible.
 * http://paperjs.org/
 * http://scriptographer.org/
 *
 * Distributed under the MIT license. See LICENSE file for details.
 *
 * Copyright (c) 2011, <NAME> & <NAME>
 * http://lehni.org/ & http://jonathanpuckey.com/
 *
 * All rights reserved.
 */

// Extend Base with utility functions used across the library.
Base.inject({
	statics: true,

	read: function(list, start, length) {
		var start = start || 0,
			length = length || list.length - start;
		var obj = list[start];
		if (obj instanceof this
				// If the class defines _readNull, return null when nothing
				// was provided
				|| this.prototype._readNull && obj == null && length <= 1)
			return obj;
		obj = new this(this.dont);
		return obj.initialize.apply(obj, start > 0 || length < list.length
			? Array.prototype.slice.call(list, start, start + length)
			: list) || obj;
	},

	readAll: function(list, start) {
		var res = [], entry;
		for (var i = start || 0, l = list.length; i < l; i++) {
			res.push(Array.isArray(entry = list[i])
				? this.read(entry, 0)
				: this.read(list, i, 1));
		}
		return res;
	},

	initialize: function(object, values, defaults) {
		if (!values)
			values = defaults;
		return Base.each(defaults, function(value, key) {
			this[key] = values[key] || value;
		}, object);
	},

	/**
	 * Utility function for adding and removing items from a list of which
	 * each entry keeps a reference to its index in the list in the private
	 * _index property. Used for PaperScope#projects and Item#children.
	 */
	splice: function(list, items, index, remove) {
		var amount = items && items.length,
			append = index === undefined;
		index = append ? list.length : index;
		// Update _index on the items to be added first.
		for (var i = 0; i < amount; i++)
			items[i]._index = index + i;
		if (append) {
			// Append them all at the end by using push
			list.push.apply(list, items);
			// Nothing removed, and nothing to adjust above
			return [];
		} else {
			// Insert somewhere else and/or remove
			var args = [index, remove];
			if (items)
				args.push.apply(args, items);
			var removed = list.splice.apply(list, args);
			// Delete the indices of the removed items
			for (var i = 0, l = removed.length; i < l; i++)
				delete removed[i]._index;
{'fraction_non_alphanumeric': 0.1292517006802721, 'fraction_numerical': 0.004947433518862091, 'mean_word_length': 3.0738874895046178, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 9, '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': '6912524', 'n_tokens_mistral': 1678, 'n_tokens_neox': 1487, 'n_words': 562}