Skip to content

Commit

Permalink
Improve readme sample and add sample code
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Sep 25, 2010
1 parent f619112 commit 23bd430
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,4 +1,5 @@
.*
*.tmp
lib-cov
sample/sample.out
!.gitignore
31 changes: 25 additions & 6 deletions readme.md
Expand Up @@ -20,23 +20,42 @@ This project provide CSV parsing and has been tested and used on large source fi
Quick exemple
-------------

Using the library is a 3 steps process where all steps are optional:
Using the library is a 4 steps process:

1. Create a source
2. Create a destination
3. Transform the data
2. Create a destination (optional)
3. Transform the data (optional)
4. Listen to events (optional)

<pre class="javascript">
var csv = require('csv-parser');
var csv = require('csv');
csv()
.fromPath('/tmp/csv.in');
.toPath('/tmp/csv.out');
.fromPath(__dirname+'/sample.in')
.toPath(__dirname+'/sample.out')
.transform(function(data){
data.unshift(data.pop());
return data;
})
.on('data',function(data,index){
console.log('#'+index+' '+JSON.stringify(data));
})
.on('end',function(count){
console.log('Number of lines '+count);
})
.on('error',function(error){
console.log(error.message);
});
</pre>

Installing
----------

Manually
Simply copy or link the lib/csv.js file into your $HOME/.node_libraries folder or inside declared path folder.

NPM
Simply install the project with `npm install node-csv` and you'll be ready to go.

Creating a source
-----------------

Expand Down
2 changes: 2 additions & 0 deletions sample/sample.in
@@ -0,0 +1,2 @@
20322051544,1979.0,8.8017226E7,ABC,45,2000-01-01
28392898392,1974.0,8.8392926E7,DEF,23,2050-11-27
23 changes: 23 additions & 0 deletions sample/sample.js
@@ -0,0 +1,23 @@

// CSV sample - Copyright David Worms <open@adaltas.com> (MIT Licensed)
//
// node sample/sample.js
//

var csv = require('csv');
csv()
.fromPath(__dirname+'/sample.in')
.toPath(__dirname+'/sample.out')
.transform(function(data){
data.unshift(data.pop());
return data;
})
.on('data',function(data,index){
console.log('#'+index+' '+JSON.stringify(data));
})
.on('end',function(count){
console.log('Number of lines '+count);
})
.on('error',function(error){
console.log(error.message);
});
2 changes: 1 addition & 1 deletion test/fromto.js
Expand Up @@ -34,7 +34,7 @@ module.exports = {
assert.strictEqual(2,count);
});
},
'Test string with destination stream': function(assert){
'Test string to stream': function(assert){
csv()
.from(fs.readFileSync(__dirname+'/fromto/string_to_stream.in').toString())
.toPath(__dirname+'/fromto/string_to_stream.tmp')
Expand Down

0 comments on commit 23bd430

Please sign in to comment.