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: Friday, December 20, 2024 at 8:07:49 PM

This is a built in tag
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);
  }
}