From 3af8897003340528699b1502bf006e011f3be7ae Mon Sep 17 00:00:00 2001 From: David Worms Date: Wed, 10 Oct 2012 01:26:04 +0900 Subject: [PATCH] Add quick example --- doc/from.md | 2 +- doc/index.md | 24 +++++++++++++++++++----- doc/stringifier.md | 2 +- doc/to.md | 2 +- doc/transformer.md | 2 +- lib/csv.js | 18 ++++++++++++++---- 6 files changed, 37 insertions(+), 13 deletions(-) diff --git a/doc/from.md b/doc/from.md index ab6586153..09e0870fe 100644 --- a/doc/from.md +++ b/doc/from.md @@ -2,7 +2,7 @@ language: en layout: page title: "Reading data from a source" -date: 2012-10-09T16:08:40.532Z +date: 2012-10-09T16:24:28.046Z comments: false sharing: false footer: false diff --git a/doc/index.md b/doc/index.md index 874938ad8..cf59b519b 100644 --- a/doc/index.md +++ b/doc/index.md @@ -2,7 +2,7 @@ language: en layout: page title: "Node CSV" -date: 2012-10-09T16:08:40.531Z +date: 2012-10-09T16:24:28.045Z comments: false sharing: false footer: false @@ -30,7 +30,23 @@ available [here](https://github.com/wdavidw/node-csv-parser/tree/v0.1). Quick example ------------- -The following example illustrate 4 usages of the library: +```javascript + +// 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) @@ -40,7 +56,6 @@ The following example illustrate 4 usages of the library: // node samples/sample.js var csv = require('csv'); - csv() .from.stream(fs.createReadStream(__dirname+'/sample.in') .to.path(__dirname+'/sample.out') @@ -57,8 +72,7 @@ csv() .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 diff --git a/doc/stringifier.md b/doc/stringifier.md index 977a96540..e862c3d60 100644 --- a/doc/stringifier.md +++ b/doc/stringifier.md @@ -2,7 +2,7 @@ language: en layout: page title: "Stringifier" -date: 2012-10-09T16:08:40.532Z +date: 2012-10-09T16:24:28.047Z comments: false sharing: false footer: false diff --git a/doc/to.md b/doc/to.md index 5c45bece5..9dc067032 100644 --- a/doc/to.md +++ b/doc/to.md @@ -2,7 +2,7 @@ language: en layout: page title: "Writing data to a destination" -date: 2012-10-09T16:08:40.532Z +date: 2012-10-09T16:24:28.046Z comments: false sharing: false footer: false diff --git a/doc/transformer.md b/doc/transformer.md index 5bf97237a..af4ea2b0e 100644 --- a/doc/transformer.md +++ b/doc/transformer.md @@ -2,7 +2,7 @@ language: en layout: page title: "Transforming data" -date: 2012-10-09T16:08:40.532Z +date: 2012-10-09T16:24:28.047Z comments: false sharing: false footer: false diff --git a/lib/csv.js b/lib/csv.js index ef14ac669..290cb7c61 100644 --- a/lib/csv.js +++ b/lib/csv.js @@ -23,7 +23,19 @@ 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) @@ -31,7 +43,6 @@ The following example illustrate 4 usages of the library: // node samples/sample.js var csv = require('csv'); - csv() .from.stream(fs.createReadStream(__dirname+'/sample.in') .to.path(__dirname+'/sample.out') @@ -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