utf7Copy

This encodes and decodes UTF-7 used in browsers and email parsers.

Created by: haitkadir
Installed 1 times

Viewed: 60

Category: Charsets

Created on: Sunday, January 4, 2026 at 7:44:58 PM

Updated on: Sunday, January 4, 2026 at 7:44:58 PM

Tag arguments
[
   {
      "type": "string",
      "help": "Provides a prefix",
      "defaultValue": "&"
   }
]
Code
class utf7 {
  encode(input, prefix) {
      return prefix + btoa(input.replaceAll(/(.)/g,"\x00$1"))
        .replaceAll(/=+$/g,"") + "-";
  }

  decode(input) {
     return input.replaceAll(/[+&]([a-zA-Z0-9]+)-/g, ($0, match) => atob(match).replaceAll(/[\x00&-]/g,""));
  }

  matches(input) {
    return /^[&+][a-zA-Z0-9]{3,}-/.exec(input);
  }
}