sitemapper
Advanced tools
Comparing version 3.1.9 to 3.1.10
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _xml2js=require("xml2js"),_got=_interopRequireDefault(require("got"));function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}class Sitemapper{constructor(a){var b=a||{requestHeaders:{}};this.url=b.url,this.timeout=b.timeout||15e3,this.timeoutTable={},this.requestHeaders=b.requestHeaders,this.debug=b.debug}fetch(){var a=0<arguments.length&&arguments[0]!==void 0?arguments[0]:this.url;return new Promise(b=>this.crawl(a).then(c=>b({url:a,sites:c})))}static get timeout(){return this.timeout}static set timeout(a){this.timeout=a}static set url(a){this.url=a}static get url(){return this.url}static set debug(a){this.debug=a}static get debug(){return this.debug}parse(){var a=0<arguments.length&&arguments[0]!==void 0?arguments[0]:this.url,b={method:"GET",resolveWithFullResponse:!0,gzip:!0,headers:this.requestHeaders};return new Promise(c=>{var d=(0,_got.default)(a,b);d.then(b=>b&&200===b.statusCode?(0,_xml2js.parseStringPromise)(b.body):(clearTimeout(this.timeoutTable[a]),c({error:b.error,data:b}))).then(a=>c({error:null,data:a})).catch(a=>c({error:a.error,data:a})),this.initializeTimeout(a,d,c)})}initializeTimeout(a,b,c){this.timeoutTable[a]=setTimeout(()=>{b.cancel(),this.debug&&console.debug("crawl timed out"),c({error:"request timed out after ".concat(this.timeout," milliseconds for url: '").concat(a,"'"),data:{}})},this.timeout)}crawl(a){return new Promise(b=>{this.parse(a).then((c)=>{var{error:d,data:e}=c;if(clearTimeout(this.timeoutTable[a]),d)return this.debug&&console.error("Error occurred during \"crawl('".concat(a,"')\":\n\r Error: ").concat(d)),b([]);if(e&&e.urlset&&e.urlset.url){this.debug&&console.debug("Urlset found during \"crawl('".concat(a,"')\""));var h=e.urlset.url.map(a=>a.loc&&a.loc[0]);return b([].concat(h))}if(e&&e.sitemapindex){this.debug&&console.debug("Additional sitemap found during \"crawl('".concat(a,"')\""));var f=e.sitemapindex.sitemap.map(a=>a.loc&&a.loc[0]),g=f.map(a=>this.crawl(a));return Promise.all(g).then(a=>{var c=a.filter(a=>!a.error).reduce((a,b)=>a.concat(b),[]);return b(c)})}return this.debug&&console.error("Unknown state during \"crawl(".concat(a,")\":"),d,e),b([])})})}getSites(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:this.url,b=1<arguments.length?arguments[1]:void 0;console.warn("\r\nWarning:","function .getSites() is deprecated, please use the function .fetch()\r\n");var c={},d=[];return this.fetch(a).then(a=>{d=a.sites}).catch(a=>{c=a}),b(c,d)}}exports.default=Sitemapper,module.exports=exports.default,module.exports.default=exports.default; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _xml2js=require("xml2js"),_got=_interopRequireDefault(require("got"));function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}function asyncGeneratorStep(a,b,c,d,e,f,g){try{var h=a[f](g),i=h.value}catch(a){return void c(a)}h.done?b(i):Promise.resolve(i).then(d,e)}function _asyncToGenerator(a){return function(){var b=this,c=arguments;return new Promise(function(d,e){function f(a){asyncGeneratorStep(h,d,e,f,g,"next",a)}function g(a){asyncGeneratorStep(h,d,e,f,g,"throw",a)}var h=a.apply(b,c);f(void 0)})}}class Sitemapper{constructor(a){var b=a||{requestHeaders:{}};this.url=b.url,this.timeout=b.timeout||15e3,this.timeoutTable={},this.requestHeaders=b.requestHeaders,this.debug=b.debug}fetch(){var a=arguments,b=this;return _asyncToGenerator(function*(){var c=0<a.length&&a[0]!==void 0?a[0]:b.url,d=[];try{d=yield b.crawl(c)}catch(a){b.debug&&console.error(a)}return{url:c,sites:d}})()}static get timeout(){return this.timeout}static set timeout(a){this.timeout=a}static set url(a){this.url=a}static get url(){return this.url}static set debug(a){this.debug=a}static get debug(){return this.debug}parse(){var a=arguments,b=this;return _asyncToGenerator(function*(){var c=0<a.length&&a[0]!==void 0?a[0]:b.url,d={method:"GET",resolveWithFullResponse:!0,gzip:!0,headers:b.requestHeaders};try{var e=(0,_got.default)(c,d);b.initializeTimeout(c,e);var f=yield e;if(!f||200!==f.statusCode)return clearTimeout(b.timeoutTable[c]),{error:f.error,data:f};var g=yield(0,_xml2js.parseStringPromise)(f.body);return{error:null,data:g}}catch(a){return"CancelError"===a.name?{error:"Request timed out after ".concat(b.timeout," milliseconds for url: '").concat(c,"'"),data:a}:{error:a.error,data:a}}})()}initializeTimeout(a,b){this.timeoutTable[a]=setTimeout(()=>b.cancel(),this.timeout)}crawl(a){var b=this;return _asyncToGenerator(function*(){try{var{error:g,data:h}=yield b.parse(a);if(clearTimeout(b.timeoutTable[a]),g)return b.debug&&console.error("Error occurred during \"crawl('".concat(a,"')\":\n\r Error: ").concat(g)),[];if(h&&h.urlset&&h.urlset.url){b.debug&&console.debug("Urlset found during \"crawl('".concat(a,"')\""));var i=h.urlset.url.map(a=>a.loc&&a.loc[0]);return[].concat(i)}if(h&&h.sitemapindex){b.debug&&console.debug("Additional sitemap found during \"crawl('".concat(a,"')\""));var c=h.sitemapindex.sitemap.map(a=>a.loc&&a.loc[0]),d=c.map(a=>b.crawl(a)),e=yield Promise.all(d),f=e.filter(a=>!a.error).reduce((a,b)=>a.concat(b),[]);return f}return b.debug&&console.error("Unknown state during \"crawl('".concat(a,")'\":"),g,h),[]}catch(a){b.debug&&b.debug&&console.error(a)}})()}getSites(){var a=arguments,b=this;return _asyncToGenerator(function*(){var c=0<a.length&&a[0]!==void 0?a[0]:b.url,d=1<a.length?a[1]:void 0;console.warn("\r\nWarning:","function .getSites() is deprecated, please use the function .fetch()\r\n");var f={},g=[];try{var h=yield b.fetch(c);g=h.sites}catch(a){f=a}return d(f,g)})()}}exports.default=Sitemapper,module.exports=exports.default,module.exports.default=exports.default; | ||
//# sourceMappingURL=sitemapper.js.map |
@@ -1,2 +0,2 @@ | ||
"use strict";var _sitemapper=_interopRequireDefault(require("../assets/sitemapper"));function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}function asyncGeneratorStep(a,b,c,d,e,f,g){try{var h=a[f](g),i=h.value}catch(a){return void c(a)}h.done?b(i):Promise.resolve(i).then(d,e)}function _asyncToGenerator(a){return function(){var b=this,c=arguments;return new Promise(function(d,e){function f(a){asyncGeneratorStep(h,d,e,f,g,"next",a)}function g(a){asyncGeneratorStep(h,d,e,f,g,"throw",a)}var h=a.apply(b,c);f(void 0)})}}var exampleURL="https://www.walmart.com/sitemap_topic.xml",sitemapper=new _sitemapper.default({url:"https://www.walmart.com/sitemap_topic.xml",debug:!0,timeout:1e4});_asyncToGenerator(function*(){try{var a=yield sitemapper.fetch();console.log(a)}catch(a){console.error(a)}})(); | ||
"use strict";var _sitemapper=_interopRequireDefault(require("../assets/sitemapper"));function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}function asyncGeneratorStep(a,b,c,d,e,f,g){try{var h=a[f](g),i=h.value}catch(a){return void c(a)}h.done?b(i):Promise.resolve(i).then(d,e)}function _asyncToGenerator(a){return function(){var b=this,c=arguments;return new Promise(function(d,e){function f(a){asyncGeneratorStep(h,d,e,f,g,"next",a)}function g(a){asyncGeneratorStep(h,d,e,f,g,"throw",a)}var h=a.apply(b,c);f(void 0)})}}var exampleURL="https://www.walmart.com/sitemap_topic.xml",sitemapper=new _sitemapper.default({url:"https://www.walmart.com/sitemap_topic.xml",debug:!0,timeout:1});_asyncToGenerator(function*(){try{var a=yield sitemapper.fetch();console.log(a)}catch(a){console.error(a)}})(); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "sitemapper", | ||
"version": "3.1.9", | ||
"version": "3.1.10", | ||
"description": "Parser for XML Sitemaps to be used with Robots.txt and web crawlers", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -37,15 +37,18 @@ ## Sitemap-parser | ||
const Google = new Sitemapper({ | ||
url: 'https://www.google.com/work/sitemap.xml', | ||
timeout: 15000, // 15 seconds | ||
}); | ||
(async () => { | ||
const Google = new Sitemapper({ | ||
url: 'https://www.google.com/work/sitemap.xml', | ||
timeout: 15000, // 15 seconds | ||
}); | ||
Google.fetch() | ||
.then(data => console.log(data.sites)) | ||
.catch(error => console.log(error)); | ||
try { | ||
const { sites } = await Google.fetch(); | ||
console.log(sites); | ||
catch (error) { | ||
console.log(error); | ||
} | ||
})(); | ||
// or | ||
const sitemapper = new Sitemapper(); | ||
@@ -52,0 +55,0 @@ sitemapper.timeout = 5000; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
11939
38
133
0