Skip to content

Commit a3e4f91

Browse files
committed
Create test; see how it and csv2json.js works with a .csv file
1 parent a93c202 commit a3e4f91

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

csv2json.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ module.exports = function(file) {
44

55
if (path.extname(file) != '.csv') {
66
console.log("Invalid file. Files with extension .csv only.")
7+
} else {
8+
fs.readFile(file, function(err, data) {
9+
if (err) throw err;
10+
11+
console.log(data.toString('utf8'));
12+
});
713
}
8-
fs.readFile(file, function(err, data) {
9-
10-
});
1114
}

test/sample.csv

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
0 Hello
2+
1 World
3+
2 This
4+
3 Is
5+
4 CSV
6+
5 To
7+
6 JSON

test/test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
var csv2json = require('../csv2json');
2+
3+
csv2json('test/sample.csv');

0 commit comments

Comments
 (0)