{"size": 1881, "ext": "js", "max_stars_repo_path": "xml.js", "max_stars_repo_name": "xandermathews/boast", "max_stars_repo_stars_event_min_datetime": "2020-08-07T15:51:42.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-07T15:51:42.000Z", "max_issues_repo_path": "xml.js", "max_issues_repo_name": "xandermathews/boast", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "xml.js", "max_forks_repo_name": "xandermathews/boast", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 24.75, "max_line_length": 67, "alphanum_fraction": 0.5943646996}
"use strict";

function handleList(xml, handlers, path) {
	var li = handleNode(xml, handlers, path);
	var out = [];
	Object.keys(li).map(k => {
		if (k === '#text') return;
		if (!Array.isArray(li[k])) {
			li[k] = [li[k]];
		}
		out = out.concat(li[k]);
	});
	return out;
}

function handleNode(xml, handlers, path) {
	var my_type = xml.nodeName;
	var out = {};
	var li = xml.childNodes;
	var valid = 0;

	for (var i = 0; i < li.length; ++i) {
		var child = li[i];
		var type = child.nodeName;
		var handler = handlers[type];
		if (handler === undefined) handler = handleNode;
		var val = handler(child, handlers, path.concat(type));
		if (val !== undefined) {
			++valid;
			if (out[type] !== undefined) {
				if (Array.isArray(out[type])) {
					out[type].push(val);
				} else {
					out[type] = [out[type], val];
				}
			} else {
				out[type] = val;
			}
		}
	}
	if (valid === 0) return '';
	if (valid === 1 && out['#text']) return out['#text'];
	return out;
}

function xml2js(xml, handlers) {
	var path = ['$'];
	if (typeof handlers === 'string') handlers = handlers.split(',');
	if (Array.isArray(handlers)) {
		var map = {};
		handlers.map(node => map[node] = handleList);
		handlers = map;
	}
	if (!handlers['#comment']) handlers['#comment'] = () => undefined;
	if (!handlers['#text']) handlers['#text'] = xml => {
		var str = xml.textContent.trim();
		var num = Number(str);
		if (str.length && Number.isFinite(num)) return num;
		return xml.textContent;
	}

	var handler = handlers[xml.nodeName];
	if (handler === undefined) handler = handleNode;
	return handler(xml, handlers, path);
}

function xmlVisitor(xml, hook, path) {
	path = path || ['$'];
	var li = xml.childNodes;
	for (var i = 0; i < li.length; ++i) {
		var child = li[i];
		if (child.nodeName === '#text') hook(path, child.textContent);
		else xmlVisitor(li[i], hook, path.concat(li[i].nodeName));
	}
}
