function _classCallCheck(instance, Constructor) {
  if (!(instance instanceof Constructor)) {
    throw new TypeError("Cannot call a class as a function");
  }
}

function _defineProperties(target, props) {
  for (var i = 0; i < props.length; i++) {
    var descriptor = props[i];
    descriptor.enumerable = descriptor.enumerable || false;
    descriptor.configurable = true;
    if ("value" in descriptor) descriptor.writable = true;
    Object.defineProperty(target, descriptor.key, descriptor);
  }
}

function _createClass(Constructor, protoProps, staticProps) {
  if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  if (staticProps) _defineProperties(Constructor, staticProps);
  return Constructor;
}

function _classPrivateFieldGet(receiver, privateMap) {
  var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get");

  return _classApplyDescriptorGet(receiver, descriptor);
}

function _classPrivateFieldSet(receiver, privateMap, value) {
  var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set");

  _classApplyDescriptorSet(receiver, descriptor, value);

  return value;
}

function _classExtractFieldDescriptor(receiver, privateMap, action) {
  if (!privateMap.has(receiver)) {
    throw new TypeError("attempted to " + action + " private field on non-instance");
  }

  return privateMap.get(receiver);
}

function _classApplyDescriptorGet(receiver, descriptor) {
  if (descriptor.get) {
    return descriptor.get.call(receiver);
  }

  return descriptor.value;
}

function _classApplyDescriptorSet(receiver, descriptor, value) {
  if (descriptor.set) {
    descriptor.set.call(receiver, value);
  } else {
    if (!descriptor.writable) {
      throw new TypeError("attempted to set read only private field");
    }

    descriptor.value = value;
  }
}

function _classPrivateMethodGet(receiver, privateSet, fn) {
  if (!privateSet.has(receiver)) {
    throw new TypeError("attempted to get private field on non-instance");
  }

  return fn;
}

function _checkPrivateRedeclaration(obj, privateCollection) {
  if (privateCollection.has(obj)) {
    throw new TypeError("Cannot initialize the same private elements twice on an object");
  }
}

function _classPrivateFieldInitSpec(obj, privateMap, value) {
  _checkPrivateRedeclaration(obj, privateMap);

  privateMap.set(obj, value);
}

function _classPrivateMethodInitSpec(obj, privateSet) {
  _checkPrivateRedeclaration(obj, privateSet);

  privateSet.add(obj);
}

var list = [" daum[\\s/]"," deusu/","(?:^|\\s)site","@[a-z]","\\(at\\)[a-z]","\\(github\\.com/","\\[at\\][a-z]","^12345","^<","^[\\w\\s\\.]+/v?\\d+(\\.\\d+)?(\\.\\d{1,10})?$","^[\\w]+$","^ace explorer","^acoon","^active","^ad muncher","^anglesharp/","^apple-pubsub/","^astute srm","^avsdevicesdk/","^bidtellect/","^biglotron","^blackboard safeassign","^blocknote.net","^braze sender","^camo asset proxy","^captivenetworksupport","^castro","^clamav[\\s/]","^cobweb/","^coccoc","^dap ","^ddg[_-]android","^discourse","^dispatch/\\d","^downcast/","^duckduckgo","^enigma browser","^evernote clip resolver","^facebook","^faraday","^fdm[\\s/]\\d","^getright/","^gozilla/","^hatena","^hobbit","^hotzonu","^hwcdn/","^infox-wisg","^invision","^jeode/","^jetbrains","^jetty/","^jigsaw","^linkdex","^lwp-","^lwp::simple","^mailchimp\\.com$","^metauri","^microsoft bits","^microsoft data","^microsoft office existence","^microsoft office protocol discovery","^microsoft windows network diagnostics","^microsoft-cryptoapi","^microsoft-webdav-miniredir","^movabletype","^mozilla/\\d\\.\\d \\(compatible;?\\)$","^my browser$","^navermailapp","^netsurf","^node-superagent","^octopus","^offline explorer","^ossproxy","^pagething","^panscient","^perimeterx","^php","^postrank","^python","^ramblermail","^read","^reed","^restsharp/","^shareaza","^shockwave flash","^smallproxy","^snapchat","^space bison","^sprinklr","^svn","^swcd ","^t-online browser","^taringa","^test certificate info","^the knowledge ai","^thinklab","^traackr.com","^tumblr/","^vbulletin","^venus/fedoraplanet","^w3c","^webbandit/","^webcopier","^wget","^whatsapp","^www-mechanize","^xenu link sleuth","^yahoo","^yandex","^zdm/\\d","^zeushdthree","adbeat\\.com","appinsights","archive","ask jeeves/teoma","bit\\.ly/","bluecoat drtr","bot","browsex","burpcollaborator","capture","catch","check","chrome-lighthouse","chromeframe","client","cloud","crawl","daemon","dareboost","datanyze","dataprovider","dejaclick","dmbrowser","download","email","evc-batch/","feed","fetch","firephp","freesafeip","ghost","gomezagent","google","headlesschrome/","http","httrack","hubspot marketing grader","hydra","ibisbrowser","images","index","ips-agent","java","jorgee","library","mail\\.ru/","manager","monitor","neustar wpm","news","nutch","offbyone","optimize","pagespeed","parse","perl","phantom","pingdom","powermarks","preview","probe","ptst[\\s/]\\d","reader","rigor","rss","scan","scrape","search","server","sogou","sparkler/","spider","statuscake","stumbleupon\\.com","supercleaner","synapse","synthetic","toolbar","torrent","tracemyfile","transcoder","trendsmapresolver","twingly recon","url","valid","virtuoso","wappalyzer","webglance","webkit2png","websitemetadataretriever","whatcms/","wordpress","zgrab"];

/**
 * Mutate given list of patter strings
 * @param {string[]} list
 * @returns {string[]}
 */
function amend(list) {
  try {
    // Risk: Uses lookbehind assertion, avoid breakage in parsing by using RegExp constructor
    new RegExp('(?<! cu)bot').test('dangerbot'); // eslint-disable-line prefer-regex-literals
  } catch (error) {
    // Skip regex fixes
    return list;
  } // Addresses: Cubot device


  list.splice(list.lastIndexOf('bot'), 1);
  list.push('(?<! cu)bot'); // Addresses: Android webview

  list.splice(list.lastIndexOf('google'), 1);
  list.push('(?<! (channel\\/|google\\/))google(?!(app|\\/google))'); // Addresses: Yandex browser

  list.splice(list.lastIndexOf('search'), 1);
  list.push('(?<! (ya|yandex))search'); // Addresses: libhttp browser

  list.splice(list.lastIndexOf('http'), 1);
  list.push('(?<!(lib))http'); // Addresses: java based browsers

  list.splice(list.lastIndexOf('java'), 1);
  list.push('java(?!;)'); // Addresses: Mozilla nightly build https://github.com/mozilla-mobile/android-components/search?q=MozacFetch

  list.splice(list.lastIndexOf('fetch'), 1);
  list.push('(?<!(mozac))fetch');
  return list;
}

amend(list);
/**
 * Test user agents for matching patterns
 */

var _list = /*#__PURE__*/new WeakMap();

var _pattern = /*#__PURE__*/new WeakMap();

var _update = /*#__PURE__*/new WeakSet();

var _index = /*#__PURE__*/new WeakSet();

var Isbot = /*#__PURE__*/function () {
  /**
   * @type {string[]}
   */

  /**
   * @type {RegExp}
   */
  function Isbot(patterns) {
    _classCallCheck(this, Isbot);

    _classPrivateMethodInitSpec(this, _index);

    _classPrivateMethodInitSpec(this, _update);

    _classPrivateFieldInitSpec(this, _list, {
      writable: true,
      value: void 0
    });

    _classPrivateFieldInitSpec(this, _pattern, {
      writable: true,
      value: void 0
    });

    _classPrivateFieldSet(this, _list, patterns || list.slice());

    _classPrivateMethodGet(this, _update, _update2).call(this);
  }
  /**
   * Recreate the pattern from rules list
   */


  _createClass(Isbot, [{
    key: "test",
    value:
    /**
     * Match given string against out pattern
     * @param  {string} ua User Agent string
     * @returns {boolean}
     */
    function test(ua) {
      return Boolean(ua) && _classPrivateFieldGet(this, _pattern).test(ua);
    }
    /**
     * Get the match for strings' known crawler pattern
     * @param  {string} ua User Agent string
     * @returns {string}
     */

  }, {
    key: "find",
    value: function find() {
      var ua = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
      var match = ua.match(_classPrivateFieldGet(this, _pattern));
      return match && match[0];
    }
    /**
     * Extent patterns for known crawlers
     * @param  {string[]} filters
     * @returns {void}
     */

  }, {
    key: "extend",
    value: function extend() {
      var _this = this;

      var filters = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
      [].push.apply(_classPrivateFieldGet(this, _list), filters.filter(function (rule) {
        return _classPrivateMethodGet(_this, _index, _index2).call(_this, rule) === -1;
      }).map(function (filter) {
        return filter.toLowerCase();
      }));

      _classPrivateMethodGet(this, _update, _update2).call(this);
    }
    /**
     * Exclude patterns from bot pattern rule
     * @param  {string[]} filters
     * @returns {void}
     */

  }, {
    key: "exclude",
    value: function exclude() {
      var filters = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
      var length = filters.length;

      while (length--) {
        var index = _classPrivateMethodGet(this, _index, _index2).call(this, filters[length]);

        if (index > -1) {
          _classPrivateFieldGet(this, _list).splice(index, 1);
        }
      }

      _classPrivateMethodGet(this, _update, _update2).call(this);
    }
    /**
     * Create a new Isbot instance using given list or self's list
     * @param  {string[]} [list]
     * @returns {Isbot}
     */

  }, {
    key: "spawn",
    value: function spawn(list) {
      return new Isbot(list || _classPrivateFieldGet(this, _list));
    }
  }]);

  return Isbot;
}();

function _update2() {
  _classPrivateFieldSet(this, _pattern, new RegExp(_classPrivateFieldGet(this, _list).join('|'), 'i'));
}

function _index2(rule) {
  return _classPrivateFieldGet(this, _list).indexOf(rule.toLowerCase());
}

var createInterface = function createInterface(instance) {
  return Object.defineProperties(function isbot(ua) {
    return instance.test(ua);
  }, {
    find: {
      get: function get() {
        return function (ua) {
          return instance.find(ua);
        };
      }
    },
    extend: {
      get: function get() {
        return function (list) {
          return instance.extend(list);
        };
      }
    },
    exclude: {
      get: function get() {
        return function (list) {
          return instance.exclude(list);
        };
      }
    },
    spawn: {
      get: function get() {
        return function (list) {
          return createInterface(instance.spawn(list));
        };
      }
    }
  });
};

var isbot = createInterface(new Isbot());

module.exports = isbot;
//# sourceMappingURL=index.js.map
