import { characterEntitiesLegacy } from "../../../character-entities-legacy/index.js";
import { characterEntitiesHtml4 } from "../../../character-entities-html4/index.js";
import { dangerous } from "../constant/dangerous.js";
var own = {}.hasOwnProperty, characters = {}, key;
for (key in characterEntitiesHtml4) own.call(characterEntitiesHtml4, key) && (characters[characterEntitiesHtml4[key]] = key);
var notAlphanumericRegex = /[^\dA-Za-z]/;
function toNamed(i, o, s, c) {
	let l = String.fromCharCode(i);
	if (own.call(characters, l)) {
		let i = characters[l], a = "&" + i;
		return s && characterEntitiesLegacy.includes(i) && !dangerous.includes(i) && (!c || o && o !== 61 && notAlphanumericRegex.test(String.fromCharCode(o))) ? a : a + ";";
	}
	return "";
}
export { toNamed };
