Changeset 489 for Dev/trunk/src/node_modules/ya-csv
- Timestamp:
- 03/08/14 11:41:10 (11 years ago)
- Location:
- Dev/trunk/src/node_modules/ya-csv
- Files:
-
- 3 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
Dev/trunk/src/node_modules/ya-csv/README.md
r484 r489 17 17 npm install ya-csv 18 18 19 Current version requires at least Node.js v0.2.3 and it's tested with Node.js v0.4.12, 0.6.11 and 0.7.5. Hope it works with the other versions in between too.19 Current version requires at least Node.js v0.2.3 and it's tested with Node.js v0.4.12, 0.6.11, 0.7.5 and v0.10.24. Hope it works with the other versions in between too. 20 20 21 21 ## Features -
Dev/trunk/src/node_modules/ya-csv/bin/reshuffle.js
r484 r489 1 1 var csv = require('../lib/ya-csv'), 2 sys = require('sys');2 util = require('util'); 3 3 4 4 var reader = csv.createCsvStreamReader(process.openStdin(), { columnsFromHeader: true }); … … 6 6 7 7 if (process.argv.length < 3) { 8 sys.error("Usage: " + process.argv[0] + " " + process.argv[1] + " <output columns>");8 util.error("Usage: " + process.argv[0] + " " + process.argv[1] + " <output columns>"); 9 9 process.exit(1); 10 10 } -
Dev/trunk/src/node_modules/ya-csv/lib/ya-csv.js
r484 r489 73 73 * @return {ReadStream} the readstream instance 74 74 */ 75 self.dest oy = function(){75 self.destroy = function(){ 76 76 readStream.destroy(); 77 77 return self; … … 113 113 var isEscape = false; 114 114 if (c === this.escapechar) { 115 var nextChar = data.charAt(i + 1); 116 if (this._isEscapable(nextChar)) { 117 this._addCharacter(nextChar); 118 i++; 119 isEscape = true; 115 // double-quote at the field beginning does not count as an escape string` 116 if (c !== this.quotechar || ps.openField || ps.quotedField) { 117 var nextChar = data.charAt(i + 1); 118 if (this._isEscapable(nextChar)) { 119 this._addCharacter(nextChar); 120 i++; 121 isEscape = true; 122 } 120 123 } 121 124 } … … 217 220 var ps = this.parsingStatus; 218 221 if (this.columnsFromHeader && ps.rows === 0) { 219 this.setColumnNames(ps.openRecord); 222 // user has passed columnNames through option 223 if (this.columnNames.length === 0) 224 this.setColumnNames(ps.openRecord); 220 225 } else if (this.columnNames != null && this.columnNames.length > 0) { 221 226 var objResult = {}; … … 327 332 function _setOptions(obj, options) { 328 333 options = options || {}; 329 obj.separator = options.separator ||',';330 obj.quotechar = options.quote ||'"';331 obj.escapechar = options.escape ||'"';332 obj.commentchar = options.comment ||'';333 obj.columnNames = options.columnNames ||[];334 obj.columnsFromHeader = options.columnsFromHeader ||false;335 obj.nestedQuotes = options.nestedQuotes ||false;336 }; 334 obj.separator = (typeof options.separator !== 'undefined') ? options.separator : ','; 335 obj.quotechar = (typeof options.quote !== 'undefined') ? options.quote : '"'; 336 obj.escapechar = (typeof options.escape !== 'undefined') ? options.escape : '"'; 337 obj.commentchar = (typeof options.comment !== 'undefined') ? options.comment : ''; 338 obj.columnNames = (typeof options.columnNames !== 'undefined') ? options.columnNames : []; 339 obj.columnsFromHeader = (typeof options.columnsFromHeader !== 'undefined') ? options.columnsFromHeader : false; 340 obj.nestedQuotes = (typeof options.nestedQuotes !== 'undefined') ? options.nestedQuotes : false; 341 }; -
Dev/trunk/src/node_modules/ya-csv/package.json
r484 r489 2 2 "name": "ya-csv", 3 3 "description": "CSV parser and generator for Node.js", 4 "version": "0.9. 2",4 "version": "0.9.3", 5 5 "keywords": [ 6 6 "node", … … 37 37 }, 38 38 "main": "lib/ya-csv", 39 "readme": "# ya-csv\n\nEvent based CSV parser and writer for Node.js suitable for processing large CSV streams.\n\n // A simple echo program:\n var csv = require('ya-csv');\n\n var reader = csv.createCsvStreamReader(process.openStdin());\n var writer = csv.createCsvStreamWriter(process.stdout);\n\n reader.addListener('data', function(data) {\n writer.writeRecord(data);\n });\n\n## Installation\n\n npm install ya-csv\n\nCurrent version requires at least Node.js v0.2.3 and it's tested with Node.js v0.4.12, 0.6.11 and 0.7.5. Hope it works with the other versions in between too.\n\n## Features\n\n - event based, suitable for processing big CSV streams\n - configurable separator, quote and escape characters (comma, double-quote and double-quote by default)\n - ignores lines starting with configurable comment character (off by default)\n - supports memory-only streaming\n\n## More examples\n\nEcho first column of the `data.csv` file:\n\n // equivalent of csv.createCsvFileReader('data.csv') \n var reader = csv.createCsvFileReader('data.csv', {\n 'separator': ',',\n 'quote': '\"',\n 'escape': '\"', \n 'comment': '',\n });\n var writer = new csv.CsvWriter(process.stdout);\n reader.addListener('data', function(data) {\n writer.writeRecord([ data[0] ]);\n });\n\nReturn data in objects rather than arrays: either by grabbing the column names form the header row (first row is not passed to the `data` listener):\n\n var reader = csv.createCsvFileReader('data.csv', { columnsFromHeader: true });\n reader.addListener('data', function(data) {\n // supposing there are so named columns in the source file\n sys.puts(data.col1 + \" ... \" + data.col2);\n });\n\n... or by providing column names from the client code (first row is passed to the `data` listener in this case):\n\n var reader = csv.createCsvFileReader('data.csv');\n reader.setColumnNames([ 'col1', 'col2' ]);\n reader.addListener('data', function(data) {\n sys.puts(data.col1 + \" ... \" + data.col2);\n });\n\nNote `reader.setColumnNames()` resets the column names so next invocation of the `data` listener will again receive the data in an array rather than an object.\n\nConvert the `/etc/passwd` file to comma separated format, drop commented lines and dump the results to the standard output:\n\n var reader = csv.createCsvFileReader('/etc/passwd', {\n 'separator': ':',\n 'quote': '\"',\n 'escape': '\"',\n 'comment': '#',\n });\n var writer = new csv.CsvWriter(process.stdout);\n reader.addListener('data', function(data) {\n writer.writeRecord(data);\n });\n\nParsing an upload as the data comes in, using node-formidable:\n\n upload_form.onPart = function(part) {\n if (!part.filename) { upload_form.handlePart(part); return }\n\n var reader = csv.createCsvFileReader({'comment': '#'});\n reader.addListener('data', function(data) {\n saveRecord(data);\n });\n\n part.on('data', function(buffer) {\n // Pipe incoming data into the reader.\n reader.parse(buffer);\n });\n part.on('end', function() {\n reader.end()\n }\n }\n",39 "readme": "# ya-csv\n\nEvent based CSV parser and writer for Node.js suitable for processing large CSV streams.\n\n // A simple echo program:\n var csv = require('ya-csv');\n\n var reader = csv.createCsvStreamReader(process.openStdin());\n var writer = csv.createCsvStreamWriter(process.stdout);\n\n reader.addListener('data', function(data) {\n writer.writeRecord(data);\n });\n\n## Installation\n\n npm install ya-csv\n\nCurrent version requires at least Node.js v0.2.3 and it's tested with Node.js v0.4.12, 0.6.11, 0.7.5 and v0.10.24. Hope it works with the other versions in between too.\n\n## Features\n\n - event based, suitable for processing big CSV streams\n - configurable separator, quote and escape characters (comma, double-quote and double-quote by default)\n - ignores lines starting with configurable comment character (off by default)\n - supports memory-only streaming\n\n## More examples\n\nEcho first column of the `data.csv` file:\n\n // equivalent of csv.createCsvFileReader('data.csv') \n var reader = csv.createCsvFileReader('data.csv', {\n 'separator': ',',\n 'quote': '\"',\n 'escape': '\"', \n 'comment': '',\n });\n var writer = new csv.CsvWriter(process.stdout);\n reader.addListener('data', function(data) {\n writer.writeRecord([ data[0] ]);\n });\n\nReturn data in objects rather than arrays: either by grabbing the column names form the header row (first row is not passed to the `data` listener):\n\n var reader = csv.createCsvFileReader('data.csv', { columnsFromHeader: true });\n reader.addListener('data', function(data) {\n // supposing there are so named columns in the source file\n sys.puts(data.col1 + \" ... \" + data.col2);\n });\n\n... or by providing column names from the client code (first row is passed to the `data` listener in this case):\n\n var reader = csv.createCsvFileReader('data.csv');\n reader.setColumnNames([ 'col1', 'col2' ]);\n reader.addListener('data', function(data) {\n sys.puts(data.col1 + \" ... \" + data.col2);\n });\n\nNote `reader.setColumnNames()` resets the column names so next invocation of the `data` listener will again receive the data in an array rather than an object.\n\nConvert the `/etc/passwd` file to comma separated format, drop commented lines and dump the results to the standard output:\n\n var reader = csv.createCsvFileReader('/etc/passwd', {\n 'separator': ':',\n 'quote': '\"',\n 'escape': '\"',\n 'comment': '#',\n });\n var writer = new csv.CsvWriter(process.stdout);\n reader.addListener('data', function(data) {\n writer.writeRecord(data);\n });\n\nParsing an upload as the data comes in, using node-formidable:\n\n upload_form.onPart = function(part) {\n if (!part.filename) { upload_form.handlePart(part); return }\n\n var reader = csv.createCsvFileReader({'comment': '#'});\n reader.addListener('data', function(data) {\n saveRecord(data);\n });\n\n part.on('data', function(buffer) {\n // Pipe incoming data into the reader.\n reader.parse(buffer);\n });\n part.on('end', function() {\n reader.end()\n }\n }\n", 40 40 "readmeFilename": "README.md", 41 "_id": "ya-csv@0.9.2", 41 "homepage": "https://github.com/koles/ya-csv", 42 "_id": "ya-csv@0.9.3", 42 43 "dist": { 43 "shasum": " 088ddf523ca066bbe654146100cf70030d9f6779"44 "shasum": "e3b1e84b699c569949b8b68a319a1b065ac456b3" 44 45 }, 45 "_from": "ya-csv@ ",46 "_resolved": "https://registry.npmjs.org/ya-csv/-/ya-csv-0.9. 2.tgz"46 "_from": "ya-csv@0.9.3", 47 "_resolved": "https://registry.npmjs.org/ya-csv/-/ya-csv-0.9.3.tgz" 47 48 } -
Dev/trunk/src/node_modules/ya-csv/test/echo.js
r484 r489 1 1 var csv = require('../lib/ya-csv'), 2 sys = require('sys');2 util = require('util'); 3 3 4 sys.debug('start');4 util.debug('start'); 5 5 6 6 if (process.argv.length < 3) { 7 sys.error("Usage: node " + process.argv[1] + " <csv file>");7 util.error("Usage: node " + process.argv[1] + " <csv file>"); 8 8 process.exit(1); 9 9 } … … 24 24 25 25 csvIn.addListener('end', function() { 26 sys.debug('end');27 sys.debug(columns + ' columns, ' + lines + ' lines');26 util.debug('end'); 27 util.debug(columns + ' columns, ' + lines + ' lines'); 28 28 }); 29 29 -
Dev/trunk/src/node_modules/ya-csv/test/index.js
r484 r489 1 var sys;1 var util; 2 2 try { 3 sys= require('util');3 util = require('util'); 4 4 } catch (e) { 5 sys= require('sys');5 util = require('sys'); 6 6 } 7 7 … … 27 27 csvIn.addListener('end', function() { 28 28 assert.strictEqual(expectedRows, lines, "Wrong number of records"); 29 sys.debug(columns + ' columns, ' + lines + ' lines');29 util.debug(columns + ' columns, ' + lines + ' lines'); 30 30 }); 31 31 -
Dev/trunk/src/node_modules/ya-csv/test/stream.js
r484 r489 1 1 var csv = require('../lib/ya-csv'), 2 sys = require('sys'),2 util = require('util'), 3 3 fs = require('fs'); 4 4 5 sys.debug('start');5 util.debug('start'); 6 6 7 7 if (process.argv.length < 3) { 8 sys.error("Usage: node " + process.argv[1] + " <csv file>");8 util.error("Usage: node " + process.argv[1] + " <csv file>"); 9 9 process.exit(1); 10 10 } … … 20 20 21 21 csvIn.addListener('end', function() { 22 sys.debug('end');23 sys.debug(columns + ' columns, ' + lines + ' lines');22 util.debug('end'); 23 util.debug(columns + ' columns, ' + lines + ' lines'); 24 24 }); 25 25 26 26 csvIn.addListener('error', function(e) { 27 sys.debug('error');28 sys.debug(e);27 util.debug('error'); 28 util.debug(e); 29 29 }); 30 30 … … 38 38 fileIn.setEncoding('utf8'); 39 39 fileIn.on('data', function(data) { 40 sys.debug(data);40 util.debug(data); 41 41 csvIn.parse(data); 42 42 });
Note: See TracChangeset
for help on using the changeset viewer.