Skip to content

Commit

Permalink
step1
Browse files Browse the repository at this point in the history
  • Loading branch information
kesharibhai84 committed Apr 10, 2024
1 parent 5801ada commit f87fcaa
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 5 deletions.
4 changes: 3 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "A minimal SQL based DB based on CSV files. For educational purposes only.",
"main": "./src/index.js",
"directories": {
"doc": "docs"
"doc": "docs",
"test": "tests"
},
"scripts": {
"test": "jest",
Expand Down Expand Up @@ -38,11 +39,11 @@
"author": "Chakshu Gautam",
"license": "ISC",
"devDependencies": {
"csv-parser": "^3.0.0",
"jest": "^29.7.0"
},
"dependencies": {
"csv-parser": "^3.0.0",
"json2csv": "^6.0.0-alpha.2",
"xterm": "^5.3.0"
}
}
}
4 changes: 4 additions & 0 deletions sample.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
id,name,age
1,John,30
2,Jane,25
3,Bob,22
22 changes: 22 additions & 0 deletions src/csvReader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// src/csvReader.js

const fs = require('fs');
const csv = require('csv-parser');

function readCSV(filePath) {
const results = [];

return new Promise((resolve, reject) => {
fs.createReadStream(filePath)
.pipe(csv())
.on('data', (data) => results.push(data))
.on('end', () => {
resolve(results);
})
.on('error', (error) => {
reject(error);
});
});
}

module.exports = readCSV;
4 changes: 3 additions & 1 deletion tests/step-02/index.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const readCSV = require('../../src/csvReader');
// tests/index.test.js

const readCSV = require('../src/csvReader');

test('Read CSV File', async () => {
const data = await readCSV('./sample.csv');
Expand Down

0 comments on commit f87fcaa

Please sign in to comment.