<commit_before>"use strict";

const JSON_URL = "data/bestiary/index.json";

window.onload = loadSources;

function moveon (cur) {
	return (!cur.toUpperCase().indexOf("ACTIONS") || !cur.toUpperCase().indexOf("LEGENDARY ACTIONS") || !cur.toUpperCase().indexOf("REACTIONS"))
}

function tryConvertNumber (strNumber) {
	try {
		return Number(strNumber)
	} catch (e) {
		return strNumber;
	}
}

function tryParseType (strType) {
	try {
		const m = /^(.*?) (\(.*?\))\s*$/.exec(strType);
		if (m) {
			return {type: m[1].toLowerCase(), tags: m[2].split(",").map(s => s.replace(/\(/g, "").replace(/\)/g, "").trim().toLowerCase())}
		}
		return strType.toLowerCase();
	} catch (e) {
		return strType;
	}
}

function tryGetStat (strLine) {
	try {
		return tryConvertNumber(/(\d+) \(.*?\)/.exec(strLine)[1]);
	} catch (e) {
		return 0;
	}
}

const SKILL_SPACE_MAP = {
	"sleightofhand": "sleight of hand",
	"animalhandling": "animal handling"
};

function loadSources () {
	DataUtil.loadJSON(JSON_URL, loadparser)
}

function sortOptions ($select) {
	$select.append($select.find("option").remove().sort((a, b) => {
		const at = $(a).text();
		const bt = $(b).text();
		return (at > bt) ? 1 : ((at < bt) ? -1 : 0);
	}));
}

function appendSource ($select, src) {
	$select.append(`<option value="${src}">${src}</option>`);
}

const COOKIE_NAME = "converterSources";
function loadparser (data) {
	let hasAppended = false;

	// custom sources
	const $srcSel = $(`#source`);
	Object.keys(data).forEach(src => appendSource($srcSel, src));
	const rawCookie = Cookies.get(COOKIE_NAME);
	const cookie = rawCookie ? JSON.parse(rawCookie) : {sources: [], selected: SRC_MM};
	cookie.sources.forEach(src => appendSource($srcSel, src));
	sortOptions($srcSel);
	$srcSel.val(cookie.selected);

	$srcSel.on("change", () => cookie.selected = $srcSel.val());

	window.addEventListener("unload", function () {
		Cookies.set(COOKIE_NAME, cookie, {expires: 365, path: window.location.pathname})
	});

	const $inptCustomSource = $(`#customsourcein`);
	$(`#addsource`).on("click", () => {
		const toAdd = $inptCustomSource.val().trim();
		if (!cookie.sources.find(src => toAdd.toLowerCase() === src.toLowerCase())) {
			cookie.selected = toAdd;
			cookie.sources.push(toAdd);
			appendSource($srcSel, toAdd);
			sortOptions($srcSel);
			$srcSel.val(toAdd);
			$inptCustomSource.val("");
		}
	});

	// init editor
	const editor = ace.edit("statblock");
	editor.setOptions({
		wrap: true
	});

	$(`button#parsestatblockadd`).on("click", () => {
		doParse(true);
	});

	$("button#parsestatblock").on("click", () => {
		if (!hasAppended || confirm("You're about to overwrite multiple entries. Are you sure?")) doParse(false);
	});

	function doParse (append) {
		const statblock = editor.getValue().split("\n");
		const stats = {};

		stats.source = $srcSel.val();

		let prevLine = null;
		let curline = null;
		for (let i = 0; i < statblock.length; i++) {
			prevLine = curline;
			curline = statblock[i].trim();

			if (curline === "") continue;

			// name of monster
			if (i === 0) {
				stats.name = curline.toLowerCase().replace(/\b\w/g, function (l) {
					return l.toUpperCase()
				});
				continue;
			}

			// size type alignment
			if (i === 1) {
				stats.size = curline[0];
				stats.type = curline.split(",")[0].split(" ").splice(1).join(" "); // + ", " + $("input#source").val();
				stats.type = tryParseType(stats.type);

				stats.alignment = curline.split(", ")[1];
				continue;
			}

			// armor class
			if (i === 2) {
				stats.ac = curline.split("Armor Class ")[1];
				continue;
			}

			// hit points
			if (i === 3) {
				stats.hp = curline.split("Hit Points ")[1];
				continue;
			}

			// speed
			if (i === 4) {
				stats.speed = curline.split("Speed ")[1];
				continue;
			}

			if (i === 5) continue;
			// ability scores
			if (i === 6) {<commit_msg>fix(converter) lowercase alignment<commit_after>"use strict";

const JSON_URL = "data/bestiary/index.json";

window.onload = loadSources;

function moveon (cur) {
	return (!cur.toUpperCase().indexOf("ACTIONS") || !cur.toUpperCase().indexOf("LEGENDARY ACTIONS") || !cur.toUpperCase().indexOf("REACTIONS"))
}

function tryConvertNumber (strNumber) {
	try {
		return Number(strNumber)
	} catch (e) {
		return strNumber;
	}
}

function tryParseType (strType) {
	try {
		const m = /^(.*?) (\(.*?\))\s*$/.exec(strType);
		if (m) {
			return {type: m[1].toLowerCase(), tags: m[2].split(",").map(s => s.replace(/\(/g, "").replace(/\)/g, "").trim().toLowerCase())}
		}
		return strType.toLowerCase();
	} catch (e) {
		return strType;
	}
}

function tryGetStat (strLine) {
	try {
		return tryConvertNumber(/(\d+) \(.*?\)/.exec(strLine)[1]);
	} catch (e) {
		return 0;
	}
}

const SKILL_SPACE_MAP = {
	"sleightofhand": "sleight of hand",
	"animalhandling": "animal handling"
};

function loadSources () {
	DataUtil.loadJSON(JSON_URL, loadparser)
}

function sortOptions ($select) {
	$select.append($select.find("option").remove().sort((a, b) => {
		const at = $(a).text();
		const bt = $(b).text();
		return (at > bt) ? 1 : ((at < bt) ? -1 : 0);
	}));
}

function appendSource ($select, src) {
	$select.append(`<option value="${src}">${src}</option>`);
}

const COOKIE_NAME = "converterSources";
function loadparser (data) {
	let hasAppended = false;

	// custom sources
	const $srcSel = $(`#source`);
	Object.keys(data).forEach(src => appendSource($srcSel, src));
	const rawCookie = Cookies.get(COOKIE_NAME);
	const cookie = rawCookie ? JSON.parse(rawCookie) : {sources: [], selected: SRC_MM};
	cookie.sources.forEach(src => appendSource($srcSel, src));
	sortOptions($srcSel);
	$srcSel.val(cookie.selected);

	$srcSel.on("change", () => cookie.selected = $srcSel.val());

	window.addEventListener("unload", function () {
		Cookies.set(COOKIE_NAME, cookie, {expires: 365, path: window.location.pathname})
	});

	const $inptCustomSource = $(`#customsourcein`);
	$(`#addsource`).on("click", () => {
		const toAdd = $inptCustomSource.val().trim();
		if (!cookie.sources.find(src => toAdd.toLowerCase() === src.toLowerCase())) {
			cookie.selected = toAdd;
			cookie.sources.push(toAdd);
			appendSource($srcSel, toAdd);
			sortOptions($srcSel);
			$srcSel.val(toAdd);
			$inptCustomSource.val("");
		}
	});

	// init editor
	const editor = ace.edit("statblock");
	editor.setOptions({
		wrap: true
	});

	$(`button#parsestatblockadd`).on("click", () => {
		doParse(true);
	});

	$("button#parsestatblock").on("click", () => {
		if (!hasAppended || confirm("You're about to overwrite multiple entries. Are you sure?")) doParse(false);
	});

	function doParse (append) {
		const statblock = editor.getValue().split("\n");
		const stats = {};

		stats.source = $srcSel.val();

		let prevLine = null;
		let curline = null;
		for (let i = 0; i < statblock.length; i++) {
			prevLine = curline;
			curline = statblock[i].trim();

			if (curline === "") continue;

			// name of monster
			if (i === 0) {
				stats.name = curline.toLowerCase().replace(/\b\w/g, function (l) {
					return l.toUpperCase()
				});
				continue;
			}

			// size type alignment
			if (i === 1) {
				stats.size = curline[0];
				stats.type = curline.split(",")[0].split(" ").splice(1).join(" "); // + ", " + $("input#source").val();
				stats.type = tryParseType(stats.type);

				stats.alignment = curline.split(", ")[1].toLowerCase();
				continue;
			}

			// armor class
			if (i === 2) {
				stats.ac = curline.split("Armor Class ")[1];
				continue;
			}

			// hit points
			if (i === 3) {
				stats.hp = curline.split("Hit Points ")[1];
				continue;
			}

			// speed
			if (i === 4) {
				stats.speed = curline.split("Speed ")[1];
				continue;
			}

			if (i === 5) continue;
			// ability scores
			if (i === 6) {
{'fraction_non_alphanumeric': 0.2091579355840124, 'fraction_numerical': 0.006467468632777131, 'mean_word_length': 3.7088915956151034, 'pattern_counts': {'":': 4, '<': 11, '<?xml version=': 0, '>': 27, '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': '4774815', 'n_tokens_mistral': 3096, 'n_tokens_neox': 2771, 'n_words': 562}