Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

still struggling on finding a good way to test :-)

  • Loading branch information...
commit 745c1b3d9af7ac079069f0a8f800e316d0857c9d 1 parent 4ceff9b
@twilson63 authored
View
6 index.js
@@ -30,13 +30,13 @@ exports.parseRow = parseRow = function(columns, sep) {
module.exports = csv2json = function(columns, row, col) {
if (row == null) {
- row = ',';
+ row = '\n';
}
if (col == null) {
- col = '\n';
+ col = ',';
}
if (columns == null) {
throw new Error('columns must be defined.');
}
- return es.pipe(es.split(col), parseRow(columns, row), es.join(','));
+ return es.pipe(es.split(row), parseRow(columns, col), es.join(','));
};
View
4 package.json
@@ -2,9 +2,9 @@
"author": "Tom Wilson <tom@jackhq.com>",
"name": "csv2json",
"description": "Stream CSV to JSON",
- "version": "0.0.2",
+ "version": "0.0.4",
"dependencies": {
- "event-stream": "~1.3.0"
+ "event-stream": "*"
},
"devDependencies": {
"coffee-script": "1.3.3"
View
6 src/index.coffee
@@ -17,11 +17,11 @@ exports.parseRow = parseRow = (columns, sep=',') ->
# main stream to receive a set of csv data and
# produce an comma delimited list of json.
-module.exports = csv2json = (columns, row=',', col='\n') ->
+module.exports = csv2json = (columns, row='\n', col=',') ->
unless columns?
throw new Error('columns must be defined.')
es.pipe(
- es.split(col)
- parseRow(columns, row)
+ es.split(row)
+ parseRow(columns, col)
es.join(',')
)
View
4 test/data/sample.csv
@@ -1,4 +1,2 @@
"foo", "bar", "baz"
-"foo1", "bar1", "baz1"
-"foo2", "bar2", "baz2"
-"foo3", "bar3", "baz3"
+"foo1", "bar1", "baz1"
View
1  test/data/sample.json
@@ -0,0 +1 @@
+{"col1":"foo","col2":"bar","col3":"baz"},{"col1":"foo1","col2":"bar1","col3":"baz1"}
View
3  test/data/sample2.csv
@@ -0,0 +1,3 @@
+"foo1", "bar1", "baz1"
+"foo2", "bar2", "baz2"
+"foo3", "bar3", "baz3"
View
21 test/index.coffee
@@ -1,7 +1,20 @@
path = require 'path'
csv2json = require path.join(__dirname,'..')
fs = require 'fs'
-#describe 'basic convert', ->
-# it 'should be successful', (done) ->
-stream = fs.FileReadStream(path.join(__dirname,'data','sample.csv'))
-stream.pipe(csv2json(["foo","bar","baz"]).pipe(process.stdout))
+es = require 'event-stream'
+assert = require 'assert'
+
+describe 'basic convert', ->
+ it 'should be successful', (done) ->
+ es.pipeline(
+ fs.FileReadStream(path.join(__dirname,'data','sample.csv'))
+ csv2json(["col1","col2","col3"])
+ fs.FileWriteStream(path.join(__dirname,'data','sample.json'))
+ es.writeArray (err, array) ->
+ console.dir(array)
+ done()
+ )
+
+
+ #stream = fs.FileReadStream(path.join(__dirname,'data','sample.csv'))
+ #stream.pipe(csv2json(["col1","col2","col3"])).pipe(process.stdout)
View
1  test/mocha.opts
@@ -0,0 +1 @@
+--compilers coffee:coffee-script
Please sign in to comment.
Something went wrong with that request. Please try again.