Skip to content

Commit

Permalink
Improve md formatting in readme
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Aug 15, 2012
1 parent 9064539 commit 096b1d3
Showing 1 changed file with 76 additions and 64 deletions.
140 changes: 76 additions & 64 deletions readme.md
@@ -1,16 +1,16 @@
<pre> <pre>
_ _ _ _____ _______ __ _____ _ _ _ _____ _______ __
| \ | | | | / ____|/ ____\ \ / /| __ \ | \ | | | | / ____|/ ____\ \ / /
| \| | ___ __| | ___ | | | (___ \ \ / / | |__) |_ _ _ __ ___ ___ _ __ | \| | ___ __| | ___ | | | (___ \ \ / /
| . ` |/ _ \ / _` |/ _ \| | \___ \ \ \/ / | ___/ _` | '__/ __|/ _ \ '__| | . ` |/ _ \ / _` |/ _ \| | \___ \ \ \/ /
| |\ | (_) | (_| | __/| |____ ____) | \ / | | | (_| | | \__ \ __/ | | |\ | (_) | (_| | __/| |____ ____) | \ /
|_| \_|\___/ \__,_|\___| \_____|_____/ \/ |_| \__,_|_| |___/\___|_| |_| \_|\___/ \__,_|\___| \_____|_____/ \/ New BSD License


</pre> </pre>


This project provides CSV parsing and has been tested and used on a large source file (over 2Gb). This project provides CSV parsing and has been tested and used on a large source file (over 2Gb).


- Support delimiter, quote and escape characters - Support delimiters, quotes and escape characters
- Line breaks discovery: line breaks in source are detected and reported to destination - Line breaks discovery: line breaks in source are detected and reported to destination
- Data transformation - Data transformation
- Async and event based - Async and event based
Expand All @@ -29,43 +29,49 @@ Using the library is a 4 steps process:


Here is a example: Here is a example:


// node samples/sample.js ```javascript
var csv = require('csv'); // node samples/sample.js

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

});
// Print sth like:
// #0 ["2000-01-01","20322051544","1979.0","8.8017226E7","ABC","45"] // Print sth like:
// #1 ["2050-11-27","28392898392","1974.0","8.8392926E7","DEF","23"] // #0 ["2000-01-01","20322051544","1979.0","8.8017226E7","ABC","45"]
// Number of lines: 2 // #1 ["2050-11-27","28392898392","1974.0","8.8392926E7","DEF","23"]
// Number of lines: 2
```


Installing Installing
---------- ----------


Via git (or downloaded tarball): Via git (or downloaded tarball):


$ git clone http://github.com/wdavidw/node-csv-parser.git ```bash
git clone http://github.com/wdavidw/node-csv-parser.git
```


Then, simply copy or link the ./lib/csv.js file into your $HOME/.node_libraries folder or inside a declared path folder. Then, simply copy or link the ./lib/csv.js file into your $HOME/.node_libraries folder or inside a declared path folder.


Via [npm](http://github.com/isaacs/npm): Via [npm](http://github.com/isaacs/npm):


$ npm install csv ```bash
npm install csv
```


Reading API Reading API
----------- -----------
Expand Down Expand Up @@ -177,18 +183,20 @@ When the returned value is an array, the fields are merged in order. When the re


Example of transform returning a string Example of transform returning a string


// node samples/transform.js ```javascript
var csv = require('csv'); // node samples/transform.js

var csv = require('csv');
csv()
.fromPath(__dirname+'/transform.in') csv()
.toStream(process.stdout) .fromPath(__dirname+'/transform.in')
.transform(function(data,index){ .toStream(process.stdout)
return (index>0 ? ',' : '') + data[0] + ":" + data[2] + ' ' + data[1]; .transform(function(data,index){
}); return (index>0 ? ',' : '') + data[0] + ":" + data[2] + ' ' + data[1];

});
// Print sth like:
// 82:Zbigniew Preisner,94:Serge Gainsbourg // Print sth like:
// 82:Zbigniew Preisner,94:Serge Gainsbourg
```


Events Events
------ ------
Expand Down Expand Up @@ -216,32 +224,36 @@ You can define a different order and even different columns in the read options


When working with fields, the `transform` method and the `data` events receive their `data` parameter as an object instead of an array where the keys are the field names. When working with fields, the `transform` method and the `data` events receive their `data` parameter as an object instead of an array where the keys are the field names.


// node samples/column.js ```javascript
var csv = require('csv'); // node samples/column.js

var csv = require('csv');
csv()
.fromPath(__dirname+'/columns.in',{ csv()
columns: true .fromPath(__dirname+'/columns.in',{
}) columns: true
.toStream(process.stdout,{ })
columns: ['id', 'name'] .toStream(process.stdout,{
}) columns: ['id', 'name']
.transform(function(data){ })
data.name = data.firstname + ' ' + data.lastname .transform(function(data){
return data; data.name = data.firstname + ' ' + data.lastname
}); return data;

});
// Print sth like:
// 82,Zbigniew Preisner // Print sth like:
// 94,Serge Gainsbourg // 82,Zbigniew Preisner
// 94,Serge Gainsbourg
```


Running the tests Running the tests
----------------- -----------------


Tests are executed with expresso. To install it, simple use `npm install -g expresso`. Tests are executed with expresso. To install it, simple use `npm install -g expresso`.


To run the tests To run the tests
expresso test ```bash
expresso test
```


Contributors Contributors
------------ ------------
Expand Down

0 comments on commit 096b1d3

Please sign in to comment.