Skip to content

Commit

Permalink
Add a quick example
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Oct 9, 2012
1 parent d9642b3 commit edf0d1a
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/csv.coffee
Expand Up @@ -23,15 +23,26 @@ available [here](https://github.com/wdavidw/node-csv-parser/tree/v0.1).
Quick example
-------------
The following example illustrate 4 usages of the library:
// node samples/string.js
var csv = require('csv');
csv()
.from( '"1","2","3","4"\n"a","b","c","d"' )
.to( console.log )
// Output:
// 1,2,3,4
// a,b,c,d
Advanced example
----------------
The following example illustrates 4 usages of the library:
1. Plug a readable stream by defining a file path
2. Direct output to a file path
3. Transform the data (optional)
4. Listen to events (optional)
// node samples/sample.js
var csv = require('csv');
csv()
.from.stream(fs.createReadStream(__dirname+'/sample.in')
.to.path(__dirname+'/sample.out')
Expand All @@ -48,8 +59,7 @@ The following example illustrate 4 usages of the library:
.on('error', function(error){
console.log(error.message);
});
// Print sth like:
// Output:
// #0 ["2000-01-01","20322051544","1979.0","8.8017226E7","ABC","45"]
// #1 ["2050-11-27","28392898392","1974.0","8.8392926E7","DEF","23"]
// Number of lines: 2
Expand Down

0 comments on commit edf0d1a

Please sign in to comment.