all files / js/ mail.deobfuscate.class.js

100% Statements 5/5
100% Branches 8/8
100% Functions 4/4
100% Lines 5/5
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36                            11× 155×             11× 11×                 11×      
/**
 * @fileOverview Class to decode a rot13 (caesar) encoded string.
 * @author Simon Gattner <npm@0x38.de>
 * @license MIT
 * @version 2.2.0
 */
export default class MailDeobfuscate {
  /**
   * Decode a rot13 (caesar) string.
   * @class MailDeobfuscate
   * @classdesc Class to decode a rot13 (caesar) encoded string.
   * @alias module:mailDeobfuscate
   */
  constructor() {
    this.decodeChar = (c) =>
      (c >= 'a' && c <= 'z') ? String.fromCharCode(
        97 + (c.charCodeAt(0) - 97 + 13) % 26
      ) :
      (c >= 'A' && c <= 'Z') ? String.fromCharCode(
        65 + (c.charCodeAt(0) - 65 + 13) % 26
      ) :
      c;
    this.decodeString = (string) =>
      Array.prototype.map.call(string, this.decodeChar).join('');
  }
  /**
   * Get the decoded rot13 (caesar) string.
   * @function MailDeobfuscate.decode
   * @param {string} string The encoded rot13 (caesar) string.
   * @return {string} Encoded rot13 (caesar) string.
   */
  get decode() {
    return this.decodeString;
  }
}