sitemap-stream-parser
Advanced tools
Comparing version 1.5.1 to 1.6.0
117
index.js
@@ -1,5 +0,4 @@ | ||
// Generated by CoffeeScript 1.12.7 | ||
// Generated by CoffeeScript 2.3.2 | ||
(function() { | ||
var SitemapParser, agentOptions, async, headers, request, sax, urlParser, zlib, | ||
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; | ||
var SitemapParser, agentOptions, async, headers, request, sax, urlParser, zlib; | ||
@@ -17,3 +16,3 @@ request = require('request'); | ||
headers = { | ||
'user-agent': '404check.io (http://404check.io)' | ||
'user-agent': process.env.USER_AGENT || 'node-sitemap-stream-parser' | ||
}; | ||
@@ -27,16 +26,16 @@ | ||
request = request.defaults({ | ||
headers: headers, | ||
agentOptions: agentOptions, | ||
headers, | ||
agentOptions, | ||
timeout: 60000 | ||
}); | ||
SitemapParser = (function() { | ||
function SitemapParser(url_cb1, sitemap_cb1) { | ||
SitemapParser = class SitemapParser { | ||
constructor(url_cb1, sitemap_cb1) { | ||
this.parse = this.parse.bind(this); | ||
this.url_cb = url_cb1; | ||
this.sitemap_cb = sitemap_cb1; | ||
this.parse = bind(this.parse, this); | ||
this.visited_sitemaps = {}; | ||
} | ||
SitemapParser.prototype._download = function(url, parserStream, done) { | ||
_download(url, parserStream, done) { | ||
var stream, unzip; | ||
@@ -46,3 +45,3 @@ if (url.lastIndexOf('.gz') === url.length - 3) { | ||
return request.get({ | ||
url: url, | ||
url, | ||
encoding: null | ||
@@ -52,15 +51,13 @@ }).pipe(unzip).pipe(parserStream); | ||
stream = request.get({ | ||
url: url, | ||
url, | ||
gzip: true | ||
}); | ||
stream.on('error', (function(_this) { | ||
return function(err) { | ||
return done(err); | ||
}; | ||
})(this)); | ||
stream.on('error', (err) => { | ||
return done(err); | ||
}); | ||
return stream.pipe(parserStream); | ||
} | ||
}; | ||
} | ||
SitemapParser.prototype.parse = function(url, done) { | ||
parse(url, done) { | ||
var inLoc, isSitemapIndex, isURLSet, parserStream; | ||
@@ -76,46 +73,36 @@ isURLSet = false; | ||
}); | ||
parserStream.on('opentag', (function(_this) { | ||
return function(node) { | ||
inLoc = node.name === 'loc'; | ||
if (node.name === 'urlset') { | ||
isURLSet = true; | ||
} | ||
if (node.name === 'sitemapindex') { | ||
return isSitemapIndex = true; | ||
} | ||
}; | ||
})(this)); | ||
parserStream.on('error', (function(_this) { | ||
return function(err) { | ||
return done(err); | ||
}; | ||
})(this)); | ||
parserStream.on('text', (function(_this) { | ||
return function(text) { | ||
text = urlParser.resolve(url, text); | ||
if (inLoc) { | ||
if (isURLSet) { | ||
return _this.url_cb(text, url); | ||
} else if (isSitemapIndex) { | ||
if (_this.visited_sitemaps[text] != null) { | ||
return console.error("Already parsed sitemap: " + text); | ||
} else { | ||
return _this.sitemap_cb(text); | ||
} | ||
parserStream.on('opentag', (node) => { | ||
inLoc = node.name === 'loc'; | ||
if (node.name === 'urlset') { | ||
isURLSet = true; | ||
} | ||
if (node.name === 'sitemapindex') { | ||
return isSitemapIndex = true; | ||
} | ||
}); | ||
parserStream.on('error', (err) => { | ||
return done(err); | ||
}); | ||
parserStream.on('text', (text) => { | ||
text = urlParser.resolve(url, text); | ||
if (inLoc) { | ||
if (isURLSet) { | ||
return this.url_cb(text, url); | ||
} else if (isSitemapIndex) { | ||
if (this.visited_sitemaps[text] != null) { | ||
return console.error(`Already parsed sitemap: ${text}`); | ||
} else { | ||
return this.sitemap_cb(text); | ||
} | ||
} | ||
}; | ||
})(this)); | ||
parserStream.on('end', (function(_this) { | ||
return function() { | ||
return done(null); | ||
}; | ||
})(this)); | ||
} | ||
}); | ||
parserStream.on('end', () => { | ||
return done(null); | ||
}); | ||
return this._download(url, parserStream, done); | ||
}; | ||
} | ||
return SitemapParser; | ||
}; | ||
})(); | ||
exports.parseSitemap = function(url, url_cb, sitemap_cb, done) { | ||
@@ -127,4 +114,8 @@ var parser; | ||
exports.parseSitemaps = function(urls, url_cb, done, sitemap_test) { | ||
exports.parseSitemaps = function(urls, url_cb, sitemap_test, done) { | ||
var parser, queue; | ||
if (!done) { | ||
done = sitemap_test; | ||
sitemap_test = void 0; | ||
} | ||
if (!(urls instanceof Array)) { | ||
@@ -147,2 +138,8 @@ urls = [urls]; | ||
exports.parseSitemapsPromise = function(urls, url_cb, sitemap_test) { | ||
return new Promise(function(resolve) { | ||
return exports.parseSitemaps(urls, url_cb, sitemap_test, resolve); | ||
}); | ||
}; | ||
exports.sitemapsInRobots = function(url, cb) { | ||
@@ -155,3 +152,3 @@ return request.get(url, function(err, res, body) { | ||
if (res.statusCode !== 200) { | ||
return cb("statusCode: " + res.statusCode); | ||
return cb(`statusCode: ${res.statusCode}`); | ||
} | ||
@@ -158,0 +155,0 @@ matches = []; |
{ | ||
"name": "sitemap-stream-parser", | ||
"version": "1.5.1", | ||
"version": "1.6.0", | ||
"description": "Get a list of URLs from one or more sitemaps", | ||
@@ -32,4 +32,4 @@ "main": "index.js", | ||
"devDependencies": { | ||
"coffeescript": "^1.10.0" | ||
"coffeescript": "^2.3.2" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
35751
180
2