all files / js/ mail.deobfuscate.module.js

90% Statements 18/20
80% Branches 8/10
100% Functions 1/1
90% Lines 18/20
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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53                                                                     
/**
 * @fileOverview Module to deobfuscate rot13 (caesar) encoded mailto-links.
 * @author Simon Gattner <npm@0x38.de>
 * @license MIT
 * @version 2.2.0
 */
 
import MailDeobfuscate from './mail.deobfuscate.class';
const deobfuscate = new MailDeobfuscate();
 
/**
 * Deobfuscate an rot13 (caesar) obfuscated mailto link.
 * @param {object} object The object to deobfuscate.
 * @module mailDeobfuscate
 * @see MailDeobfuscate
 */
export default function mailDeobfuscate(object) {
  let href = object.href;
  let title = object.title;
  let text = object.text;
  try {
    Eif (href.length > 0) {
      href = href.split(':', 2);
    }
    try {
      Eif (href.length === 2) {
        const proto = href[0];
        const mail = href[1];
        const deobfuscatedMail = deobfuscate.decode(mail);
        if (proto === 'mailto') {
          object.href = proto + ':' + deobfuscatedMail;
        }
        if (title.match(mail)) {
          object.title = title.replace(mail, deobfuscatedMail);
        }
        if (text.match(mail)) {
          object.innerHTML = text.replace(mail, deobfuscatedMail);
        }
      }
    } catch (error) {
      console.info( // eslint-disable-line no-console
        'Deobfuscate Mail: No link in href',
        error
      );
    }
  } catch (error) {
    console.info( // eslint-disable-line no-console
      'Deobfuscate Mail: No href protocoll',
      error
    );
  }
}