Skip to content
Browse files

Improve readme sample and add sample code

  • Loading branch information...
1 parent f619112 commit 23bd430d0e400d078199720a78d1b00fd7f207fd @wdavidw committed
Showing with 52 additions and 7 deletions.
  1. +1 −0 .gitignore
  2. +25 −6 readme.md
  3. +2 −0 sample/sample.in
  4. +23 −0 sample/sample.js
  5. +1 −1 test/fromto.js
View
1 .gitignore
@@ -1,4 +1,5 @@
.*
*.tmp
lib-cov
+sample/sample.out
!.gitignore
View
31 readme.md
@@ -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
-----------------
View
2 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
View
23 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);
+ });
View
2 test/fromto.js
@@ -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')

0 comments on commit 23bd430

Please sign in to comment.
Something went wrong with that request. Please try again.