hexEscape
This tag provides hex escapes and decoding
Created by: hackvertor
Installed 1 times
Category: Convert
Created on: Monday, September 23, 2024 at 11:18:15 AM
Updated on: Monday, September 30, 2024 at 1:27:46 PM
Tag arguments
[]
Code
class hexEscape {
encode(input) {
return input.split('').map(chr => chr.charCodeAt(0) <= 0xff ? "\\x"+chr.charCodeAt(0).toString(16).padStart(2, "0"):chr).join('');
}
decode(input) {
return input.replaceAll(/\\x([a-fA-F0-9]{2})/g,($0,hex) => String.fromCharCode(parseInt(hex,16)));
}
matches(input) {
return /^(?:\\x[a-fA-F0-9]{2})+/.exec(input);
}
}