Skip to content

Commit

Permalink
Add CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelnisi committed Apr 15, 2013
1 parent 934b988 commit 059a9eb
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 20 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
npm-debug.log
27 changes: 16 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,29 @@ The pickup [Node.js](http://nodejs.org/) module is a [Transform](http://nodejs.o

## Usage

Install [jsontool](https://github.com/trentm/json) to format JSON in the command-line:
To transform from stdin to stdout:

var pickup = require('pickup')
, transformer = pickup()
, Readable = require('stream').Readable
, reader = new Readable().wrap(process.openStdin())
, writer = process.stdout

reader.pipe(transformer).pipe(writer)

If you haven't already, I suggest you intall [jsontool](https://github.com/trentm/json), a `json` command for working with JSON on the command-line:

npm install -g jsontool

Clone pickup to run examples:

git clone git://github.com/michaelnisi/pickup.git
cd pickup

Pipe stdin to stdout:

cat test/itunes.xml | node example/stdin.js | json

Now you can transform RSS to JSON on the command-line like so:

curl -sS http://feeds.feedburner.com/the_talk_show | pickup | json

## Installation

Install with [npm](https://npmjs.org):

npm install pickup
npm install -g pickup

## License

Expand Down
11 changes: 11 additions & 0 deletions bin/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env node

;(function () {
var pickup = require('../')
, transformer = pickup()
, Readable = require('stream').Readable
, reader = new Readable().wrap(process.openStdin())
, writer = process.stdout

reader.pipe(transformer).pipe(writer)
})()
7 changes: 3 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

// pickup - transform RSS or Atom feed to JSON
// pickup - transform RSS or Atom XML to JSON

var sax = require('sax')
, Transform = require('stream').Transform
, maps = require('./lib/maps')()
, mappings = require('./lib/mappings')()
, CHANNEL = 'channel'
, ITEM = 'item'
, FEED = 'feed'
Expand Down Expand Up @@ -56,7 +56,7 @@ module.exports = function () {
name = node.name

if (isElement(name)) {
map = maps[name]
map = mappings[name]
}

switch (name) {
Expand Down Expand Up @@ -115,7 +115,6 @@ module.exports = function () {
name = null
}


return stream
}

6 changes: 3 additions & 3 deletions lib/maps.js → lib/mappings.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

// maps - map elements
// mappings - map elements to property names

module.exports = function () {
var channel = {
Expand Down Expand Up @@ -60,12 +60,12 @@ module.exports = function () {
, 'email':'email'
}

var maps = {
var mappings = {
channel:channel
, item:item
, feed:feed
, entry:entry
}

return maps
return mappings
}
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
{
"name": "pickup",
"version": "0.1.2",
"description": "transform RSS or ATOM XMLto JSON",
"version": "0.1.3",
"description": "transform RSS or ATOM XML to JSON",
"main": "index.js",
"directories": {
"lib": "lib",
"example": "example",
"test": "test"
},
"scripts": {
"test": "tap test/*.js"
},
"bin": {
"pickup": "bin/cli.js"
},
"repository": {
"type": "git",
"url": "git://github.com/michaelnisi/pickup.git"
Expand Down

0 comments on commit 059a9eb

Please sign in to comment.