<commit_before>import { _slice, $copy, $toArray } from './types';
import { $sel, $each, $map } from './dom';

/**
 * Cast selection as Wee object
 *
 * @private
 * @param {($|HTMLElement|string)} sel
 * @param {($|HTMLElement|string)} [context=document]
 */
let Get = function(sel, context) {
		if (sel) {
			let els = Array.isArray(sel) ?
					sel :
					$toArray($sel(sel, context)),
				i = 0;

			for (; i < els.length; i++) {
				let el = els[i];

				if (el) {
					[].push.call(this, el);
				}
			}

			this.sel = sel;
		}
	};

/**
 * Create chainable Wee object from selection
 *
 * @param {(HTMLElement|string)} sel
 * @param {object} [context=document]
 */
export function $(sel, context) {
	return new Get(sel, context);
}

// Bind core chainable methods
$.fn = Get.prototype = {
	_$: true,
	length: 0,

	/**
	 * Execute function for each object element
	 *
	 * @param fn
	 * @param {object} [options]
	 * @param {Array} [options.args]
	 * @param {context} [options.context=document]
	 * @param {bool} [options.reverse=false]
	 * @param {Array} [options.scope]
	 */
	each: function(fn, options) {
		$each(this, fn, options);

		return this;
	},

	/**
	 * Translate object elements to a new array
	 *
	 * @param {function} fn
	 * @param {object} [options]
	 * @param {Array} [options.args]
	 * @param {object} [options.scope]
	 * @returns {Array}
	 */
	map: function(fn, options) {
		return $map(this, fn, options);
	},

	/**
	 * Reverse the order of object elements
	 *
	 * @returns {$}
	 */
	reverse: function() {
		let copy = $copy(this),
			x = this.length,
			total = x,
			i = 0;

		for (; i < total; i++) {
			x--;
			this[i] = copy[x];
		}

		return this;
	},

	/**
	 * Convert selection to standard array
	 */
	toArray: function() {
		return _slice.call(this);
	}
};

/**
 * Register a new chainable method
 *
 * @param {(object|string)} a - method name or object
 * @param {function} b
 */
export function $chain(a, b) {
	if (typeof a == 'string') {
		$.fn[a] = b;
	} else {
		for (let key in a) {
			$.fn[key] = a[key];
		}
	}<commit_msg>Update $chain optional second param<commit_after>import { _slice, $copy, $toArray } from './types';
import { $sel, $each, $map } from './dom';

/**
 * Cast selection as Wee object
 *
 * @private
 * @param {($|HTMLElement|string)} sel
 * @param {($|HTMLElement|string)} [context=document]
 */
let Get = function(sel, context) {
		if (sel) {
			let els = Array.isArray(sel) ?
					sel :
					$toArray($sel(sel, context)),
				i = 0;

			for (; i < els.length; i++) {
				let el = els[i];

				if (el) {
					[].push.call(this, el);
				}
			}

			this.sel = sel;
		}
	};

/**
 * Create chainable Wee object from selection
 *
 * @param {(HTMLElement|string)} sel
 * @param {object} [context=document]
 */
export function $(sel, context) {
	return new Get(sel, context);
}

// Bind core chainable methods
$.fn = Get.prototype = {
	_$: true,
	length: 0,

	/**
	 * Execute function for each object element
	 *
	 * @param fn
	 * @param {object} [options]
	 * @param {Array} [options.args]
	 * @param {context} [options.context=document]
	 * @param {bool} [options.reverse=false]
	 * @param {Array} [options.scope]
	 */
	each: function(fn, options) {
		$each(this, fn, options);

		return this;
	},

	/**
	 * Translate object elements to a new array
	 *
	 * @param {function} fn
	 * @param {object} [options]
	 * @param {Array} [options.args]
	 * @param {object} [options.scope]
	 * @returns {Array}
	 */
	map: function(fn, options) {
		return $map(this, fn, options);
	},

	/**
	 * Reverse the order of object elements
	 *
	 * @returns {$}
	 */
	reverse: function() {
		let copy = $copy(this),
			x = this.length,
			total = x,
			i = 0;

		for (; i < total; i++) {
			x--;
			this[i] = copy[x];
		}

		return this;
	},

	/**
	 * Convert selection to standard array
	 */
	toArray: function() {
		return _slice.call(this);
	}
};

/**
 * Register a new chainable method
 *
 * @param {(object|string)} a - method name or object
 * @param {function} [b]
 */
export function $chain(a, b) {
	if (typeof a == 'string') {
		$.fn[a] = b;
	} else {
		for (let key in a) {
			$.fn[key] = a[key];
		}
	}
{'fraction_non_alphanumeric': 0.1846042471042471, 'fraction_numerical': 0.0014478764478764478, 'mean_word_length': 2.8702147525676938, 'pattern_counts': {'":': 0, '<': 7, '<?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': '5592158', 'n_tokens_mistral': 1672, 'n_tokens_neox': 1488, 'n_words': 420}