'use strict';

const request = require("request");
const url = require("url");

function getfavicon (webpage) {
  return new Promise((resolve, reject) => {
    request(webpage, function(err, res, body) {
      let faviconArrayA = /<link[\w\s="]*rel="shortcut icon" href="([\w._-]*)"/.exec(body);
      let faviconArrayB = /<link[\w\s="]* href="([\w._-]*)"[\w\s._-]*rel="shortcut icon" /.exec(body);

      if (faviconArrayA.length >= 2) {
        resolve(url.resolve(webpage, faviconArrayA[1]));
      }
      else if (faviconArrayB.length >= 2) {
        resolve(url.resolve(webpage, faviconArrayB[1]));
      }
      else {
        resolve(null);
      }
    });
  });
};

module.exports = getfavicon;

@@ -416,16 +416,41 @@
 onArrayA
+ != null && faviconArrayA
 .length 
@@ -550,16 +550,41 @@
 onArrayB
+ != null && faviconArrayB
 .length 

prüfe ob array = null