UNPKG

bs-broken-links-checker

Version:
189 lines (165 loc) 4.17 kB
/** * @exports * @desc * Main checker model class */ "use strict"; var _createClass = require("babel-runtime/helpers/create-class")["default"]; var _classCallCheck = require("babel-runtime/helpers/class-call-check")["default"]; var _Map = require("babel-runtime/core-js/map")["default"]; Object.defineProperty(exports, "__esModule", { value: true }); var Model = (function () { function Model() { _classCallCheck(this, Model); /** * Pending queue * @type {Array} */ this._pending = []; /** * Performed items * @type {Array} */ this._active = []; /** * Map of external link items * @type {Map} */ this._external = new _Map(); /** * Map of processed link items * @type {Map} */ this._processed = new _Map(); } /** * Getter for external links items map * @return {Map} external items map */ _createClass(Model, [{ key: "addToExternal", /** * Add item to external links model * @param {String} url resolved from href * @param {String} baseUrl page url where href was discovered * @param {String} href found in document * @returns {Model} */ value: function addToExternal(url, baseUrl, href) { this._external.set(url, { page: baseUrl, href: href }); return this; } /** * Add link url to list of active (checked at this moment) * @param {String} url of href found on page */ }, { key: "addToActive", value: function addToActive(url) { this._active.push(url); return this; } /** * Adds item to array of pending items * @param {String} url resolved url of link * @param {Object} advanced info object * @returns {Model} */ }, { key: "addToPending", value: function addToPending(url, advanced) { this._pending.push({ url: url, advanced: advanced }); return this; } /** * Returns length of active items array * @return {Number} */ }, { key: "getActiveLength", value: function getActiveLength() { return this._active.length; } /** * Returns length of pending items array * @return {Number} */ }, { key: "getPendingLength", value: function getPendingLength() { return this._pending.length; } /** * Returns true if external items map contains items * @return {Boolean} */ }, { key: "areExternal", value: function areExternal() { return !!this._external.size; } /** * Returns true if active items array contains items * @return {Boolean} */ }, { key: "areActive", value: function areActive() { return !!this.getActiveLength(); } /** * Returns true of length of active items greater then given max number * @param {[type]} max [description] * @return {Boolean} [description] */ }, { key: "isQueueFull", value: function isQueueFull(max) { return this._active.length >= max; } /** * Returns true if items was not at provessed items * Also item is put into processed map * @param {String} url resolved from link */ }, { key: "addToProcessed", value: function addToProcessed(url) { if (this._processed.has(url)) { return false; } this._processed.set(url, true); return true; } /** * Removes item corresponded to given url from active items array * @param {String} url resolved from link * @return {Model} */ }, { key: "removeFromActive", value: function removeFromActive(url) { this._active.splice(this._active.indexOf(url), 1); return this; } /** * Removes first item from pending items array and returns it * @return {Object} */ }, { key: "removeFromPending", value: function removeFromPending() { return this._pending.shift(); } }, { key: "external", get: function get() { return this._external; } }]); return Model; })(); exports["default"] = Model; module.exports = exports["default"];