The pickup Node package transforms XML feeds to JSON or objects. Exporting a Transform stream, it parses RSS 2.0, including iTunes namespace extensions, and Atom 1.0 formatted XML, producing newline separated JSON strings or objects.
$ export URL=https://www.newyorker.com/feed/posts
$ curl -sS $URL | node ./example/stdin.js
The Standard Input example is more or less the CLI binary of pickup, ./bin/cli.js, which you can install globally if you want to.
npm i -g pickup
💡 You can use pickup, node ./example/stdin.js, or node ./bin/cli.js in these examples.
Piping data to pickup, you can now, for example, parse feeds from the network using curl on the command-line.
$ curl -sS $URL | pickup
For convenient JSON massaging, I use json, available on npm.
$ npm install -g json
Now you can extend your pipe for correct formatting…
$ curl -sS $URL | pickup | json -g
…and handy filtering.
$ curl -sS $URL | pickup | json -ga title
Being a library user of this module, my preferred interface for exploring, and testing while working on it, is its REPL.
$ ./repl.js
pickup> let x = get('https://www.newyorker.com/feed/posts')
pickup> read(x, Entry, 'title')
pickup> 'An Asylum Seeker’s Quest to Get Her Toddler Back'
'At N.H.L.’s All-Star Weekend, Female Players Prove Their Excellence, but NBC Can’t Keep Up'
'Cliff Sims Is Proud to Have Served Trump'
'The Slimmed-Down and Soothing New “Conan”'
'Donald Trump’s Chance to Bring Peace to Afghanistan and End America’s Longest War'
'The First Days of Disco'
'How Various Government Agencies Celebrated the End of the Shutdown'
'Why We Care (and Don’t Care) About the New Rules of Golf'
'Howard Schultz Against the Hecklers'
'Daily Cartoon: Tuesday, January 29th'
ok
pickup>
Look at ./repl.js to see what it can do. Not much, but enough for exploring exotic feeds.
Here’s the Standard Input example from before again.
const pickup = require('pickup')
process.stdin
.pipe(pickup())
.pipe(process.stdout)You can run this example from the command-line:
$ curl -sS $URL | node example/stdin.js | json -g
const http = require('http')
const https = require('https')
const pickup = require('../')
http.createServer((req, res) => {
https.get('https:/'.concat(req.url), (feed) => {
feed.pipe(pickup()).pipe(res)
})
}).listen(8080)To try the proxy server:
$ node example/proxy.js &
$ curl -sS http://localhost:8080/www.newyorker.com/feed/posts | json -ga title
This can either be a String(), null, or undefined.
The options Object is passed to the Transform stream constructor.
pickup uses following additional options:
-
eventModeBooleandefaults tofalse, iftruereadable state buffers are not filled and no'data', but'feed'and'entry'events are emitted. -
charsetstr()|'UTF-8'|'ISO-8859-1'An optional string to specify the encoding of input data. In the common use case you received this string in the headers of your HTTP response before you began parsing. If you, not so commonly, cannot provide the encoding upfront, pickup tries to detect the encoding, and eventually defaults to'UTF-8'. Thecharsetoption is corresponding to the optionalcharsetMIME type parameter found inContent-TypeHTTP headers. It's OK to pass any string, pickup will fall back on'UTF-8'when confused.
An undefined property, not populated by the parser, to identify feeds and entries in upstream systems, without prompting V8 to create new hidden classes.
authorstr()copyrightstr()idstr()imagestr()languagestr()linkstr()originalURLurl()paymentstr()subtitlestr()summarystr()titlestr()ttlstr()updatedstr()urlurl()
lengthstr()typestr()urlstr()
authorstr()durationstr()enclosureenclosure()orundefinedidstr()imagestr()linkstr()originalURLurl()subtitlestr()summarystr()titlestr()updatedstr()urlurl()
feed()Emitted when the meta information of the feed gets available.
entry()Emitted for each entry.
pickup(opts())pickup exports a function that returns a Transform stream which emits newline separated JSON strings, in objectMode the 'data' event contains entry() or feed() objects. As per XML's structure the last 'data' event usually contains the feed() object. In eventMode neither 'readable' nor 'data' events are emitted, instead 'feed' and 'entry' events are fired.
With npm, do:
$ npm install pickup
To use the CLI (as above):
$ npm install -g pickup
Please create an issue if you encounter a feed that pickup fails to parse.