feedparser
Advanced tools
Comparing version 0.3.1 to 0.3.2
@@ -47,17 +47,9 @@ /********************************************************************** | ||
var self = this; | ||
self.meta = {}; | ||
self.articles = []; | ||
self.stack = []; | ||
self.nodes = {}; | ||
self.xmlbase = []; | ||
self.in_xhtml = false; | ||
self.xhtml = {}; /* Where to store xhtml elements as associative | ||
array with keys: '#' (containing the text) | ||
and '#name' (containing the XML element name) */ | ||
self.saxStream = require('sax').createStream(false, {lowercasetags: true}); // https://github.com/isaacs/sax-js | ||
self.saxStream.on('error', function (e) { self.handleError(e, self) }); | ||
self.saxStream.on('opentag', function (n) { self.handleOpenTag(n, self) }); | ||
self.saxStream.on('closetag', function (el) { self.handleCloseTag(el, self) }); | ||
self.saxStream.on('text', function (text) { self.handleText(text, self) }); | ||
self.saxStream.on('cdata', function (text) { self.handleText(text, self) }); | ||
self.saxStream.on('error', function (e){ self.handleError(e, self) }); | ||
self.saxStream.on('opentag', function (n){ self.handleOpenTag(n, self) }); | ||
self.saxStream.on('closetag', function (el){ self.handleCloseTag(el, self) }); | ||
self.saxStream.on('text', function (text){ self.handleText(text, self) }); | ||
self.saxStream.on('cdata', function (text){ self.handleText(text, self) }); | ||
self.saxStream.on('end', function (){ self.handleEnd(self) }); | ||
events.EventEmitter.call(this); | ||
@@ -101,12 +93,4 @@ } | ||
var self = this; | ||
this.saxStream.on('end', function () { | ||
if (self.articles.length) { | ||
self.emit('end', self.articles); | ||
self.emit('done', self.articles); // deprecated | ||
} | ||
if ('function' == typeof callback) { | ||
callback(self.meta, self.articles); | ||
} | ||
}); | ||
this.saxStream.end(string, 'utf8'); | ||
self._reset(); | ||
self.saxStream.end(string, 'utf8'); | ||
}; | ||
@@ -125,15 +109,7 @@ | ||
var self = this; | ||
self.saxStream.on('end', function () { | ||
if (self.articles.length) { | ||
self.emit('end', self.articles); | ||
self.emit('done', self.articles); // deprecated | ||
} | ||
if ('function' == typeof callback) { | ||
callback(self.meta, self.articles); | ||
} | ||
}); | ||
self._reset(); | ||
if (/^https?:/.test(file) || (typeof file == 'object' && 'protocol' in file)) { | ||
self.parseUrl(file, callback); | ||
} else { | ||
fs.createReadStream(file).pipe(this.saxStream); | ||
fs.createReadStream(file).pipe(self.saxStream); | ||
} | ||
@@ -157,12 +133,4 @@ }; | ||
var self = this; | ||
self.saxStream.on('end', function () { | ||
if (self.articles.length) { | ||
self.emit('end', self.articles); | ||
self.emit('done', self.articles); // deprecated | ||
} | ||
if ('function' == typeof callback) { | ||
callback(self.meta, self.articles); | ||
} | ||
}); | ||
request(url).pipe(this.saxStream); | ||
self._reset(); | ||
request(url).pipe(self.saxStream); | ||
}; | ||
@@ -187,14 +155,21 @@ | ||
var self = this; | ||
self.saxStream.on('end', function () { | ||
if (self.articles.length) { | ||
self.emit('end', self.articles); | ||
self.emit('done', self.articles); // deprecated | ||
} | ||
if ('function' == typeof callback) { | ||
callback(self.meta, self.articles); | ||
} | ||
}); | ||
stream.pipe(this.saxStream); | ||
self._reset(); | ||
stream.pipe(self.saxStream); | ||
}; | ||
FeedParser.prototype.handleEnd = function (scope){ | ||
var self = scope; | ||
var meta = self.meta | ||
, articles = self.articles; | ||
if (articles.length) { | ||
self.emit('end', articles); | ||
self.emit('done', articles); // deprecated | ||
} | ||
if ('function' == typeof callback) { | ||
callback(meta, articles); | ||
} | ||
}; | ||
FeedParser.prototype.handleError = function (e, scope){ | ||
@@ -494,2 +469,14 @@ var self = scope; | ||
FeedParser.prototype._reset = function () { | ||
this.meta = {}; | ||
this.articles = []; | ||
this.stack = []; | ||
this.nodes = {}; | ||
this.xmlbase = []; | ||
this.in_xhtml = false; | ||
this.xhtml = {}; /* Where to store xhtml elements as associative | ||
array with keys: '#' (containing the text) | ||
and '#name' (containing the XML element name) */ | ||
} | ||
exports = module.exports = FeedParser; |
@@ -5,3 +5,3 @@ { | ||
"description": "Robust RSS, Atom, and RDF feed parsing using sax js", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"repository": { | ||
@@ -8,0 +8,0 @@ "type": "git", |
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
19717
463