Comparing version 0.3.3 to 0.3.4
@@ -5,3 +5,3 @@ --- | ||
title: "Reading data from a source" | ||
date: 2013-06-04T09:36:56.250Z | ||
date: 2013-07-17T08:03:53.224Z | ||
comments: false | ||
@@ -12,2 +12,3 @@ sharing: false | ||
github: https://github.com/wdavidw/node-csv | ||
source: ./src/from.coffee | ||
--- | ||
@@ -14,0 +15,0 @@ |
@@ -5,3 +5,3 @@ --- | ||
title: "Node CSV" | ||
date: 2013-06-04T09:36:56.251Z | ||
date: 2013-07-17T08:03:53.223Z | ||
comments: false | ||
@@ -12,2 +12,3 @@ sharing: false | ||
github: https://github.com/wdavidw/node-csv | ||
source: ./src/index.coffee | ||
--- | ||
@@ -47,9 +48,10 @@ | ||
// node samples/string.js | ||
var csv = require('csv'); | ||
csv() | ||
.from( '#Welcome\n"1","2","3","4"\n"a","b","c","d"' ) | ||
.to( function(data){ | ||
console.log data | ||
.from.string( | ||
'#Welcome\n"1","2","3","4"\n"a","b","c","d"', | ||
{comment: '#'} ) | ||
.to.array( function(data){ | ||
console.log(data) | ||
} ); | ||
// [ 'a', 'b', 'c', 'd' ] [ 1, 2, 3, 4 ] | ||
// [ [ '1', '2', '3', '4' ], [ 'a', 'b', 'c', 'd' ] ] | ||
@@ -63,6 +65,6 @@ | ||
The following example illustrates 4 usages of the library: | ||
1. Plug a readable stream by defining a file path | ||
1. Plug a readable stream from a file | ||
2. Direct output to a file path | ||
3. Transform each row (optional) | ||
4. Listen to events (optional) | ||
3. Transform each row | ||
4. Listen to events | ||
@@ -73,2 +75,3 @@ ```javascript | ||
var csv = require('csv'); | ||
var fs = require('fs'); | ||
csv() | ||
@@ -75,0 +78,0 @@ .from.stream(fs.createReadStream(__dirname+'/sample.in') |
@@ -5,3 +5,3 @@ --- | ||
title: "Parsing" | ||
date: 2013-06-04T09:36:56.251Z | ||
date: 2013-07-17T08:03:53.224Z | ||
comments: false | ||
@@ -12,2 +12,3 @@ sharing: false | ||
github: https://github.com/wdavidw/node-csv | ||
source: ./src/parser.coffee | ||
--- | ||
@@ -14,0 +15,0 @@ |
@@ -5,3 +5,3 @@ --- | ||
title: "Stringifier" | ||
date: 2013-06-04T09:36:56.252Z | ||
date: 2013-07-17T08:03:53.225Z | ||
comments: false | ||
@@ -12,2 +12,3 @@ sharing: false | ||
github: https://github.com/wdavidw/node-csv | ||
source: ./src/stringifier.coffee | ||
--- | ||
@@ -14,0 +15,0 @@ |
@@ -5,3 +5,3 @@ --- | ||
title: "Writing data to a destination" | ||
date: 2013-06-04T09:36:56.251Z | ||
date: 2013-07-17T08:03:53.224Z | ||
comments: false | ||
@@ -12,2 +12,3 @@ sharing: false | ||
github: https://github.com/wdavidw/node-csv | ||
source: ./src/to.coffee | ||
--- | ||
@@ -14,0 +15,0 @@ |
@@ -5,3 +5,3 @@ --- | ||
title: "Transforming data" | ||
date: 2013-06-04T09:36:56.251Z | ||
date: 2013-07-17T08:03:53.224Z | ||
comments: false | ||
@@ -12,2 +12,3 @@ sharing: false | ||
github: https://github.com/wdavidw/node-csv | ||
source: ./src/transformer.coffee | ||
--- | ||
@@ -14,0 +15,0 @@ |
// Generated by CoffeeScript 1.6.2 | ||
var convert_anchor, convert_code, date, docs, each, fs, getindent, mecano, unindent; | ||
var convert_anchor, convert_code, date, docs, each, fs, getindent, mecano, path, unindent; | ||
fs = require('fs'); | ||
path = require('path'); | ||
mecano = require('mecano'); | ||
@@ -99,3 +101,3 @@ | ||
content = convert_code(content); | ||
docs = "---\nlanguage: en\nlayout: page\ntitle: \"" + title + "\"\ndate: " + (date()) + "\ncomments: false\nsharing: false\nfooter: false\nnavigation: csv\ngithub: https://github.com/wdavidw/node-csv\n---\n" + content; | ||
docs = "---\nlanguage: en\nlayout: page\ntitle: \"" + title + "\"\ndate: " + (date()) + "\ncomments: false\nsharing: false\nfooter: false\nnavigation: csv\ngithub: https://github.com/wdavidw/node-csv\nsource: ./" + (path.relative(__dirname + '/../', source)) + "\n---\n" + content; | ||
while (match = re.exec(text)) { | ||
@@ -102,0 +104,0 @@ if (match[1]) { |
@@ -36,9 +36,10 @@ // Generated by CoffeeScript 1.6.2 | ||
// node samples/string.js | ||
var csv = require('csv'); | ||
csv() | ||
.from( '#Welcome\n"1","2","3","4"\n"a","b","c","d"' ) | ||
.to( function(data){ | ||
console.log data | ||
.from.string( | ||
'#Welcome\n"1","2","3","4"\n"a","b","c","d"', | ||
{comment: '#'} ) | ||
.to.array( function(data){ | ||
console.log(data) | ||
} ); | ||
// [ 'a', 'b', 'c', 'd' ] [ 1, 2, 3, 4 ] | ||
// [ [ '1', '2', '3', '4' ], [ 'a', 'b', 'c', 'd' ] ] | ||
@@ -50,9 +51,10 @@ | ||
The following example illustrates 4 usages of the library: | ||
1. Plug a readable stream by defining a file path | ||
1. Plug a readable stream from a file | ||
2. Direct output to a file path | ||
3. Transform each row (optional) | ||
4. Listen to events (optional) | ||
3. Transform each row | ||
4. Listen to events | ||
// node samples/sample.js | ||
var csv = require('csv'); | ||
var fs = require('fs'); | ||
csv() | ||
@@ -59,0 +61,0 @@ .from.stream(fs.createReadStream(__dirname+'/sample.in') |
@@ -96,3 +96,3 @@ // Generated by CoffeeScript 1.6.2 | ||
* `escape` Defaults to the escape read option. | ||
* `columns` List of fields, applied when `transform` returns an object, order matters, see the transform and the columns sections below. | ||
* `columns` List of fields, applied when `transform` returns an object, order matters, read the transformer documentation for additionnal information. | ||
* `header` Display the column names on the first line if the columns option is provided. | ||
@@ -257,2 +257,23 @@ * `lineBreaks` String used to delimit record rows or a special value; special values are 'auto', 'unix', 'mac', 'windows', 'unicode'; defaults to 'auto' (discovered in source or 'unix' if no source is specified). | ||
csv.on('record', function(record) { | ||
var column, i, _i, _j, _len, _len1, _record, _ref, _ref1; | ||
if (this.options.to.columns) { | ||
if (Array.isArray(record)) { | ||
_record = record; | ||
record = {}; | ||
_ref = this.options.to.columns; | ||
for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) { | ||
column = _ref[i]; | ||
record[column] = _record[i]; | ||
} | ||
} else { | ||
_record = record; | ||
record = {}; | ||
_ref1 = this.options.to.columns; | ||
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { | ||
column = _ref1[_j]; | ||
record[column] = _record[column]; | ||
} | ||
} | ||
} | ||
return records.push(record); | ||
@@ -259,0 +280,0 @@ }); |
{ | ||
"name": "csv", | ||
"version": "0.3.3", | ||
"version": "0.3.4", | ||
"description": "CSV parser with simple api, full of options and tested against large datasets.", | ||
"homepage": "http://www.adaltas.com/projects/node-csv/", | ||
"bugs": "https://github.com/wdavidw/node-csv/issues", | ||
"author": "David Worms <david@adaltas.com>", | ||
"author": "David Worms <david@adaltas.com> (hhttp://www.adaltas.com)", | ||
"contributors": [ | ||
"David Worms <david@adaltas.com>", | ||
"Will White <https://github.com/willwhite>", | ||
"Justin Latimer <https://github.com/justinlatimer>", | ||
"jonseymour <https://github.com/jonseymour>", | ||
"pascalopitz <https://github.com/pascalopitz>", | ||
"Josh Pschorr <https://github.com/jpschorr>", | ||
"Elad Ben-Israel <https://github.com/eladb>", | ||
"Philippe Plantier <https://github.com/phipla>", | ||
"Tim Oxley <https://github.com/timoxley>", | ||
"Damon Oehlman <https://github.com/DamonOehlman>", | ||
"Alexandru Topliceanu <https://github.com/topliceanu>", | ||
"Visup <https://github.com/visup>", | ||
"Edmund von der Burg <https://github.com/evdb>", | ||
"Douglas Christopher Wilson <https://github.com/dougwilson>" | ||
"David Worms <david@adaltas.com> (http://www.adaltas.com)", | ||
"Will White (https://github.com/willwhite)", | ||
"Justin Latimer (https://github.com/justinlatimer)", | ||
"jonseymour (https://github.com/jonseymour)", | ||
"pascalopitz (https://github.com/pascalopitz)", | ||
"Josh Pschorr (https://github.com/jpschorr)", | ||
"Elad Ben-Israel (https://github.com/eladb)", | ||
"Philippe Plantier (https://github.com/phipla)", | ||
"Tim Oxley (https://github.com/timoxley)", | ||
"Damon Oehlman (https://github.com/DamonOehlman)", | ||
"Alexandru Topliceanu (https://github.com/topliceanu)", | ||
"Visup (https://github.com/visup)", | ||
"Edmund von der Burg (https://github.com/evdb)", | ||
"Douglas Christopher Wilson (https://github.com/dougwilson)" | ||
], | ||
@@ -24,0 +24,0 @@ "engines": { |
@@ -14,6 +14,6 @@ [![Build Status](https://secure.travis-ci.org/wdavidw/node-csv-parser.png)](http://travis-ci.org/wdavidw/node-csv-parser) | ||
This project provides CSV parsing and has been tested and used | ||
on large input files. It provide every option you could expect from an | ||
on large input files. It provides every option you would expect from an | ||
advanced CSV parser and stringifier. | ||
[Documentation for the CSV parser is available here](http://www.adaltas.com/projects/node-csv/). | ||
[The full documentation of the CSV parser is available here](http://www.adaltas.com/projects/node-csv/). | ||
@@ -29,9 +29,10 @@ Usage | ||
// 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 | ||
.from.string( | ||
'#Welcome\n"1","2","3","4"\n"a","b","c","d"', | ||
{comment: '#'} ) | ||
.to.array( function(data){ | ||
console.log(data) | ||
} ); | ||
// [ [ '1', '2', '3', '4' ], [ 'a', 'b', 'c', 'd' ] ] | ||
``` | ||
@@ -43,7 +44,12 @@ | ||
// node samples/sample.js | ||
var fs = require('fs'); | ||
var csv = require('csv'); | ||
// opts is optional | ||
var opts = ; | ||
csv() | ||
.from.stream(fs.createReadStream(__dirname+'/sample.in')) | ||
.to.path(__dirname+'/sample.out') | ||
.from.path(__dirname+'/sample.in', { delimiter: ',', escape: '"' }) | ||
.to.stream(fs.createReadStream(__dirname+'/sample.out')) | ||
.transform( function(row){ | ||
@@ -50,0 +56,0 @@ row.unshift(row.pop()); |
var csv = require('..'); | ||
// node samples/string.js | ||
csv() | ||
.from( '"1","2","3","4"\n"a","b","c","d"' ) | ||
.to( console.log ) | ||
/* | ||
`node samples/string.js` | ||
1,2,3,4 | ||
a,b,c,d | ||
*/ | ||
.from.string( | ||
'#Welcome\n"1","2","3","4"\n"a","b","c","d"', | ||
{comment: '#'} ) | ||
.to.array( function(data){ | ||
console.log(data) | ||
} ); | ||
// [ [ '1', '2', '3', '4' ], [ 'a', 'b', 'c', 'd' ] ] |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
368243
83
1645
131