/** * Sitemap Parser * * Copyright (c) 2014 Sean Thomas Burke * Licensed under the MIT license. * @author Sean Burke */ import { ISiteMapperResult } from "./ISiteMapperIndex"; import { ISitemapperOptions } from "./ISitemapperOptions"; import { ISitemapperResponse } from "./ISitemapperResponse"; /** * Sitemapper */ export default class Sitemapper { private _requester; /** * Get the timeout * * @example * console.log(sitemapper.timeout); * @returns {number} timeout */ /** * Set the timeout * * @public * @param {Timeout} duration * @example * sitemapper.timeout = 15000; // 15 seconds */ timeout: number; /** * * @param {string} url - url for making requests. Should be a link to a sitemaps.xml * @example * sitemapper.url = 'http://wp.seantburke.com/sitemap.xml' */ /** * Get the url to parse * @returns {string} * @example * console.log(sitemapper.url) */ url: any; private _url; private _timeout; /** * Construct the Sitemapper class * * @params {Object} options to set * @params {string} [options.url] - the Sitemap url (e.g http://wp.seantburke.com/sitemap.xml) * @params {Timeout} [options.timeout] - the number of milliseconds before all requests timeout. The promises will still resolve so * you'll still receive parts of the request, but maybe not all urls * default is 15000 which is 15 seconds * * @example * let sitemap = new Sitemapper({ * url: 'http://wp.seantburke.com/sitemap.xml', * timeout: 15000 * }); */ constructor(options?: ISitemapperOptions); /** * Gets the sites from a sitemap.xml with a given URL * * @public * @param {string} url - the Sitemaps url (e.g http://wp.seantburke.com/sitemap.xml) * @returns {Promise} * @example * sitemapper.fetch('example.xml') * .then((sites) => console.log(sites)); */ fetch(url?: string): Promise; /** * Resolve handler type for the promise in this.parse() * * @typedef {Object} ParseData * * @property {Error} error that either comes from `xmlParse` or `request` or custom error * @property {Object} data * @property {string} data.url - URL of sitemap * @property {Array} data.urlset - Array of returned URLs * @property {string} data.urlset.url - single Url * @property {Object} data.sitemapindex - index of sitemap * @property {string} data.sitemapindex.sitemap - Sitemap * @example { * error: "There was an error!" * data: { * url: 'linkedin.com', * urlset: [{ * url: 'www.linkedin.com/project1' * },[{ * url: 'www.linkedin.com/project2' * }] * } * } */ /** * Requests the URL and uses xmlParse to parse through and find the data * * @private * @param {string} [url] - the Sitemaps url (e.g http://wp.seantburke.com/sitemap.xml) * @returns {Promise} */ parse(url?: string): Promise; /** * Recursive function that will go through a sitemaps tree and get all the sites * * @private * @recursive * @param {string} url - the Sitemaps url (e.g http://wp.seantburke.com/sitemap.xml) * @param {string} lastmod - internal optional - the lastmod to set on single sitemap * @returns {Promise} An array of urls */ crawlSite(url?: string, lastmod?: string): Promise; /** * Recursive function that will go through a sitemaps tree and get all the sites * * @private * @recursive * @param {string} url - the Sitemaps url (e.g http://wp.seantburke.com/sitemap.xml) * @returns {Promise} An array of urls */ crawl(url?: string): Promise; /** * Callback for the getSites method * * @callback getSitesCallback * @param {Object} error - error from callback * @param {Array} sites - an Array of sitemaps */ /** * Gets the sites from a sitemap.xml with a given URL * @deprecated * @param {string} url - url to query * @param {getSitesCallback} callback - callback for sites and error * @callback */ getSites(url: string, callback: (err: Error, sites?: string[]) => void): void; private parseXml; }