html
This tag HTML encodes and decodes.
Created by: hackvertor
Installed 1 times
Category: Convert
Created on: Thursday, October 3, 2024 at 9:13:40 PM
Updated on: Friday, December 20, 2024 at 8:08:04 PM
Tag arguments
[]
Code
class html {
encode(input) {
const keys = Object.keys(hv.variables.htmlEntities).reverse();
return input
.split("")
.map((chr) => {
if(chr === "<") {
return '<';
}
if(chr === ">") {
return '>';
}
const entity = keys.find(
(key) => hv.variables.htmlEntities[key] === chr.codePointAt(),
);
return entity ? "&" + entity + ";" : chr;
})
.join("");
}
decode(input) {
const textarea = document.createElement("textarea");
textarea.innerHTML = input;
return textarea.value;
}
matches(input) {
return /^(?:&[a-zA-Z]{1,20};)+/.exec(input);
}
}