mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-28 17:35:49 +08:00
* Move node-feedparser to feedparser. Resolves #17467. * Fix test name * Fix import in test for feedparser.
This commit is contained in:
32
types/feedparser/feedparser-tests.ts
Normal file
32
types/feedparser/feedparser-tests.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import request = require('request');
|
||||
import * as FeedParser from "feedparser";
|
||||
|
||||
const req = request('https://news.google.com/news?cf=all&hl=en&pz=1&ned=us&output=rss');
|
||||
const feedparser = new FeedParser({});
|
||||
|
||||
req.on("error", error => {
|
||||
// handle any request errors
|
||||
});
|
||||
|
||||
req.on("response", res => {
|
||||
if (res.statusCode !== 200) {
|
||||
req.emit('error', new Error('Bad status code'));
|
||||
} else {
|
||||
req.pipe(feedparser);
|
||||
}
|
||||
});
|
||||
|
||||
feedparser.on('error', (error: Error) => {
|
||||
// always handle errors
|
||||
});
|
||||
|
||||
feedparser.on('readable', () => {
|
||||
// This is where the action is!
|
||||
const stream = feedparser;
|
||||
const meta = feedparser.meta; // **NOTE** the "meta" is always available in the context of the feedparser instance
|
||||
let item: FeedParser.Item;
|
||||
|
||||
while (item = stream.read()) {
|
||||
console.log(item);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user